Induction open lid trash bin based on Wemos D1

Hardware platform introduction WeMos D1

Insert picture description here

characteristic
  1. Based on ESP-8266EX
  2. Arduino compatible, use arduino IDE to program
  3. 11 * I / O pull leg
  4. 1 * ADC pin (input range 0-3.3V)
  5. Onboard 5V 1A switching power supply (high input voltage 24V)
At work
  1. Similar to STM32 module development, high integration
  2. More economical and cheaper

Software environment introduction

Arduino development environment
advantage:
  1. Integrate many development libraries such as serial port, network, sg90 and other hardware development interfaces for rapid development
  2. Comes with serial port debugging tool
Disadvantages:
  1. Program compilation is slow

Ultrasonic module introduction

Insert picture description here

There are usually two ultrasonic components on the ultrasonic sensor module, one for transmitting and one for receiving. There are 4 pins on the circuit board: VCC (positive), Trig (trigger), Echo (response), GND (ground)

The main parameters:
  1. Working voltage and current: 5V, 15mA
  2. Sensing distance: 2~400cm
  3. Sensing angle: not more than 15°
  4. The area of ​​the measured object should not be less than 50cm² and should be as flat as possible
  5. With temperature compensation circuit

Input a high potential of more than 10 microseconds into the starting pin of the ultrasonic module to transmit ultrasonic waves. After transmitting the ultrasonic wave, and before receiving the returned ultrasonic wave, the "response" pin presents a high potential. Therefore, the program can convert the distance of the measured object from the high potential pulse duration of the "response" pin.

Principle of Ultrasonic Module:

Insert picture description here

Insert picture description here

Response ranging core code
const byte trigPin = 10;
const int echoPin = 9;
unsigned long d;
unsigned long ping(){
    
    
	digitalWrite(trigPIN, HIGH)delayMicroseconds(10);	//发送一个10us脉冲
	digitalWrite(trigPin, LOW);
	return pulseIn(echoPin, HIGH);	//波传过程echo高点品,计算高电平时间就获取波传输时间,单位是us

}

void setup(){
    
    
	pinMode(trigPin, OUTPUT)
	pinMode(echoPin, INPUT);
	Serial.begin(115200);
}

void loop(){
    
    
	d = ping()/58;
	Serial.print(d);
	Serial.print("cm");
	Serial.printn();
	delay(1000);
}		
Notes on dividing the distance by 58

The propagation speed of sound in dry, 20°C air is approximately 343m/s, which is 34300cm/s, and the conversion unit is 34300/1,000,000cm/us. That is 0.0343cm/us, another angle, 1/0.0343cm/us, that is 29.15us/cm, which means that, 291.5us means a distance of 10cm, and 1cm is 29.15us, but from sending to receiving, the sound goes Over 2 times the distance. So the actual distance is 1cm corresponding to 58.3us. The actual whole ranging process is the time from when the sound wave is sent out to when the echo is received. The time in the program is us, which is replaced by the distance cm, which is divided by 58 (58.3)

SG90 steering gear

Insert picture description here
Model: SG90 Weight 13 grams Angle 90°~270°
Red wire is voltage, brown wire is ground wire, orange wire is signal wire
Size: 21.5mm 11.8mm 22.7mm
Weight: 9g
Five load speed: 0.12s/60° (4.8V )
Locked-rotor torque: 1.2-1.4 kg/cm (4.8V) Operating
temperature: -30℃~60℃
Dead zone setting: 7us
Working voltage: 4.8V-6V

wiring

Ultrasonic Ranging Module

1.VCC接Wemos板的5V口
2.Trig接Wemos板的D8
3.Echo接Wemos板的D2
4.Gnd接Wemos板的GND

SG90 steering gear

1.橙色线接Wemos板的D5
2.红色线接Wemos板的3.3V
3.灰色线接Wemos板的另一个GND

The finished product is as follows

Insert picture description here

Insert picture description here

This project is based on Chen Lichen's course teaching. For other related information, please follow the CSDN account: https://blog.csdn.net/chenlichenforlinux21
or the vibrato number: Shangguan programmable

Guess you like

Origin blog.csdn.net/zouchengzhi1021/article/details/111880104