Arduino Internet Controlled Desk Lamp




Introduction: Arduino Internet Controlled Desk Lamp

About: Hello, I'm Bruce. I'm a student in Belgium. I have a wide variety of interests: electronics, computers, technology, ... In my spare time I spend a lot of time on: projects, exploring the internet, cycling. ...
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.



    • Water Contest

      Water Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Fix It! Contest

      Fix It! Contest

    43 Discussions

    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....


    3 years ago

    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

    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?

    2 replies

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

    Thank you for taking the time to respond. Sorry if I was obtuse.

    I have had X-10 for about 10 years for control, but I hear different things about how long they are going to be in business. I do know that a lot of prices on X-10 equipment are skyrocketing. I lost my bridge between the 110V legs on the 220V mains, and the price is now double what I paid for it.

    I was also using Dallas 1-wire tech for sensors, but they seem not to be expanding their line in ways useful to me. And they have dropped a part or two which are critical, so I was thinking about switching to I2C, XBee and Arduino.

    My real question is have you ever used a latching (bistable) relay in such a circuit? If so how did it work out, or do you have an opinion on using such a relay?

    Thank you again.

    Excelent Work GEo, keep up, also you can check the chrome.serial module to read from and write to a device connected to a serial port,


    geo bruce
    This is what I wanted to do for a while but didnt know how to send data out a USB.
    I cannot get past step 5. I run the example but I get an error. Serial port is not valid.
    I go to the terminal and type in ls - /dev/ttyUSB0
    It comes back with 'ls' is not recognized as an internal or external command.
    I am using windows 7 .What can I do now? I want to send data out the USB port.
    My Arduino is on com 4. Thanks Clintm

    Hello great project. I have a problem with the PHP page. it is displaying part of the light switch with a comment saying unable to open file! any ideas anybody??
    thanks Lester

    6 replies

    Hello Bruce. Thanks for the quick reply. No there is no testFile.txt in my webpage folder. What should i do? Thanks Lester

    you can try to manually create the "testFile.txt"
    with no spaces and just 1 in it

    does your server have php?

    Yes i think so (PHP). Just created testfile.txt. The whole of the switch shows now in browser. However the switch will only go in the on position and not off. Also my relay goes on,off, on, off, It does not stay in one position? ant ideas?
    thanks Lester

    not testfile.txt it has to be testFile.txt with capital "F"
    toggling relay can be 2 things
    1) someone has the url of you webpage and wrote a script to drive you crazy solution: change webpage name

    2)when the relay goes on it draws to much current the arduino can't handle it and the voltage drops and the arduino resets
    solution use a transistor as described in thin instructable to drive your relay
    and maybe use an external power source

    I don't think it is the relay. I have tried with just LED in 13 it still blinks and wont stay on or off. don't think it is a virus i have only set up apache web server today ??