Introduction: Arduino Internet Controlled Desk Lamp

Picture of 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

Picture of 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

Picture of 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

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


kwyshak (author)2017-02-09

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?

91pragya (author)2015-10-22

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

सतिशल (author)2015-08-25

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

ZakD (author)2015-05-28

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

stella_maris (author)2014-05-05

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!

bobgrant (author)2014-05-01

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

Om_vaghela (author)2014-04-10

how to connect arduino to server?

jkasih (author)2013-07-08

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

Groaker (author)2013-06-04

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?

geo bruce (author)Groaker2013-06-05

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

Groaker (author)geo bruce2013-06-05

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.

maloso9 (author)2013-06-05

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,


clintm (author)2013-01-20

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

lesterwyatt (author)2012-11-10

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

geo bruce (author)lesterwyatt2012-11-10

check if there is a "testFile.txt" made in the same folder as your webpage

lesterwyatt (author)geo bruce2012-11-10

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

geo bruce (author)lesterwyatt2012-11-10

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

does your server have php?

lesterwyatt (author)geo bruce2012-11-10

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

geo bruce (author)lesterwyatt2012-11-10

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

lesterwyatt (author)geo bruce2012-11-10

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

geo bruce (author)lesterwyatt2012-11-10

oh ok just keep trying with the led are you sure you've the right arduino code programmed and not the blink example

lesterwyatt (author)geo bruce2012-11-10

Bruce, I used the code you put up on the example; i don't need to add anything else to it do I? (as you have probably figured i am new to this)
Thanks Lester

geo bruce (author)lesterwyatt2012-11-10

I'll pm you my contact information so we can chat on skype/msn (maybe fb)

scaver (author)2012-10-30

Great manual. I want to make this to control the x-mass lights over the internet.
I've never worked with the arduino before. Any tips where and what I should by?
I want to use a utp or wifi connection and use the arduino as a webserver.

Greets from the Netherlands.

geo bruce (author)scaver2012-10-30

it's easier if you use the arduino direct as webserver i think
i buy all my electronics from the internet mostly
and if u use a triac or solid state relay instead of a relais you can dim your ligts :D

greets from Belgium the dutch part :D

badenuff (author)2012-10-18

hi Geo Bruce,
quick questions,
1) can i substitute these? 2N3904 for 2N2222; and 1N4007 for 1N4004.
2) is the relay you're using, 6 pin? just want to make sure.


geo bruce (author)badenuff2012-10-19

1) yes to both
2) doesn't matter

mr.future11 (author)2012-10-13

well. i m new to arduino n these types of projects. it would really kind mr geo buce if u could help me explaining all those stuffs that u did. n i couldnt understand how to use a relay for the lamp .

miguipda (author)2012-06-05

Dear geo bruce,

thanks for this instructable. I am a really perfect newbie due to the fact I still did not even touch an arduino.

But now I really need to use it for a small project like yours.
I also want to be able to switch on or off lights through internet.

There is just two more interesting points I need :
1) I need the arduino must be able to switch on or off more than one lamp. Following you how many lamp could I manage with the arduino connection ?

2) I need they also could be set in security mode. For me it means that each lamp could be randomly switch on or off by a webserver. For this I already use a router on which there is a webserver. Then if we can switch on/off a lamp through internet it means it received some PHP commands that can be also be used to do it by itself randomly.
Is not it ?

Sincerely thanks for your answer because I will need it soon.

Have a nice day,

Miguipda ;-)

geo bruce (author)miguipda2012-06-05

1)how many lamp could I manage with the arduino connection ?
>> easy 11 or if you make little changes as much as you want

2) PHP commands that can be also be used to do it by itself randomly.
Is not it ?
>> yes

Warm Regards

miguipda (author)geo bruce2012-06-05

Dear geo bruce,

sincerely thanks for your quick answer.
Could I ask you if you could make a schematic picture like this one shown at right on this page ?

It could help me to more understand and also help all newbies like me.

Another little remark. I already found the circuit schema you showed here above. But for other newbies like me it could be better if they can have a larger picture when they click on it. Because with this small size picture I presume they will not be able to well understand. It is just because I was also confused I remembered I previously already saved this picture that I realized that for other people it will not be so easy.

And my last question because I still never tried to use Arduin board. I read some titles talking about Arduino where they talk about Arduino as webserver. Then as you made an introduction about the need of a webserver with PHP is it possible or to have this webserver directly on the Arduino and then be able to do your instructable application ?

Sincerely thanks and have a nice day,

Miguipda ;-)

geo bruce (author)miguipda2012-06-05

I'll update the picture
and yes you can make an arduino webserver if you have an ethernet shield on your arduino

u can add me on skype / msn so i can take you to the whole build proces in 15 min and get it working ;)
it's just a 15 min project

i'll pm my contact information

smanna (author)geo bruce2012-09-16

hey brucw can u add you on skype i need kinda a meentoooor :P:P if possible pm me mate

geo bruce (author)smanna2012-09-16

I'll send my login in pm

margoob (author)2012-07-22

Hi Geo,

Awesome project! It's simple but it answers a lot of questions I had regarding how to sending data to an arduino from a web page!

I have a question here. I want to do a little modification - I want to send the data to the Arduino over bluetooth. So, any idea on what should I have in my path instead of:


I think this is the only change that I need to make. By the way, just FYI, I plan to use this setup for bluetooth:

Any suggestion would be a great help! As for linux, I'm be using Ubuntu.


geo bruce (author)margoob2012-08-08

I think it's possible with that setup, I haven't done anything with bluetooth yet so I can't give you some tips.

But let me know if it works ;)

stringstretcher (author)2012-05-07

I'm blinking it now!!! Cool! Thanks, I have to try this sometime.

AtomSoft (author)2012-05-03

Can this be used in windows and changed to COM1 for instance?

geo bruce (author)AtomSoft2012-05-03


AtomSoft (author)geo bruce2012-05-03

Thanks. I hope you dont mind but i printed this page as a PDF and downloaded all the Files.. (Ino and Zip) so i can have for future reference. Thanks for the awesome work and time spent on this.

geo bruce (author)AtomSoft2012-05-03

no problem

TSC (author)2012-04-24

This is cool! I voted for it!

geo bruce (author)TSC2012-04-24


About This Instructable




Bio: 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 ... More »
More by geo bruce:Musical Tesla Coil Kit (instructions)Design a Parametric Pulley (DXF / STL)High Voltage Pulse Generator for $8 (stungun)
Add instructable to: