Arduino Internet Controlled Desk Lamp
Intro: 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(){
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
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.
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.
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.
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.
43 Comments
kwyshak 7 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?
91pragya 8 years ago
i need to make a GSM or GPRS based controlling device..plz suggest me some ideas
सतिशल 8 years ago
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 8 years ago
stella_maris 10 years 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!
bobgrant 10 years 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_vaghela 10 years ago
how to connect arduino to server?
jkasih 10 years ago
Groaker 10 years ago
geo bruce 10 years ago
but have a look at x10
Groaker 10 years ago
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 10 years ago
regards,
clintm 11 years ago
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 11 years ago
thanks Lester
geo bruce 11 years ago
lesterwyatt 11 years ago
geo bruce 11 years ago
with no spaces and just 1 in it
does your server have php?
lesterwyatt 11 years ago
thanks Lester
geo bruce 11 years ago
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 11 years ago