Introduction: Turn a Lamp Into a Smart Lamp With LinkitONE

About: I build products which solve real world problems.

Do you have a old lamp at home that you never used? Is it just like too old and you don't like that? Want to do some basic hardware hacking? Then you are at the right place!

Here I'll show you how to turn your basic night lamp into a Wi-Fi connected lamp that you can control easily using your mobiles browser!

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

Step 2: Chosing a Lamp

Now open up your lamp and find out 2 wires that connect to the bulb of the lamp. We'll use them to connect the relay module.

I have a small wire that connects to my lamp using small port. i'll be cutting out that wire and attaching it to the relay.

Step 3: Opening It Up!

now open it up and attach some wires to it!

We'll connect the relay here.

Step 4: Adding the Relay Module

Here we'll add the relay module so that we can power the device with high current.

First of all, place the relay on a breadboard, then connect the 2 wires from bulb of your lamp to one side of the relay. After completing this step connect the wires to the LinkitONE and the breadboard.

Step 5: Writing Some Code

Now we are going to write some code.

See the code from the web-led.ino file and burn the 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 LED on

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

Step 6: Finishing It Up

Now finish up by checking all the connections and attaching the wifi antenna. Attach it into the BT/W port of your LinkitONE.

Step 7: Testing It Out!

Now open this url http://192.168.xx.xx/on

Surprised?

LED is on!!

you can turn on the LED anytime with this and this is way easy!

You can open this up in mobile and it'll be more fun!

Make It Glow! Contest

Participated in the
Make It Glow! Contest

Tech Contest

Participated in the
Tech Contest