Instructables
Picture of Wi-Fi Controlled LED Candle / Light Show
schematic_light.png
pcb.png
light_assembled.png
light_enclosure.png
lightcontroller2.png
INTRODUCTION

This project is a wireless full-color electronic candle.  Several of these devices can be placed around a room and controlled with a Wi-Fi capable computer to create special effects or music-synchronized light shows.

The entire hardware and software design is offered free and open-source.




HARDWARE

The hardware relies on a RN-XV Wi-Fi module to provide wireless network connectivity.  A PIC12F683 microcontroller communicates with the RN-XV, processes incoming messages from the network, and generates pulse width modulated (PWM) signals to drive an array of red, green, and blue LEDs.  This gives the device the ability to reproduce the full color spectrum at a full range of brightnesses.

The RN-XV WiFly module serves a crucial role in forming a wireless adhoc network with the control computer.  The module is programmed with a unique IP address.  Control messages are sent from the control computer via UDP datagrams.  The data format is extremely simple, allowing multiple devices to be managed on the network with minimal latency.  The WiFly module automatically processes the incoming UDP datagrams, and transforms the messages into an asynchronous serial stream that can be read and processed by the PIC microcontroller serving as the PWM controller.

The PIC12F683 is a very small, economical, and convenient microcontroller for this application.  It is a simple 8-pin device, but with a little bit of effort, it provides all of the capabilities we need.  The 12F683 lacks an integrated UART, so all serial communication with the RN-XV is performed through bit-banging.  The 12F683 also provides a very limited instruction set, which makes certain mathematical operations somewhat difficult to implement.  However, all of these issues can be overcome and implemented using pure PIC assembly language.

The biggest complication of this development effort is the fact that the PIC12F683 microcontroller has only one onboard PWM generator.  So three 8-bit PWM outputs are implemented in code using general purpose I/O pins and timer interrupts.  This task is made even more difficult because the PWM routines have to be synchronized with the UART routine (also implemented in code).  The first implementation of this routine resulted in a very pronounced glitch in the PWM output due to interruptions by the incoming serial data.  This issue was resolved by ensuring that the serial bit period was evenly divisible by the PWM cycle period.  Then only one timer interrupt is required, and each incoming bit can simply be read every N number of PWM cycles. 

The device can be powered by a 5-15VDC source, which is regulated to 3.3V -- a requirement of the RN-XV module.  The PIC12F683 has a much broader operating voltage range, but 3.3V is used not only to maintain commonality with the RN-XV supply voltage, but also to guarantee compatibility with the 3.3V signaling requirements of the RN-XV UART.  Another interesting note is that the LD1117V33 linear regulator is able to operate comfortably with up to a 15VDC input, even in a TO-220 package with no heatsink.  This is due to the fact that the RN-XV draws very little current -- one of several reasons it was chosen over the Digi XBee Wi-Fi module for this application.  With an XBee module, the power dissipation required for a 15VDC input would necessitate some additional heat management measures, which in turn would require changes to the PCB.

In order to make the device truly wireless and self-contained, power is provided by 4 AA batteries.  A switched battery holder works as a convenient base for supporting the circuit board.  Because the circuitry is typically hidden inside a decorative enclosure, a simple rubber band holds the circuit board in place.

The hardware schematic and microcontroller firmware source code are available for download at the main project website (see SOURCES section below for hyperlink).


CONTROL MESSAGE FORMAT

The control message format is extremely simple and designed for minimal latency.  Each color is independently controlled by sending a single byte value consisting of a 2-bit color address (A) and 6-bit intensity level (L):

MSb             LSb
A A L L L L L L

Color Addresses: Red = 00, Green = 01, Blue = 10
Intensity: 000000 = Off, 111111 = Fully On

Typical messages from the software consist of all three color control bytes concatenated into a single 24-bit message that ensures all three colors are updated simultaneously.


PCB LAYOUT

The circuit board was original developed for a different project, so the component layout is not ideal for this application, but it is functional.  The PCB layout gerber files are available for download at the main project website (see SOURCES section below for hyperlink).  Pay close attention to the PCB layout versus the schematic, because to properly use the layout, cut the traces on the U2 (microcontroller) side between C4 and D1, C5 and D2, and C6 and D3.  Don't cut any traces on the ground side.  Then jumper the U2 side of C4, C5, and C6 to the J1 side of R1, R2, and R3, respectively.  This will make sure the outputs from the microcontroller are each routed through current-limiting resistors on the way to their respective LEDs.

The primary interface to the PhantomLink device is a DB-9 connector.  The standard pinout is modified to provide power to the device.  The serial data lines are only used for initial programming of the RN-XV (though its usually easier to program the XV using its adhoc command mode).


WI-FI MODULE CONFIGURATION

The RN-XV WiFly module must form a wireless adhoc network for the control laptop to join and communicate with the various lights.  Follow the RN-XV instructions for accessing its command mode, then enter the following command sequence and save the configuration.  Note this is a one-time process, so once the settings are saved in the WiFly module, they will never change.

set wlan join 4
set wlan ssid PhantomLink
set wlan chan 1
set ip dhcp 0
set ip address 169.254.1.1
set ip netmask 255.255.0.0
set ip local 2000
set option format 0
set uart mode 0
set sys mask 0x2100
set ip protocol 3
set uart baud 2400



ENCLOSURE

The three LEDs don't produce a good color mixture without a good way of diffusing the light.  To get the proper effect, a 4" x 4" x 6" clear plastic box was lined with crumpled white tissue paper.

This enclosure provides enough width to conceal the inner contents, and enough height to place the light source in the center of the box.  The result is a glow that seems to emanate from the middle of the box but has no distinguishable source.


SOFTWARE

The light controller software provides a comprehensive set of features for controlling one or multiple candles.  The software is written in Java and can run on any system capable of communicating on a Wi-Fi wireless internet connection.  Control messages are sent via UDP datagrams using a simple 24-bit message format.  The controller software provides several preset effects as well as manual controls for each networked device.

An entire performance sequence can also be programmed on a timescale, which can be optionally synchronized to a music file source (visualized at the top of the screen).  This first implementation imports WAV files (currently 22050/mono only), though future support for more formats will follow soon.

The programming interface is mouse driven and highly intuitive. The user simply selects a region on the timescale, then right-clicks to select from a popup menu of available effects and colors.  Each effect and/or color can be applied to a single device or to all.

Another interesting feature is a "training" mode which allows the user to manually trigger a light in real-time as the audio source is played.  These triggers are recorded in real-time, ready for immediate playback when the audio is restarted.  This recorded triggers can then be tweaked and edited as needed, but the most tedious work -- synchronizing the lights to the audio -- is already done by the training process.


SOURCES

The firmware and software source code, binaries, and PCB files are available for download on the main project webpage at http://www.phantomlink.com/lab/light.aspx
nexus9871 month ago

hi the link provided is not working anymore

Please advise how to get firmware and software source code