当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking
- 2020-11-07:已知一个正整数数组,两个数相加等于N并且一定存在,如何找到两个数相乘最小的两个数?
- 归纳一些比较好用的函数
- C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
- Astra: the future of Apache Cassandra is cloud native
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- 模板链表类学习
- Which is more worth starting with the difference between vivos7e and vivos7
- C / C + + Programming Notes: what are the advantages of C compared with other programming languages?
- ASP.NET A complete solution based on exception handling in MVC
猜你喜欢
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
高并发,你真的理解透彻了吗?
2020-11-05
ASP.NET A complete solution based on exception handling in MVC
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
Wechat nickname Emoji expression, special expression causes the list not to be displayed, export excel error report and other problems solved!
More than 50 object detection datasets from different industries
解决Safari浏览器下载文件文件名称乱码的问题
Qt混合Python开发技术:Python介绍、混合过程和Demo
Unparseable date: 'Mon Aug 15 11:24:39 CST 2016',时间格式转换异常
随机推荐
ulab 1.0.0发布
OSChina 周日乱弹 —— 之前呢,我一直以为自己是个……
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
shiyou的数值分析作业
IOS learning note 2 [problems and solutions encountered during the installation and use of cocopods] [update 20160725]
How can a technician take over a complex system?
nvm
An error occurred while starting the kernel was successfully resolved
China Telecom announces 5g SA commercial scale in 2020
5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award
vivoS7e和vivoS7的区别 哪个更值得入手
鼠标变小手
python_scrapy_房天下
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
Julia 是如何风靡起来的?
Unparseable date: 'mon Aug 15 11:24:39 CST 2016', time format conversion exception
C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
架构师(2020年11月)
游戏优化性能杂谈(十一) - 知乎
vivoY73s和vivoY70s的区别 vivoY73s和vivoY70s哪个值得入手