Introduction: Arduino Internet Controlled Desk Lamp
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
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);
}
}
}
Attachments
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:
$serial->deviceSet("/dev/ttyUSB0");
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.

Participated in the
Robot Challenge

Participated in the
Arduino Challenge

Participated in the
Make It Real Challenge

Participated in the
Spy Challenge
43 Comments
6 years ago
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?
7 years ago
i need to make a GSM or GPRS based controlling device..plz suggest me some ideas
8 years ago on Introduction
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....
8 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!
9 years ago on Introduction
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!
9 years ago on Introduction
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
9 years ago on Introduction
how to connect arduino to server?
10 years ago on Introduction
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
10 years ago on Step 3
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?
Reply 10 years ago on Step 3
sorry I don't fully understand your question
but have a look at x10
Reply 10 years ago on Step 3
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.
10 years ago on Introduction
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,
10 years ago on Introduction
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
10 years ago on Introduction
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
Reply 10 years ago on Introduction
check if there is a "testFile.txt" made in the same folder as your webpage
Reply 10 years ago on Introduction
Hello Bruce. Thanks for the quick reply. No there is no testFile.txt in my webpage folder. What should i do? Thanks Lester
Reply 10 years ago on Introduction
you can try to manually create the "testFile.txt"
with no spaces and just 1 in it
does your server have php?
Reply 10 years ago on Introduction
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
Reply 10 years ago on Introduction
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
Reply 10 years ago on Introduction
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 ??