I need to control a coffee machine plugged into a wall outlet using a relay connected to an arduino. Apparently I need to connect a transistor to the relay. Why? Is it because the arduino can't supply enough current to trigger the coil in the relay?

So the info on the packaging of this relay says "R46-5D12-12 ROHS SPDT 12A-12VDC". How do I go about choosing a transistor? Will I need anything else other than a diode?

edit: The relay will need to be triggered for about 0.5 - 1 seconds every once in a while. The load is definitely not big. It'll simply replace the power button on the coffee machine with an arduino.


There are multiple reasons you want to do this in your case the reasons I can think of are:

1) The relay needs 12V on the input to turn on. An Arduino GPIO only outputs 5V. A transistor in between will allow a 5V signal from the Arduino to switch a 12V signal via the transistor to the relay - thus turning it on.

2) The transistor provides protection. In the event of a back emf voltage spike or some other undesired event only your transistor will be blown, instead of the entire Arduino.

3) Using a transistor should provide marginally faster switch times because the transistor can source more current than the few mA that an Arduino can - thus saturating the coil faster.

Read this info sheet (http://www1.electusdistribution.com.au/images_uploaded/relaydrv.pdf). and pay attention to these images in particular. They show you what a good switching circuit would be and explain how to implement them.

enter image description here

  • \$\begingroup\$ Do you think a 9V battery would be sufficient given that I wait longer for the switch in the relay to activate \$\endgroup\$ – Sam D20 Mar 9 '14 at 2:04
  • 1
    \$\begingroup\$ The 9V would die pretty quickly if you want to keep this in your kitchen indefinitely. In my experience relays are very robust parts and will probably work at 9V. That said you will be operating out of spec so behavior is unpredictable and sometimes the coil may not energize or provide a poor connection. \$\endgroup\$ – EasyOhm Mar 9 '14 at 2:06
  • \$\begingroup\$ The entire setup will need to be test run about 15-20 times in total, it is for a competition, not actually going into my kitchen (yet). You think I'll be fine? \$\endgroup\$ – Sam D20 Mar 9 '14 at 2:11
  • 1
    \$\begingroup\$ Yes a battery will work 15-20 times. I can't guarantee it will be fine because you are operating beyond part specifications. The best way is to test it. Connect a 9V battery to the coil of the relay and test for continuity with a multimeter (or if you don't have that listen for a click). \$\endgroup\$ – EasyOhm Mar 9 '14 at 2:14

Is it because the arduino can't supply enough current to trigger the coil in the relay?

Yes. An Arduino (really, a ATMEGA328p or similar) can only provide 20~40mA on a single pin without significant voltage droop and possibly frying the pin. A relay coil can take significantly more. And the Arduino pin output is referenced to VIN, or 5v on a typical arduino. The relay requires 12v, which a transistor can switch.

To choose a transistor, you need to know the Relay's activation current. This can be found on the datasheet for the relay. Once you know the activation current, you want a transistor that can handle 20% more current (as a safety precaution), and that has a gain (hfe) that can amp a few mA at the base to the current needed at the collector. Aside from the flyback diode, you need a resistor between the Arduino and the transistor base (to protect the Arduino output and the Transistor base input.)

  • \$\begingroup\$ Thank you for clarifying. Could assist me in locating the activation current for this relay? The only thing I see on the packaging is what I've typed in the original post. \$\endgroup\$ – Sam D20 Mar 9 '14 at 1:59
  • \$\begingroup\$ Any standard transistor should be fine (for example NPN 2N3904 found here [ sparkfun.com/products/521 ] or on digikey). I've switched relays even without a transistor in between. Your main problem is that you need to provide 12V input on the relay. \$\endgroup\$ – EasyOhm Mar 9 '14 at 2:02
  • 1
    \$\begingroup\$ Datasheet farnell.com/datasheets/1750340.pdf The coil is ~400Ω, with a 12v voltage, that is i = v / r, so 12 / 400 or 0.03A. So a common 2n2222 or 2n3904 will work. \$\endgroup\$ – Passerby Mar 9 '14 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.