Web Controlled Arduino LED

 by tamberg
Featured
yaler.png
This instructable shows you how to build a Web-enabled tri-color LED based on an Arduino and the WIZnet Ethernet shield, controllable from any Web browser .

Check the live demo at http://try.yaler.net/~arduino/led

Because the LED is exposed through a simple RESTful web service running on the Arduino color changes can also be triggered by Pachube or other platforms offering Web hooks. Welcome to the Web of Things ! The LED can of course be replaced by a motor or a high voltage switching relay to enable more interesting browser controlled applications, e.g. for home automation.

Publishing your Arduino through the Yaler relay server makes the Arduino accessible from everywhere even if it is hidden behind a firewall or a NAT and does not have a public IP address. A single Yaler relay server instance can host many Arduinos (and any other device with a TCP Socket library, e.g. a Sheevaplug or an Android phone) and is available for non-commercial use including full source code at http://yaler.org/ (Disclosure: I founded the company developing Yaler)

Material
  • Tri color LED [Ladyada | SparkFun]
  • Arduino Duemilanove ATmega 328 [Ladyada | SparkFun]
  • Arduino WIZnet Ethernet Shield [Ladyada | SparkFun]
  • Resistors [1 x 150 Ohm, 2 x 82 Ohm for the Ladyada LED or
                        1 x 180 Ohm, 2 x 100 Ohm for the SparkFun LED]
  • RJ45 cable
Tools
  • Soldering iron
  • Helping hands
  • A / B USB cable
Infrastructure
  • Internet access with DHCP, no public IP address needed for Arduino
  • (Optional: PC or Cloud Server with a public IP address, to run Yaler)
 
Remove these adsRemove these ads by Signing Up

Step 1: Soldering resistors and wire to the tri-color LED

4343263424_1e7d6bf6fa.jpg
4343262388_316a9ca0b3.jpg
4343264024_3c639d1739.jpg
4343264348_48439f5d37.jpg
(Note: All images show the Ladyada LED with the corresponding resistors and wire color)
  • Shorten all except for the longest leg of the LED
  • Solder the resistors to the LED legs as shown below
  • Shorten the remaining long leg
  • If you use the Ladyada LED, solder the red wire to it [as shown below]
  • If you use the SparkFun LED, solder the black wire to it

1-40 of 46Next »
bajonjon says: Feb 12, 2013. 5:08 AM
hello sir,.can you upload the complete code???
tamberg (author) in reply to bajonjonFeb 12, 2013. 8:41 AM
Just sent you a message. Regards, Thomas
renexdon says: Jan 4, 2013. 7:15 AM
Hi tamberg, firstly congratz for this very useful post. I'm quite new with Arduino and Web of the Things staff, I'd like to implement the java apps directly on my google app engine account, I use Eclipse for that purpose, any suggestion? ReneX
tamberg (author) in reply to renexdonJan 4, 2013. 12:11 PM
He renexdon, Sounds great. Your Java App could call the Arduino via HTTP. Regards, Thomas
Michael_Bell says: Nov 11, 2012. 12:25 AM
Are you planning to get your demo working again? I enjoy playing with it, it is my homepage
tamberg (author) in reply to Michael_BellNov 11, 2012. 6:09 AM
Glad you like it. Sometimes it's stuck and needs a reset. Will do that ASAP.
jaypozo says: Apr 22, 2012. 3:31 AM
Great project, but it doesn't seem to work for me. Everything compiles and I can connect to the Arduino and see the colour select page, but when I click one of the boxes, it doesn't change on the Arduino. Any ideas? I get this output when I hit the page:

n/led/ HTTP/1.1

And this when I click on the RED box:


n/led/led/ff0000 HTTP/1.1
Host: try.yaler.net

It looks like the "isPut" variable never gets set to "true" and so the pins never get set.
tamberg (author) in reply to jaypozoOct 14, 2012. 5:34 AM
jaypozo, the code didn't work anymore due to a change on the relay. Please download the updated version from this Instructable. Regards, tamberg
tamberg (author) in reply to jaypozoApr 22, 2012. 5:29 AM
Hi, from the output it seems the path is shorter than the code expects. Which URL are you using to access your Arduino? Kind regards, tamberg
jaypozo in reply to tambergApr 22, 2012. 10:35 AM
This is the URL I'm using: http://try.yaler.net/gsiot-2fds-hkan/led/
tamberg (author) in reply to jaypozoApr 22, 2012. 1:08 PM
Ok. Does it work if you use http://try.yaler.net/gsiot-2fds-hkan/led instead (without the final slash)?

Regards,
tamberg
tamberg (author) says: Oct 13, 2012. 12:17 PM
Just updated the ZIP downloads to reflect the new relay IP address and fix a parsing error.
crackHacker says: Mar 29, 2012. 7:09 PM
ok i can get it to compile and everything but my network keeps showing it as expired on the lease.
tamberg (author) in reply to crackHackerMar 29, 2012. 11:56 PM
Hi, according to this thread http://code.google.com/p/arduino/issues/detail?id=716 calling maintain() might help. Cheers, tamberg
whanif says: Jan 25, 2012. 6:29 PM
I had a problem, when compiling the "HelloTriColorLedYalerService.pde" sketch, the result return with errors and the main error is "cannot declare parameter 'c' to be of abstract type 'client'" can i know why ? I've add the EthernetDHCP into libraries but still produce that error. TQ
tamberg (author) in reply to whanifJan 25, 2012. 11:40 PM
Whanif, thanks for trying the code. Which Arduino model and Arduino IDE version did you use? And which version of the libraries? It's been some time since I wrote this code. Cheers, tamberg
whanif in reply to tambergJan 27, 2012. 12:32 AM
Thank you for the reply, I'm now using Arduino Uno Revision 2 and the IDE is version 1.0, for the libraries, it is Version 1.0b4. Thanks in advance...
tamberg (author) in reply to whanifJan 27, 2012. 2:13 AM
Ok. I don't have an Arduino Uno R2, but I can try to recompile the code with the new IDE and libraries this weekend. Sorry for the delay...
whanif in reply to tambergJan 27, 2012. 3:58 AM
Ok, thank you for your help...
tamberg (author) in reply to whanifJan 28, 2012. 3:47 PM
Looks like the Arduino libraries changed significantly with v1.0, as far as Ethernet is concerned. Upgrading the code might take some time. As a quick fix you can try to use Arduino 0018 (if that works with the Uno).
tamberg (author) in reply to tambergJan 30, 2012. 2:17 AM
Just added a new version of the source code for Arduino 1.0. Please let me know if it works for you. Cheers, tamberg
whanif in reply to tambergJan 29, 2012. 7:33 PM
I've patched my latest Arduino libraries to version 0018 and this error come up -->

sketch_jan30a:-1: error: variable or field 'receiveYalerResponse' declared void
sketch_jan30a:-1: error: 'Client' was not declared in this scope
sketch_jan30a:-1: error: variable or field 'sendPutResponse' declared void
sketch_jan30a:-1: error: 'Client' was not declared in this scope
sketch_jan30a:-1: error: variable or field 'sendGetResponse' declared void
sketch_jan30a:-1: error: 'Client' was not declared in this scope
sketch_jan30a:-1: error: variable or field 'receiveRequest' declared void
sketch_jan30a:-1: error: 'Client' was not declared in this scope
In file included from C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Ethernet.h:5,
from sketch_jan30a.cpp:29:
C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Client.h:17: error: conflicting return type specified for 'virtual void Client::write(uint8_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Client.h:19: error: conflicting return type specified for 'virtual void Client::write(const uint8_t*, size_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:50: error: overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
In file included from C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Ethernet.h:6,
from sketch_jan30a.cpp:29:
C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Server.h:20: error: conflicting return type specified for 'virtual void Server::write(uint8_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\libraries\Ethernet/Server.h:22: error: conflicting return type specified for 'virtual void Server::write(const uint8_t*, size_t)'
C:\Documents and Settings\User\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:50: error: overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
sketch_jan30a.cpp: In function 'void setup()':
sketch_jan30a:217: error: redefinition of 'void setup()'
sketch_jan30a:2: error: 'void setup()' previously defined here
sketch_jan30a.cpp: In function 'void loop()':
sketch_jan30a:230: error: redefinition of 'void loop()'
sketch_jan30a:7: error: 'void loop()' previously defined here


any ideas ?
tamberg (author) in reply to whanifJan 30, 2012. 1:25 AM
Assuming you are using the unchanged code from this Instructable it's hard to understand how those errors could result. Unfortunately my 0018 version of the IDE is broken in another way. I tried to verify the code on 0022 though, and there it works if you select the menu entry Include > SPI before verifying the code.

Sorry for the trouble,
tamberg
cvasantrao says: Dec 27, 2011. 8:38 PM
Looks like try.yaler.net is down again. A very interesting project. Was planning something of the sort
tamberg (author) in reply to cvasantraoDec 28, 2011. 3:32 AM
Cvasantrao, the relay try.yaler.net is up and running (http://status.yaler.net/), but it happens that the Arduino goes offline (the current code needs a reset from time to time) which results in a 504 Gateway Timeout. Some browsers display this as an empty page or even an error. Cheers, tamberg
amcelmon says: Nov 25, 2011. 5:57 AM
I have a similar project i'm working on, an alert light based on values in a database. I originally started this project thinking I would be making outbound requests to a webserver, on a timer, from Arduino and switching lights based on the returned values.

Am I better off having having the webserver send simple requests to my Arduino device or the other way around.
tamberg (author) in reply to amcelmonNov 25, 2011. 7:11 AM
Hi amcelmon, interesting question. If you need real-time updates, the timer would probably be a bad idea, as the interval would have to be very low and thus a large number of requests (most of them in vain) would be sent from the Arduino. If a delayed update is fine, your solution would work and probably be simpler. But another question is how much of the logic you'd like to put on the Arduino. My example exposes just a very thin API layer above the hardware (i.e. the LED), which enables you to keep the application logic in the cloud (as a Web client) or even on your desktop (try cURL with my LED). This way (embedded device as a Web server) it's almost trivial to make mash-ups using different Web APIs. Cheers, tamberg
tamberg (author) in reply to tambergNov 25, 2011. 7:16 AM
PS. In your case you can further decide to couple your DB Web Server tightly with the Arduino (by calling out directly from the DB Web server to the Arduino Web server) or loosely (by having a scripted Web client call both your DB Web server and the Arduino LED Web server).
jcouch1227 says: Feb 7, 2011. 9:18 PM
Hi, if i wanted to run this same sort of operation over a local network, would an ethernet shield be necessary? I want to control my arduino with a website on an iphone but have no need to do it anywhere in the world :) thanks.
tamberg (author) in reply to jcouch1227Nov 2, 2011. 2:22 AM
Hi, the Ethernet shield is necessary if you want to host a Web page on your Arduino. The Yaler relay specific code is only needed if you want global access. Cheers, tamberg
a_pineda says: Oct 29, 2011. 10:53 AM
I had problems with running my own instance and using the "HelloTriColorLedYalerService.pde" arduino code above. To get it to work properly, I had to modify the "parseYalerResponseChar" function as follows to get it to work:

// if (yalerCount == 56) { // sizeof("HTTP/1.1 101 ... \r\n\r\n") - 1
if (yalerCount == 75) { // sizeof("HTTP/1.1 101 ... \r\n\r\n") - 1

Now it works fine. Apparently the returned HTML is longer on the source code version that what comes back from Yaler.net.

Maybe I built the Java source incorrectly, but this fix seems to work for me.

tamberg (author) in reply to a_pinedaOct 29, 2011. 1:24 PM
Thanks for the comment. You are right, the current hosted version differs from the open source version in this respect. Kind regards, tamberg
tyao says: Jul 16, 2011. 9:11 AM
Hi, this is a very nice project. May I recommend that you put a income data filter to limit the light options to red, green, and blue. I am currently able to go into Firebug, edit the button commands to send whatever data I want. ie. I set the Green button to send "ffffff" which results a almost white led. OR "000000", which turns off the led. maybe "ff00ff" which would give purple.

overall, this project is very well designed
tamberg (author) in reply to tyaoJul 16, 2011. 10:18 AM
Hi tyao,

thanks for checking out this project. You're right, it's currently possible to set other colors than red, green and blue. The LED has a public interface which let's you send HTTP requests to control it. In addition to editing the button command you can use cURL, the Poster Firefox plugin or any other Web client to send an HTTP PUT request "by hand". Of course you're also right that such an interface should only allow valid settings and filter the rest.

Cheers,
Thomas
tedlawson says: Jun 12, 2011. 9:11 AM
Caught my errors ... working nicely. Onward!
tamberg (author) in reply to tedlawsonJun 12, 2011. 10:07 AM
Hi Ted, good to hear it works. Thanks for investing your time in this. Cheers, tamberg
tedlawson says: Jun 10, 2011. 9:14 PM
After initial success in duplicated this project, I've been getting the 504 error for the past week. I also tried it using a Mega
tedlawson says: Jun 2, 2011. 3:35 PM
Basically duplicating what you have laid out in your instructions and with the addition of JTV. As I said, I had the basic version running fine. I then inserted the code for JTV and when I invoked try.yaler it came back with the 504 error,,, still does even when I go back to the version described here which was working last Sunday and hasn't since.
Can't get your link above to connect either.
tamberg (author) in reply to tedlawsonJun 2, 2011. 5:12 PM
Hi Ted,

the memory on the Arduino is pretty terse. Depending on the size of your change, that might lead to the Arduino code not running at all.

The example above on the other hand, just needs a rest.

Cheers,
tamberg
tedlawson says: Jun 1, 2011. 8:26 PM
Was up & running. Now seems I (or your demo) can't connect with Yaler. Is this service intermittent. Have JTV embedded nicely in my web site (tedlawson44.com/catcam/JTV.html), but haven't had a chance to see it in Yaler due to the (disconnect?)
1-40 of 46Next »
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!