当前位置:网站首页>2020-11-05
2020-11-05
2020-11-08 08:54:00 【osc_4isxawz4】
be based on Wemos D1 Avoiding obstacles WiFi Car and intelligent garbage can design
One 、 Experimental equipment
| Master chip | Wemos D1 |
|---|---|
| Other equipment | HC-SR04 ultrasonic 、L9110s The motor 、ESP82660WiFi modular 、 Buzzer |
| Equipment required | TCP |
Two 、 Effect display
chart 1.

3、 ... and 、 Specific operation
1. At first, we still use Wemos D1 Come on Light up our first LED Light
void setup() {
// put your setup code here, to run once:
pinMode(2,OUTPUT);// Here we use 2 Pin No
//void setup() This is the core code that is executed only once
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2,LOW);
delay(1000);// Delay 1ms
digitalWrite(2,HIGH);
delay(2000);
}
chart 2.

2.HC-RS04 ultrasonic
| Working voltage and current | 5V 15mA |
|---|---|
| Sensing distance | 2——400cm |
| 4 One pin | GND( Grounding ) VCC( Positive pole )Trig( Trigger )Eco( Accept ) |
| The two front circles are like eyes | One for transmitting signals 、 One is used to receive signals |
chart 3.

function
#define Ecno D2
#define Trig D8 // Here we will trigger and receive two pin definition, convenient for later operation
void initchaosbo() // Initialize the ultrasound
{
pinMode(Ecno,INPUT);
pinMode(Trig,OUTPUT);
}
long getTime() // Get the distance to be measured
{
digitalWrite(Trig,HIGH);
delayMicroseconds(10);
digitalWrite(Trig,LOW);
return pulseIn(Ecno,HIGH);
}
void setup() {
// put your setup code here, to run once:
initchaosbo();
Serial.begin(115200); // Open the serial port
}
void loop() {
// put your main code here, to run repeatedly:
long dis;
dis=getTime()/58;
Serial.print(dis);
Serial.println("cm");
delay(500);
}
Why divide with 58?
Make a note of , Other bloggers talk about ~~~·" The sound is drying 、 Celsius 20 The propagation velocity in the air is about 343 rice / second , close 34,300 centimeter / second .
perhaps , Let's do the unit conversion ,34,300 Divide 1,000,000 centimeter / Microsecond .
That is to say :0.0343 centimeter / Microsecond
Another angle ,1/(0.0343 centimeter / Microsecond )
namely :29.15 Microsecond / centimeter .
That means , Every time 291.5 Microsecond representation 10CM Distance of .1 Centimeter is 29.15 Microsecond .
But after sending, when the echo is received , The sound goes by 2 Times the distance .
So the actual distance is 1 centimeter , Corresponding 58.3 Microsecond .
In fact, the whole ranging process is the time from sending out sound wave to receiving echo , The first one in your program distance It's actually time us.
So change it to distance cm, Divide by 58. Divide by, of course 58.3 Maybe more accurate ."
3.L9110s Principle of driving step motor
| Driving principle : All in all 6 One pin The middle two are the positive and negative poles of the power supply, and the other four are the signal lines |
|---|
| Four signal lines, we can use the hypothesis 0 It means no turning 1 For rotation |
chart 4.
Specific operation
#define Zhuang1 D4
#define Zhuang2 D5
#define Dong1 D7
#define Dong2 D8
// Define four pins, the first two are used to control the car forward or backward, and the two control the steering of the car after
// Initialize the steering gear
void initL9110s()
{
pinMode(Dong1,OUTPUT);
pinMode(Dong2, OUTPUT);
pinMode(Zhuang1, OUTPUT);
pinMode(Zhuang2, OUTPUT);
}
// back off
void huo()
{
digitalWrite(Dong1, HIGH);
digitalWrite(Dong2, LOW);
}
// Forward
void qian()
{
digitalWrite(Dong1, LOW);
digitalWrite(Dong2, HIGH);
}
void zuo()
{
digitalWrite(Zhuang1, HIGH);
digitalWrite(Zhuang2, LOW);
}
// Back to normal
void zheng()
{
digitalWrite(Zhuang1, LOW);
digitalWrite(Zhuang2, LOW);
}
// Turn left
void zuo()
{
digitalWrite(Zhuang1, HIGH);
digitalWrite(Zhuang2, LOW);
}
// Turn right
void you()
{
digitalWrite(Zhuang1, LOW);
digitalWrite(Zhuang2, HIGH);
}
// stop it
void ting()
{
digitalWrite(Dong1, LOW);
digitalWrite(Dong2, LOW);
}
notes : In the process of operation, there may be errors in the control of the front and rear, and you can make corresponding code changes according to the operation of the car
4.ESP82660WiFi
Wemos D1 One of the great advantages of is the integration of ESP8266WiFi modular , And run WemosD1 The platform has its own ESP8266 The packaging library , Here we just need to know how to call the library function .
Specific operation
#include<ESP8266WiFi.h> // Required header file
char *ssid = "nova 5 Pro"; //WiFi Hot spot name Here you can do it according to your own
char *password = "yin1234567"; //WiFi password
int port = 8888; // Port number
WiFiServer server(port);
// initialization wifi The initialization code here is almost a template, which can be used directly
void initwifista()
{
WiFi.mode(WIFI_STA);// Set up STA Pattern
WiFi.begin(ssid, password); // Connect to the network
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println(WiFi.localIP());// Print address through serial port
}
void setup()
{
initwifista();
Serial.begin(115200);
server.begin();
}
void loop()
{
char cmd;
WiFiClient client = server.available(); // Service initialization
while (client.connected())
{
while (client.available() > 0)
{
cmd = client.read();
if(cmd=='q'){
Serial.println("xaio yin student");
// To meet the requirements of your own input, you can change the function to be implemented
}
else
{
}
}
}
}
4.WiFi The use of the equipment needed by the car is almost finished ( Let's take a look at the overall code , Let the car run Hee hee is not a little bit of achievement duck )
#include<ESP8266WiFi.h>
#define Dong1 D6
#define Dong2 D7
#define Zhuang1 D4
#define Zhuang2 D5
#define Ecno D2
#define Trig D8
char *ssid = "nova 5 Pro";
char *password = "yin1234567";
int port = 8888;
WiFiServer server(port);
void initchaosbo()
{
pinMode(Ecno,INPUT);
pinMode(Trig,OUTPUT);
}
long getTime()
{
digitalWrite(Trig,HIGH);
delayMicroseconds(10);
digitalWrite(Trig,LOW);
return pulseIn(Ecno,HIGH);
}
void initwifista()
{
WiFi.mode(WIFI_STA);// Set up STA Pattern
WiFi.begin(ssid, password); // Connect to the network
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println(WiFi.localIP());// Print address through serial port
}
void initL9110s()
{
pinMode(Dong1, OUTPUT);
pinMode(Dong2, OUTPUT);
pinMode(Zhuang1, OUTPUT);
pinMode(Zhuang2, OUTPUT);
}
void huo()
{
digitalWrite(Dong1, HIGH);
digitalWrite(Dong2, LOW);
}
void qian()
{
digitalWrite(Dong1, LOW);
digitalWrite(Dong2, HIGH);
}
void zuo()
{
digitalWrite(Zhuang1, HIGH);
digitalWrite(Zhuang2, LOW);
}
void zheng()
{
digitalWrite(Zhuang1, LOW);
digitalWrite(Zhuang2, LOW);
}
void you()
{
digitalWrite(Zhuang1, LOW);
digitalWrite(Zhuang2, HIGH);
}
void ting()
{
digitalWrite(Dong1, LOW);
digitalWrite(Dong2, LOW);
}
void setup() {
initL9110s();
initchaosbo();
Serial.begin(115200);
initwifista();
server.begin();
}
void loop() {
char cmd;
long dis;
dis=getTime()/58;
WiFiClient client = server.available(); // Service initialization
while (client.connected())
{
while (client.available() > 0)
{
cmd = client.read();
switch (cmd)
{
case 'q':
qian();
if(dis<=10)
{
ting();
}
break;
case 'h':
huo();
break;
case 'z':
zuo();
break;
case 'y':
you();
break;
case 's':
ting();
break;
case 'd':
zheng();
break;
}
}
}
}
5. By the way, I forgot to use TCP To control the car , In fact, the principle is very simple, we will use ComAssistant( Of course, you can use other software ) This serial port software to get what we need IP Address . Note that in the use process, we also need to set the corresponding port number baud rate to the same as we set in the code . And then in TCP With what we've got ID Make a remote host connection In accordance with their own code to send the corresponding instructions on it .
chart 5.

3、 ... and 、 Smart trash can
I'm not going to talk about the chip used here WemosD1 Ultrasound and the front of WiFi The principle of the car as like as two peas is more than one steering gear SG90 The steering gear .
3.SG90 The steering gear
| model | SG90 weight 13 g |
|---|---|
| Working voltage | 4.8v~6v(3.3v It's fine too ) |
| Three lines correspond to ports | Red : Positive pole Brown :GND Orange : The signal line |
chart 6. Overall effect display

Specific operation
#include<Servo.h> // The required header file
#define Ecno D2
#define Trig D8
#define BEEP D5 // A buzzer is added here to control whether the buzzer rings or not according to the distance
Servo myDuoJi;
#define DuoPin D5 // Define the steering gear
// Initialize buzzer
void initfmq()
{
pinMode(BEEP,OUTPUT);
digitalWrite(BEEP,HIGH); // When running, we set it to high level to avoid the buzzer ringing as soon as the program is running
}
void setup() {
// put your setup code here, to run once:
myDuoJi.attach(DuoPin); // Connect the steering gear
initchaosbo();
Serial.begin(115200);
myDuoJi.write(180); // The degree of flipping
//initfmq();
}
// Initialize the ultrasound
void initchaosbo()
{
pinMode(Ecno,INPUT);
pinMode(Trig,OUTPUT);
}
long getTime()
{
digitalWrite(Trig,HIGH);
delayMicroseconds(30);
digitalWrite(Trig,LOW);
return pulseIn(Ecno,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
long dis;
dis=getTime()/58;
Serial.println(dis);
Serial. println("cm");
if(dis<4)
{
// digitalWrite(BEEP,LOW);
// delay(1000);
myDuoJi.write(90);
delay(2000);
}
else
{
//digitalWrite(BEEP,HIGH);
myDuoJi.write(180);
}
}
That's all WiFi Car and smart trash all the code , If there is a mistake in my understanding, I hope you can point out , Learn from each other and make progress together ( Blunt duck ).
版权声明
本文为[osc_4isxawz4]所创,转载请带上原文链接,感谢
边栏推荐
- How does spotify drive data-driven decision making?
- print( 'Hello,NumPy!' )
- 5G+AR出圈,中国移动咪咕成第33届中国电影金鸡奖全程战略合作伙伴
- 抖音直播监控Api:随机推荐
- 阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking
- China Telecom announces 5g SA commercial scale in 2020
- Shiyou's numerical analysis assignment
- What details does C + + improve on the basis of C
- ulab 1.0.0发布
- GET,POST,PUT,DELETE,OPTIONS用法与说明
猜你喜欢

Blazor 准备好为企业服务了吗?

PX4添加新的应用

Python loop distinction (while loop and for loop)

Unparseable date: 'mon Aug 15 11:24:39 CST 2016', time format conversion exception

Visual studio 2015 unresponsive / stopped working problem resolution

How can a technician take over a complex system?

sed之查找替换

软件测试就是这么回事?!

阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking

5G+AR出圈,中国移动咪咕成第33届中国电影金鸡奖全程战略合作伙伴
随机推荐
Adobe Prelude /Pl 2020软件安装包(附安装教程)
What details does C + + improve on the basis of C
Julia 是如何风靡起来的?
scala 中 Future 的简单使用
Do you really understand the high concurrency?
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
Codeforce算法题 | 你能想出解法,让你的基友少氪金吗?
vivoY73s和vivoY70s的区别 vivoY73s和vivoY70s哪个值得入手
0.计算机简史
搜索引擎的日常挑战_4_外部异构资源 - 知乎
Experience the latest version of erofs on Ubuntu
NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)
Ulab 1.0.0 release
Bili Bili common API
Tiktok live monitoring Api: random recommendation
软件测试就是这么回事?!
5g/4g工业无线路由器
接口
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
November 07, 2020: given an array of positive integers, the sum of two numbers equals N and must exist. How to find the two numbers with the smallest multiplication?