视频效果: 基于arduino+web的物联网demo,web和微信控制
基于arduino + web的物联网demo,实现了web和微信的多方式控制,折腾了好几周,终于完美解决了。
配件清单:
Arduino uno3(主板)
HLK-RM04(Uart串口转Wifi)
主板程序源码:
String strs = ""; int led = 6; void setup() { pinMode(led, OUTPUT); Serial.begin(115200);//设置串口波特率 while(!Serial){} } void loop() { getHttp(); delay(2000); httpSend(); } void httpSend(){ Serial.println("GET /demo/demo.jsp?tags=4"); // HTTP/1.1 HTTP协议名称 //Serial.println("Host: 115.28.65.124:8080");//设置服务器地址 } void getHttp(){ while(Serial.available() > 0) { strs += char(Serial.read()); delay(3); } strs.trim(); if (strs.length() > 0){ if(strs.toInt() >0){ //is number chanageLED(strs.toInt()); }else{chanageLED(0);} Serial.println("["+strs+"]"); strs = ""; }else{chanageLED(0);} } void chanageLED(int val){ if(val <= 0){ val = 0;} //min if(val >= 1024){ val = 1023;} //max if(val == 333){ for(int i=0;i<1024;i+50){ analogWrite(led,i);//点亮LED analogWrite digitalWrite delay(30); } for(int i=1023;i>=0;i-50){ analogWrite(led,i);//点亮LED analogWrite digitalWrite delay(30); } }else if(val == 777){ analogWrite(led,1023);//点亮LED analogWrite digitalWrite delay(50); analogWrite(led,0);//点亮LED analogWrite digitalWrite delay(50); }else{ analogWrite(led,val);//点亮LED analogWrite digitalWrite } }
运行效果: