Instructables

Arduino Internet Controlled Desk Lamp

Featured
Picture of Arduino Internet Controlled Desk Lamp
This is a little project I did to control my desk lamp over the internet.
 
Remove these adsRemove these ads by Signing Up

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(){
  Serial.begin(9600);
}

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

    char inByte = Serial.read();
    if(inByte == '1'){
      digitalWrite(13,HIGH);
    }
    else if(inByte == '0'){
      digitalWrite(13,LOW);
    }
  }
}

Step 3: The circuit

Picture of The circuit
relay.jpg
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:
$serial->deviceSet("/dev/ttyUSB0");


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.


stella_maris2 months ago

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!

bobgrant2 months ago

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_vaghela3 months ago

how to connect arduino to server?

jkasih1 year ago
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
mbtria1 year ago
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)  mbtria1 year ago
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.

maloso91 year ago
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,

regards,
clintm1 year ago
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
geo bruce (author)  lesterwyatt1 year ago
check if there is a "testFile.txt" made in the same folder as your webpage
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)  lesterwyatt1 year ago
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
geo bruce (author)  lesterwyatt1 year ago
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 ??
geo bruce (author)  lesterwyatt1 year ago
oh ok just keep trying with the led are you sure you've the right arduino code programmed and not the blink example
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)  lesterwyatt1 year ago
I'll pm you my contact information so we can chat on skype/msn (maybe fb)
scaver1 year ago
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)  scaver1 year ago
it's easier if you use the arduino direct as webserver i think
i buy all my electronics from the internet mostly ebay.com
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
badenuff1 year ago
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.

Thanks,
Sean
geo bruce (author)  badenuff1 year ago
1) yes to both
2) doesn't matter
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 .
miguipda2 years ago
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)  miguipda2 years ago
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
Bruce
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 ?
http://bildr.org/

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)  miguipda2 years ago
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
hey brucw can u add you on skype i need kinda a meentoooor :P:P if possible pm me mate
geo bruce (author)  smanna1 year ago
I'll send my login in pm
margoob2 years ago
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:

$serial->deviceSet("/dev/ttyUSB0");

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:

http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/

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

Thanks!
geo bruce (author)  margoob1 year ago
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 ;)

I'm blinking it now!!! Cool! Thanks, I have to try this sometime.
AtomSoft2 years ago
Can this be used in windows and changed to COM1 for instance?
geo bruce (author)  AtomSoft2 years ago
yes
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)  AtomSoft2 years ago
no problem
TSC2 years ago
This is cool! I voted for it!
geo bruce (author)  TSC2 years ago
Thanks!!!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!