当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 哔哩哔哩常用api
- Brief history of computer
- FORTRAN77从文件中读入若干数据并用heron迭代公式开方
- The difference between vivoy 73s and glory 30 Youth Edition
- Test requirements for MIC certification of Bluetooth 2.4G products in Japan
- Game mathematical derivation AC code (high precision and low precision multiplication and division comparison) + 60 code (long long) + 20 point code (Full Permutation + deep search DFS)
- Golang anonymous structure member, named structure member, inheritance, composition
- More than 50 object detection datasets from different industries
- laravel8更新之速率限制改进
- C language I blog assignment 03
猜你喜欢
VC6兼容性及打开文件崩溃问题解决
QT hybrid Python development technology: Python introduction, hybrid process and demo
More than 50 object detection datasets from different industries
Spotify是如何推动数据驱动决策的?
What details does C + + improve on the basis of C
计算机网络基本概念(五)局域网基本原理
ASP.NET MVC下基于异常处理的完整解决方案
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
高并发,你真的理解透彻了吗?
搜索引擎的日常挑战_4_外部异构资源 - 知乎
随机推荐
The difference between vivoy 73s and glory 30 Youth Edition
Learn Scala if Else statement
Macquarie Bank drives digital transformation with datastex enterprise (DSE)
Is there a big difference between i5 1135g7 and i51035g1? Which is better?
【原创】关于高版本poi autoSizeColumn方法异常的情况
SQL Server 2008R2 18456错误解决方案
Review the cloud computing application scenarios you didn't expect (Part 1)
UCGUI简介
Cloud alibabab notes come out, the whole network detailed explanation only this one hand is slow
Fgagt: flow guided adaptive graph tracking
Interface
laravel8更新之速率限制改进
Python loop distinction (while loop and for loop)
Bili Bili common API
C语言I博客作业03
QT hybrid Python development technology: Python introduction, hybrid process and demo
Simple use of future in Scala
阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking
C language I blog assignment 03
Solve the problem of rabbitmq message loss and repeated consumption