Control Led through Wi-Fi
In this project,we will use a Zduino WiFi to make a wireless control LED, control it turn brighter or darker on mobile phone or other wireless device in the same Wi-Fi through UDP or TCP protocol.
Preparation:
We need a Zduino WiFi, a relay module, a led, a Led,and many dupont lines. Connect them like this:
Install a Network debug assistant on your PC or some devices else.
About the Code:
#define SSID "xxxxxxxx”// A wifi you want to join in. #define PASSWORD "xxxxxxxx”//the password of this wifi. #include "OpenWIFI.h" #include <SoftwareSerial.h> WIFI wifi; void setup() { delay(3000); wifi.begin(); DebugSerial.println(wifi.GMR()); delay(2000); bool b = wifi.Initialize(AP_STA, SSID, PASSWORD); if(!b) { DebugSerial.println("Init error"); } DebugSerial.println(wifi.showMode()); //back cwmode delay(8000); DebugSerial.println(wifi.showJAP()); //receive ssid of current connection DebugSerial.println("show the ip address of module"); DebugSerial.println(wifi.showIP());//show the ip address of module delay(8000); wifi.ipConfig(UDP,"192.168.1.14",8080,1,1113,0,4); DebugSerial.println("setup done.."); pinMode(13,OUTPUT); } void loop() { char buf[100]; int iLen = wifi.ReceiveMessage(buf); if(iLen > 0) { if (strcmp(buf, "HIGH") == 0) { digitalWrite(12, HIGH); } else if (strcmp(buf, "LOW") == 0) { digitalWrite(12, LOW); } } }
Upload this Code to Zduino Wi-Fi,then open Network debug assistant,set the Network debug assistant like this
Picture
Then control the Led through send “HIGH”or”LOW”.Of course you can D.I.Y. It through edit the Code.