马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
利用
板:WeMos
语音模块:YS-LDV7
使用相关插件
串口调试小助手:ComAssistant
stc-isp
TCP(手机app)
使用相关代码软件
arduino
Keil uVision4
Source Insight 4.0
实现:
1.超声波测距感应
2.使用手机app(TCP)实现手机和垃圾桶联网实现控制垃圾桶
3.通过语音控制垃圾桶开盖和关盖
#include<ESP8266WiFi.h>
#include<Servo.h>
#define Echo D2
#define Trig D8
#define DuoPIN D5
Servo myDuoJi;
long getTime()
{
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
return pulseIn(Echo, HIGH);
}
void initChaoShengBo()
{
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
}
char* ssid = "huawei ry";
char* passwd = "66666666";
int port = 8888;
WiFiServer server(port);
void initWifiSta()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, passwd);
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println(WiFi.localIP());
}
void setup() {
// put your setup code here, to run once:
initChaoShengBo();
myDuoJi.attach(DuoPIN);
Serial.begin(115200);
initWifiSta();
server.begin();
}
void loop() {
char cmd;
int temp = 0;
int sb = 1;
int sp = 1;
char mark;
// put your main code here, to run repeatedly:
WiFiClient client = server.available();
while(client.connected()){
if(temp == 1) {
break;
}
while(client.available() > 0){
cmd = client.read();
if((cmd == '1') && (sb == 1)){
myDuoJi.write(90);
sb = 0;
}if(cmd == '2'){
temp = 1;
break;
}
if(sb == 0){
if(cmd != '1' && cmd != '2' )
{
myDuoJi.write(180);
sb = 1;
}
}
}
}
while(Serial.available() > 0){
mark = Serial.read();
if(mark == '1' && sp == 1 ){
myDuoJi.write(90);
sp = 0;
delay(1500);
}if(mark == '2'){
break;
}
if(sp == 0){
if(mark != '1' && mark != '2')
{
myDuoJi.write(180);
sp = 1;
delay(1000);
}
}
}
long dis;
dis = getTime()/58;
Serial.print(dis);
Serial.println("cm");
if(dis<10){
myDuoJi.write(90);
delay(500);
}else{
myDuoJi.write(180);
delay(500);
}
}
|