Pages

Creating a Pachube controled RGB LED

This article describes a simple application to demonstrate the ENC28J60 EtherShield library. It can be run on a plain Arduino or clone and an ethernet shield based on the ENC28J60 ethernet chip (Note: This is not the same as the official ethernet shield). An alternative is to use the Nanode, wiki site at Hackspace which combines the arduino and the EtherShield into a single compatible board. It also demonstrates the network capability of the board and the control functionality included in the Pachube dashboard application.

For this project you will need:

  • Arduino or clone and ENC28J60 based ethernet shield or a Nanode
  • Pachube account and master api-key
  • RGB LED and 3 current limiting resistors, value depends on specification of LED
  • Internet connection with router running DHCP server

RGB LEDs

RGB LEDs are available in the UK from:

Oomlout. I received one of these LEDs as a sample in an order and can say it is a good bright LED with a cloudy lens which helps blend the colours.

Earthshine Electronics. I’ve not tried these, but for a pack of 10 they are a bargain!

There are two types of RGB LED, one with a common cathode (negative) and the other with a common anode (positive). Both will work with the example provided the correct option is selected at the top of the example code. If this is set incorrectly then when you expect the LED to be on, it will be off and vice-versa.

Similar RGB LEDs should be readily available in whatever country you reside in.

Setting up Pachube feed

For the demo we are using the Pachube dashboard to create a set of three knobs that control the datastreams in a feed. The datastreams and feed are created in your account when the dashboard is created. The steps are described in detail below and shown in the screen captures.

  • Login to www.pachube.com
  • Click on the link my api keys. Take a copy of your master API key as you need it in the app.
  • Visit the Pachube dashboard app page at http://apps.pachube.com/dashboard/create.php
  • Enter 0 for number of switches and 3 for number of dials then paste your master API key in to the box.
  • Open the link that says Then click here when you are ready! in another browser window or tab
  • you should then see the results with 2 links, one to the dashboard and another for the stream.
  • To make things look nice, we should edit the stream first. As per the screenshot below, set the stream names in the Tags fields to Red, Green and Blue then click the Save Feed button.
  • Go back to the results tab and open the dashboard URL in another window or tab. It should now have the dials labelled Red, Green and Blue

Get your master API key Create the app, select 3 dials All created

 
Update the feed names Access the dashboard  

Running the example code

After installing the EtherCard library, launch the Arduino IDE, copy and paste the sketch from https://github.com/thiseldo/EtherCardExamples/tree/master/EtherCard_PachubeRGB. The parts to change are:

  • Set the type of RGB LED, use #define COMMON_ANODE for common anode LEDs and #undef COMMON_ANODE for common cathode LEDS
  • Set BLUEPIN, REDPIN and GREENPIN to the correct PWM ports used for your LED, defaults are 3, 5 and 6
  • Define your Pachube master API key in the HOSTNAME variable. Replace the XXXXXXXXXX part with your API key
  • Define the feed number to use in the HTTPPATH. Replace the NNNNN part with your feed number

Upload the sketch to your Arduino or Nanode, plug in the ethernet and away it should go. Initially the LED is Red, then amber while it is allocating an IP address, then green when it is ready to request Pachube data.

Select your browser window with the Pachube dashboard, point your mouse at the end of one of the knobs and drag it round, the value should change on the dashboard. After a few seconds you should also start to see the RGB LED change colour.

Nanode working RGB LED Close up view of RGB LED and current limiting resistors

This is only an example, however, with suitable code it could be reading a Pachube feed that monitors your electricity usage and changes colour according to how much is being used, i.e. green for low and red for high power usage.

Bookmark this post: bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

6 comments to Creating a Pachube controled RGB LED