0

My first project - finished! (nearly)

Posted by Chris on Wednesday, April 29, 2009 in , ,
Well here it is, my first USB-driven device, all soldered up and ready to go.
In case you're wondering, it's a (USB-driven) relay switching device but also has the facility to receive switching instructions via serial communication (so it can be connected to a PC serial port or perhaps even a radio receiver).


Almost there - a few terminals to connect to the common and NO/NC switches on the relay, and some decoupling capacitors to keep the supply voltage from dipping, and I think we're done!


After quite a bit of discussion on a couple of electronics forums, and some help from electro-tech-online, I discovered a couple of interesting things about switching relays. First off, PIC microcontrollers aren't powerful enough to drive a relay coil - you need to use a transistor to provide power to the relay, and use the PIC signal to switch the transistor "on" and "off". Secondly, when using transistors like this, the switching should be done on the 0v side of the coil - not as I had originally done, on the 5v side of the coil. Because relays can generate back-emf when the coil is switched off, it is also necessary to include a "flyback diode" to stop reverse voltage spikes from frazzling the other components on the board, when the relay is no longer energised.

One of the most important things I learned was that I'm rubbish at soldering component parts, but not bad at soldering DIP holders and chips (with plenty of liquid flux thrown around the place). So for each relay that was to be switched, I eventually (after three/four different PCBs were made up and soldered - badly) discovered the ULN2803A chip, better known as a relay-driver. This includes the transistors and reverse diodes as part of the package so simply put, you can send a PIC signal to one pin and connect the relay contact directly to the other side - no need to mess about with any other component parts. This not only reduced the component count on the board (reducing cost to make!) but made the PCB layout quite a bit simpler - and the finished soldering look much, much neater!


Soldering the pins on IC chips is a doddle - quick and easy does it. Soldering little fiddly things like transistors and diodes can be a pain. Stick to IC (integrated circuit) blocks were possible!


Another important lesson was the difference between "sink" and "source" switching.
The ULN2803A can only sink voltage - i.e. it must be connected to the 0v rail - each of the relays is permanently connected to the 5V supply voltage and the relay-driver chip connects the relay coil to ground. It simply doesn't work the other way around: if it took 5V and switched it to drive the relays on and off, this would be "sourcing" and not "sinking" the voltage.

All in all, quite a lot learned. Most of it, to be honest, relearned: I'm sure I learned a lot of this in school, many years ago - but the old adage holds true - use it or lose it. I'm quite enjoying rediscovering things that at the time I thought were a waste of time and useless!

Following on from this, I think I'm shortly in for another whole world of hurt, after reading this post about switching 240v appliances. I know that my board needs A LOT more decoupling, but it's nice to hear the faint click-clack of the relays in response to a few bytes of data sent from the PC. Maybe I'm just a few days behind everyone else working on a similar idea....

0 Comments

Post a Comment

whos.amung.us

Copyright © 2009 .Nerd Club All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive Supported by Blogger Templates.