Arduino Internet Controlled Desk Lamp





Introduction: Arduino Internet Controlled Desk Lamp

This is a little project I did to control my desk lamp over the internet.

Step 1: What You'll Need

A linux web-server with PHP, an arduino, a relay and some other components.

Step 2: Upload Your Code to the Arduino

Upload the following code to your arduino:

void setup(){

void loop()
  if (Serial.available() > 0) {

    char inByte =;
    if(inByte == '1'){
    else if(inByte == '0'){

Step 3: The Circuit

Connect everything as shown in the image.
Connect the base of the transistor to the pin used in the code I used pin 13

Connect your light bulb in series with switching contacts of the relay.

And connect your arduino to your server.

Step 4: The Webpage

php_serial.class.php = Serial library

example.php = The code
make sure you put the path of your arduino on the following line:

Upload this two files to your server in the same directory.

Step 5: Test It

Make sure your permissions are right
go to your terminal and type: ls -l /dev/ttyUSB0
then you'll should get a response like:  crw-rw-rw- 1 root .............
otherwise you have to set the permissions type: chmod 666 /dev/ttyUSB0

Browse to the example page.

Normally you should be able to control your lights.



    • Science of Cooking

      Science of Cooking
    • Trash to Treasure

      Trash to Treasure
    • Paper Contest 2018

      Paper Contest 2018

    We have a be nice policy.
    Please be positive and constructive.




    From your Fritzing diagram it looks like you have one leg of your lamp going to the relay's coil rather than to the NO contact. Shouldn't the lamp go to the NO contact of the relay?

    i need to make a GSM or GPRS based controlling device..plz suggest me some ideas

    hee geo bruce i new in server making i need help.......i want to control robot through iot base ...i take a arduino board & ethernet shield....motor control direction in forward reverse left & right....


    Hey guys! Is it possible to set up my arduino to a light, which flashes/goes on when my favourite football team score?? Thanks!

    Hello, thank you for a nice tutorial! I was looking for something like this desperately for our close-deadline bachelor project. But how do you adapt it to a server which is not Linux? I have windows7...It would be awesome if you could give me and my goup any adice!: ) thank you!

    Thanks for the great instruction. I have been looking for something like this to expand my project. I did ran into small problem. I am able to send on and off command through example.php but my relay doesn't stay on or off. It goes click light blinks and goes off. Am I missing anything. Thanks

    how to connect arduino to server?

    Thanks for tutorial, btw this is just only one lamp, how about many lamp and how to recognize every lamp? i really interest for case

    I don't know much about electronic circuits (though I do put in new mains circuits), but am interested in being able to switch 110V circuits (US) where I have power, but no feasible wiring for switching (log home). I was considering using XBee/Arduino for this, but thought that a latching relay would be more appropriate to save battery power. Any comment?

    sorry I don't fully understand your question
    but have a look at x10