Introduction: Add Wireless Lights to Your Home

About: maker
The Problem: It gets dark at night.  Single-color lights are quaint and 20th century.
The Solution: RGB LED strips!  Bright, weatherproof, and easily hidden.

Step 1: System Overview and Bill of Materials

My primary goals for this system were simplicity and flexibility.  I used premade parts where it was cost effective, and spun my own where I could.  While I had a board made, you could easily breadboard your own without needing to send out for a pcb.

All the files are at http://github.com/rmd6502/hall_lights_connectport

Each light has a power supply, XBee, Arduino, XBee Shield, 6- and 8-pin stackable headers for the shield, three or 6 MOSFETs, and 6 or 10 pins worth of screw terminals as 2+4 or 2+8, in addition to the light strip itself.  The gates of the MOSFETs are connected to three of the PWM outputs (yes, you can control two lights with a single Arduino, that's in the works).  A simple serial protocol lets you set and query the color of the light(s).

For the central control and web server I used a ConnectPortX2.  This is a relatively cheap box that has a builtin XBee and ethernet port, and is programmable in Python.  The Connectport acts as an XBee coordinator, and automatically catalogs the XBees it finds for the script to present to you in a web page.  You'll also want an XBee Explorer so you can program the XBees.

If a web browser is inconvenient at the time, there's also an iPhone app that will control the lights with a nice color picker interface.

You'll need a 10KΩ pulldown resistor for the gate of each MOSFET.  This ensures the MOSFETs turn all the way off, and also eliminates flicker between the time the power comes on and the Arduino starts up.

If you go for the custom board you'll also need a fuse, voltage regulator, XBee socket, and assorted bypasscapacitors.  Since the MOSFETs have pretty low RDS(ON) even at 3.3v, I chose to make the whole system use 3.3v so I didn't need to convert voltage for the XBee.

For convenience, all the non-documentation links go to the appropriate Sparkfun product page.  They don't seem to have a 12VDC 6A power supply, I used a surplus one meant for monitors from EBay.  You can save some money by shopping DealExtreme, EBay, Digikey/Mouser/Element14, and Radio Shack, but you'll have to wait longer and submit multiple orders.

So the final bill of materials:
  • 1 RGB light strip of your choice
  • 1 Power supply rated for the full output of the light strip + the Arduino
  • 1 Arduino or clone
  • 3 or 6 MOSFETs
  • 3 or 6 10kΩ resistors
  • 1 XBee S2 (not S1; it won't talk to the connectport) - I think the S2B works without needing a firmware update, which needs a Windows machine.
  • 1 XBee shield
  • 1 XBee Explorer
  • 1 Digi Connectport X2
  • 2 6-pin stackable arduino headers
  • 2 8-pin stackable arduino headers
  • 6 or 10 pins worth of screw terminals

Step 2: Assemble the Lights

The first image is the schematic I used - the transistor part numbers are different since they're surface mount parts.  I also broke out all 6 PWMs.

You can breadboard this, or solder into the XBee shield's prototyping area.  Size is not to scale.
  1. Solder the 6 and 8-pin headers to the XBee shield.
  2. Solder the screw terminals into the prototyping area, along the edges as shown in step1.png
  3. Solder in the resistors and transistors as shown.  It's very important that the heatsink mounting tabs don't touch - those are connected internally to the drain also, and will short.  See step2.png
  4. Connect the transistors, resistors, and screw terminals as shown in figure 3.  Best bet is to print out the image and cross off the wires as they are soldered, so you don't miss any.
  5. Solder wires (these can be thinner) to the appropriate pins on the arduino.  The XBee shield has a second row of pins broken out for the Arduino pins.  Ground will have to come from one of the XBee pins.
  6. You can now use the screw terminals to connect the power (to the 2 pin).  Note polarity carefully before plugging anything in.
  7. Perform a quick smoke test with by plugging in the power supply with nothing else connected.
  8. Attach the LED string to the CRGB header and once again perform a smoke test.  The LED string should stay off, and nothing should heat up.
  9. Attach the shield to the Arduino!

Step 3: Upload the Arduino Sketch and Test

Go to the github page and download the .ino file if you haven't already.  Flip the switch on the XBee shield to the DLINE position.  Don't plug in the XBee, remove it if you did.

Upload the sketch the normal way, then start the serial monitor at 9600 baud.  If all goes well, the LEDs should come on a warm white color.

Select CR+LF as the line endings in the serial monitor, then enter r255g0b0 and hit send.  Only the red lights should come on, at full brightness
Enter r0g255 and hit send.  Now the green LED should be on full brightness.
Enter g0b255 and hit send.  The blue LED should be on full brightness.

If it doesn't work right, go back to the previous step and check all your wiring.

If it did, have fun setting different colors.

When you're done, flip the switch to UART.

Step 4: Set Up the XBees

For this step you may need access to a Windows machine.  
  1. Plug in the connectport's power supply and ethernet cable.  Find its IP address and navigate there with your web browser.
  2. Attach your XBee to the XBee explorer and connect it to your computer with the USB cable.
  3. On your browser, you should see the first screen.  Click XBee Network on the left.  Click the button labeled "Discover XBee devices"
  4. With luck the green LED on the XBee explorer will come on and you'll see it in the list.
  5. If not, you'll have to update the firmware of your XBee.  You'll need to go to digi.com and download the XCTU software, and the latest firmware.  There are a plethora of options and alternatives, I've found that 22A0 seems to work - you want the ZB AT Command Set Router.
  6. Update the firmware with XCTU on Windows.
  7. Hopefully you can now see your XBee in the list.  Click on the node to go to the configuration screen, where you can change the node name (that's what will appear on the web page), and transmit power (you can turn this down unless you live in a very large house)
Repeat for all the XBees you're hooking up.  Remember to give them all different names!

You can now plug the XBee into the shield, and make a nice case for the Arduino.

Step 5: Set Up the Connectport

In your web browser, select "Python" from the Connectport's menu.

Upload lights.py and colors.py by choosing them and clicking the upload button.  I believe you'll have to do them one at a time.

Once the files are uploaded, go to the bottom of the screen and select "Auto-start settings"

Enter lights.py in the auto-start command line, then click the Enable checkbox on the left.

Reboot your Connectport from the menu.  While you're waiting, plug in the lights you've assembled.

Navigate to the ip address of your Connectport + "/lights", so if your Connectport is at 192.168.0.110, you'd go to http://192.168.0.110/lights.

If all goes well you now have web-connected LED lights.  If not, please comment to this Instructable and I'll try to diagnose.

Step 6: API

Since I don't have any security on this, you probably don't want to put it on a public port.  There's another endpoint, /query, that you can use to get an XML dump of the lights and their current status. 

Note that nodes never come off the list, though the time they were last heard from will not get updated.

The iphone app will color any nodes that have not been heard from in 90 or more seconds as inactive.

Have fun!!

Step 7: ADDENDUM: Rolling Your Own

So you've decided that you need 20 of these things all over the house?

The hardware directory of the github repo contains my Eagle files for my controller board.  I was able to have them made at Seeedstudio in Hong Kong relatively cheaply, and they work great.

However, you'll need to follow some special procedures to get these guys programmed.  You'll need an AVR programmer, since the board I designed doesn't use a crystal, and the bootloader assumes one.

Buy some ATMega328 chips (or mega168, they're a little cheaper).  Sparkfun sells one with the Arduino bootloader preinstalled.  Put this into your favorite Arduino board and attach the programming cable.  Start up the Arduino software and change the board type to "Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328" (or ATMega168 if you bought that).  Then set up for whatever programmer you have and select Tools->Burn Bootloader.  This will also set the fuses to use the internal 8MHz RC clock instead of the crystal.

EDIT: If your ATMega328 gives "USB: port not found" errors from AVRdude, you'll need to go to the command line. Instructions are given here for the mac, since that's what I have.  The procedure should be similar for linux, and you can use AVR Studio for windows.

Download the optiboot firmware.  Also download and install Crosspack-AVR.  Optiboot won't work at the default 115200 baud with an 8MHz clock, you'll have to modify the makefile to change it to 57600.  Find the line that reads 
atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
and change 115200 to 57600.  Remove optiboot_atmega328_pro_8MHz.hex then type "make atmega328_pro8".

Now you need to program the chip and the fuses.  Enter the following line (you may need to customize if you have something other than an AVR Dragon):

avrdude -P usb -c dragon_isp -p atmega328p -U hfuse:w:0xde:m -U lfuse:w:0xe2:m -U efuse:w:0x05:m -U flash:w:optiboot_atmega328_pro_8MHz.hex

Now remove the AVR Dragon and plug the Arduino board back in.
END EDITS

Now you can program the sketch into the Arduino using the same settings.  Take the chip out of the Arduino and plug it into the board.  Smoke test and connect as described in the "Assemble the Lights" step, and proceed from there.

Make It Real Challenge

Participated in the
Make It Real Challenge

Arduino Challenge

Participated in the
Arduino Challenge