当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Distributed consensus mechanism
- C语言I博客作业03
- Six key points of data science interview
- vivoS7e和vivoS7的区别 哪个更值得入手
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- Learn Scala if Else statement
- GoLand writes a program with template
- NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)
- Visual Studio 2015 未响应/已停止工作的问题解决
- 2020-11-07:已知一个正整数数组,两个数相加等于N并且一定存在,如何找到两个数相乘最小的两个数?
猜你喜欢

What is the difference between vivoy73s and vivoy70s

Review the cloud computing application scenarios you didn't expect (Part 1)

麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型

个人短网址生成平台 自定义域名、开启防红、统计访问量

成功解决An error ocurred while starting the kernel

Cloud Alibabab笔记问世,全网详解仅此一份手慢无

FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem

糟糕,系统又被攻击了

5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award

Simple use of future in Scala
随机推荐
PX4添加新的应用
i5 1135g7和i5 1035g1参数对比区别大吗? 哪个好
蓝牙2.4G产品日本MIC认证的测试要求
在Ubuntu上体验最新版本EROFS
Codeforce算法题 | 你能想出解法,让你的基友少氪金吗?
Distributed consensus mechanism
Visual studio 2015 unresponsive / stopped working problem resolution
Seven features of Python 3.9
模板链表类学习
ulab 1.0.0发布
Is there a big difference between i5 1135g7 and i51035g1? Which is better?
Application of bidirectional LSTM in outlier detection of time series
Six key points of data science interview
Windows下子系统Ubuntu安装
Spotify是如何推动数据驱动决策的?
Adobe Prelude /Pl 2020软件安装包(附安装教程)
python 循环区分(while循环和for循环)
Oschina plays on Sunday - before that, I always thought I was a
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
The most detailed usage guide for perconaxtradbcluster8.0