Dec282006

Microcontroller-controlled Relays (Partylights)

The prototypeObjective:

Control high voltage, high current devices using a microcontroller

Background:

Inspired by the guys on YouTube who control their Christmas lights and synchronize them with music, I set out to learn how to attach relays to my Freescale 9SS12C32 microcontroller. I did some research into the parts I would need and ordered them without any specific task to accomplish once the microcontroller controlled the relays. I started with a setup just using one relay and got that to work. I later added 3 more relays so I could control 4 sets of Christmas lights and sync them to the tempo of music for our party They’re The Most Wonderful Times of The Year (the video shows the lights).

The relays usedParts Used:

Microcontroller w/ Technical Arts docking module (Technological Arts part: NC12C32SP-SB)
4x Relay (L90-5W)
4x PNP Transistor (2N4403)
4×200ohm Resistor
4×10Kohm Resistor
Open Collector Hex inverter (7406) (open collector can receive up to 40mA current)
4x LEDs (functionally just diodes, but the light helps debug)
Power Strip

Hardware:

The relays have an impedence of 27Ohms and the prototyping board UT students get from Technical Arts has a +5V port that can supply up to .5A of current. Going slightly over this amount does not damage the microcontroller, but instead resets it. Instead of drawing voltage straight from the microcontroller, I used an open collector inverter. This provides a buffer between the microcontroller and the circuitry so I fry the $.30 inverter before the $10 microcontroller.

The prototype

The 7406 (Open Collector Inverter) can only accept 40mA and it takes around 185mA (I = V / R where V = 5V and R = 27Ohms) to switch the relays so I was not able to connect the relays directly into the 7406. So I did a little learning and came up with a circuit based on a PNP transistor that would allow me to supply 185mA to the relay while still using the 7406 as a buffer between the microcontroller and the relay. That schematic is below.

The LED is used as a protection diode which dissipates the remaining energy stored in the magnetic field of the relay’s coil.

The schematic

I implemented the above schematic 4 times in order to control 4 relays.

Software:

I built this setup to set a dancing mood for a party; I needed software to synchronize the switching of 4 relays with music.

I didn’t have the experience / time to build something that would detect peaks, so I decided to write a program that would allow me to set the tempo manually. The program I wrote in assembly, executed a simple state machine that switched on one relay, then then next, then the next, etc. When input was detected from the serial port (SCI Receive Interrupt), the software executed a function that waited for three more key presses, averaged the interval between them, and set the state machine to switch at that interval. With this I could tap a key four times to set the tempo. Get the code

I then connected my ATI Remote Wonder so that I could set the tempo from a remote in my pocket.

Check out our party They’re the Most Wonderful Times of the Year to see this in action.

References / Thanks to:

The Electronics Club – has information about transistors
Dr. Jonathan W. Valvano – my Introduction to Microcontrollers professor

Write a comment


If you have trouble reading the code, click on the code itself to generate a new random code.
 
Comment Lily on : Fri November 25, 2011, 22:34:21
Hallelujah! I needed this?you're my saovir.