The SparkFun 5V SPDT relay is typical of its kind. Although its coil needs only 5V to switch on, it needs more current than the Arduino can supply – although in practice it does work connected directly. Its coil resistance is 57 ohms, therefore it needs 88mA @ 5V to turn on consistently (i = 5/57 = 0.088 A). The Arduino can only supply 40mA per pin, so for reliability you should drive the relay with a transistor. For any relay whose coil requires more than 5V (many require 12V), the need for a transistor is more obvious.
See http://teaching.ericforman.com/relay-circuit/ (the first diagram is for a reed relay, look at the links under for examples with this kind of relay). With any electromechanical relay, you should protect the Arduino and the rest of your circuit with a diode.
If you want to save time, buy something like this https://www.sparkfun.com/products/11042
How fast can it switch on and off?
It’s a mechanical device with moving parts, so it’s not blindingly fast and you can hear it click. But it’s still pretty fast. On the datasheet it says
Operate Time: Max. 20mSec.
Release Time: Max. 10mSec.
That means it will take at most 20mS to turn on, and 10mS to turn off. It might be faster than that, but probably not. So you should avoid trying to force it to switch faster than that. So if you were blinking it, make sure you wait 20mS after you turn it on, and 10mS after you turn it off. E.g. fastest possible blink time (assuming you wanted that, and also that you wanted it to be on longer than off):
// fastest possible blink for typical electromechanical relay
digitalWrite(relayPin, HIGH);
delay(20);
digitalWrite(relayPin, LOW);
delay(10);
HOWEVER – some things, for example a ballast and fluorescent light, aren’t designed to switch anywhere near that fast. So use trial and error to find out the fastest you can switch those without getting weird hums or flickers.
If you need a relay that switches faster and/or is silent, look for SSR – Solid State Relays. Example: http://www.sparkfun.com/products/10636
Just wanted to send a big thank you from a complete newb whose been searching for an explanation on how to complete an spdt relay circuit with arduino. Been going over pages and pages of sites for the past few days and have gotten some questions answered but nothing as conclusive as what your diagram illustrates. A picture is worth a thousand words. Thanks.
LikeLike
Sir,
I was looking all over the place for this. I have a project due next week and I’m insanely grateful for this.
Thanks a ton. Keep writing. 🙂
LikeLike