The best/easiest way to switch relays is through something like a
ULN2003A darlington array.
They include flyback diodes and a transistor in a common package
If you haven't any of these, you can use an NPN transistor and a diode
on every relay you need to switch.
I'll try to describe it in words:
Your relay coil is connected to +5V (or whatever power source you're using)
The ground pin on the relay coil goes into the collector pin of a transistor
The output from your Arduino goes to the base (gate) pin on the transistor
The emitter pin on the transistor goes to ground
Now, when your Arduino output goes high, it allows current to flow from
the collector through to the emitter (and away to ground) thus
activating the relay.
When the relay goes off, you might get some back emf, so you put a
flyback or free-wheeling diode from the emitter pin (the one connected
to ground) and allow the current to flow (counter-intuitively) from the
emitter/ground pin "past" the transistor, and into the positive
connection on the relay coil. Any back emf created when the coil goes
off is safely handled.
I'll post a diagram and link to it in a min......
On 17/11/2012 22:28, Seb Lee-Delisle wrote:
> Hi everyone!
> We've attached a relay directly to an arduino pin and gnd, and I now
> gather that that's not a great thing to do :)
> We'll be rebuilding the circuit (as in this diagram
> http://www.kpsec.freeuk.com/components/relay.htm#protect ) when I get
> back to Brighton, but in the meantime, can I protect the arduino using
> just a diode?
> Any advice would be appreciated.
> You received this message because you are subscribed to the Google
> Groups "BuildBrighton - the Brighton Hacker Space" group.
> To post to this group, send email to email@example.com.
> To unsubscribe from this group, send email to
> For more options, visit https://groups.google.com/groups/opt_out.