loading

Have a fan at home? Is it too boring or too old? Want to automate it? Do you want to build something cool? Then you are at the right place!

Here I'll show you how to turn your old classy fan into a WiFi Chandelier that you can control using your smartphone!

Let's begin...

Step 1: What Do You Need?

1 . LinkitONE board

2. An old lamp (I have a small LED lamp)

3. Breadboard

5. LinkitONE wifi antena

6. Battery pack

7. Relay module

8. A Fan (of course)

Step 2: Looking in the Fan's Curciut!

Now look into the device you are using. I'm using a metal one which has connection wires above it. I'll hack the fan by connecting my board at the connection point.

Step 3: Attaching Relay to Fan

As this light runs on 220 volts, we'll need to use a relay because arduino can only provide upto 5v max. So we'll attach a relay to it. I'm using a 6v relay.

Step 4: Attaching the Board

Now finally connect your board to the relay on breadboard and then connect it to your fan.

Step 5: Writing Some Code

Now we are going to write some code.

The code is simple, when ever it finds a client, it gives back a webpage where you can control it!

CODE

-------------

#define WIFI_AP "Your WiFi network" // chance this to your wifi network name #define WIFI_PASSWORD "Password" // change this to the password for the network #define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration // If this doesn't work, try LWIFI_WEP. If your network doesn't have a password, use LWIFI_OPEN. int serverPort = 80; LWiFiServer server(serverPort); int LED = 13;

void setup() { pinMode(LED, OUTPUT); LWiFi.begin(); Serial.begin(115200); // keep retrying until connected to AP Serial.println("Connecting to AP"); while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(600);

} digitalWrite(LED, HIGH); printWifiStatus(); Serial.println("Start Server"); server.begin(); Serial.println("Server Started"); digitalWrite(LED, LOW); }

int loopCount = 0;

void loop() { // put your main code here, to run repeatedly: String str = ""; String url = ""; int i; delay(500); loopCount++; LWiFiClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // we basically ignores client request, but wait for HTTP request end char c = client.read(); Serial.print(c); if(c != '\n') str += c; if(c == '\n') { //Serial.println(str); if(str.startsWith("GET ")) { url = str.substring(4, str.lastIndexOf(" ")); Serial.print("URL:"); Serial.print(url); Serial.println(":"); } str = ""; }

if (c == '\n' && currentLineIsBlank) { Serial.println("send response"); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println();

if(url != String("favicon.ico")) { client.println("");

//i = digitalRead(LED); url.toLowerCase(); if(url == String("/on")) { digitalWrite(LED, HIGH); client.println("Turning LED on "); } else if(url == String("/off")) { digitalWrite(LED, LOW); client.println("Turning LED off "); } else { client.println("Doing nothing "); } client.println("

\n

"); client.println(); break; } } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(50);

// close the connection: Serial.println("close connection"); client.stop(); Serial.println("client disconnected"); } }

void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(LWiFi.SSID());

// print your WiFi shield's IP address: IPAddress ip = LWiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);

Serial.print("subnet mask: "); Serial.println(LWiFi.subnetMask());

Serial.print("gateway IP: "); Serial.println(LWiFi.gatewayIP());

// print the received signal strength: long rssi = LWiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }

-------------

Once you complete this step, go to the URL of LinkitONE and access your web interface.

http://192.168.xx.xx/on for turning circuit on

http://192.168.xx.xx/off for turning circuit off

Step 6: Building an Android App (Optional)

I made an android app for controlling the lights. It's very easy to do so!

You just need to use App Inventor, and build a simple app using its web interface. There are a lot of tutorials on app inventor, so refer to them.

Step 7: Finalizing It!

Now finalize the circuit by connecting the WiFi antenna and the battery. After doing this you are finally done to play with it!

BE careful while doing connections as you are dealing with 220 volts!!!

Step 8: Testing It Out!

Test it out! Build the app and then test it! When you press green button, it turns on and when you press red it turns off!

About This Instructable

467views

7favorites

License:

More by ssarthak598:DIY Smart Home Monitoring Bottle Arduino Video Game (The DIY Gift) Is My Fridge Door Open?! 
Add instructable to: