I'm using a couple arduino pro mini's (3.3V) for a home automation project and want to add relays to the final PCB design to switch some stuff on and off.

Since I want to use a 5V relay like this: HF 46F 5V, Miniature HF power relay, 5 V, 1 NO 5 A

I wonder how I can switch this relay with the arduino, since the pro mini only has an output of 3.3V on the pins? The arduino is driven by a 3.7V Li-Ion Battery.

Another question would be how to use the relay safely with high voltages? (apart from trace-width and trace spacing between high and low voltage parts on the pcb) Thanks in advance!

  • 1
    \$\begingroup\$ Why not pick a lower voltage relay? There is a 3V version of the model you linked to. You may find that 3.7V is enough to close the contacts on some higher voltage relays; it will say in the datasheet. The minimum 'pick-up' voltage for the linked relay is 3.75V, so it would not work. I have no experience of undervolting a relay long term, so I cannot say for definite that you should rely on that technique. \$\endgroup\$ – CharlieHanson Jan 23 '16 at 18:41
  • \$\begingroup\$ Run the relay from the higher voltage PSU that's feeding the Arduino and take the load off the 3.3 V regulator. You're looking for a MOSFET or transistor switch. There are thousands of posts on this SE site regarding this. \$\endgroup\$ – Transistor Jan 23 '16 at 18:43
  • 1
    \$\begingroup\$ @CharlieHanson there is no way the controller can source/sink enough current to directly drive a relay like this, even if the coil voltage matches. You'll always need some sort of a buffer stage. \$\endgroup\$ – jippie Jan 23 '16 at 18:45
  • \$\begingroup\$ @jippie I did not say the controller ever could. As this was a comment and not an answer I didn't see the need to wax lyrical about current issues. \$\endgroup\$ – CharlieHanson Jan 23 '16 at 18:54
  • \$\begingroup\$ Why is this battery powered and not using a power supply derived from the load supply? Even if you want the MCU battery powered for backup purposes, run your switching element (relay, etc) from a supply derived from the load supply - there's not a lot of benefit to clicking the relay if there's no mains power to run the load, and your battery life will be a lot better if you don't run the relay coil off of it. \$\endgroup\$ – Chris Stratton Jan 23 '16 at 20:07

There are an awfull lot of ways to connect a 5V device to a 3.3V output pin.

//edited The original/accepted answer can be found below. This edited part should be an improved version of the original one.

Mind that this answer is for driving relays, if you're going to switch 20VDC at ~3A, a MOSFET will be a better/cheaper solution, as you don't need the relay.

Output pins shouldn't be used to drive anything. Output signals are low current control signals. It is somewhat accepted to drive a LED directly from an output pin (if using a high enough current limiting resistor), but it may lead to problems, since the total current over multiple pins can also be limited by the hardware. For communications, it may sometimes work to use 3.3V since it could be registered as a logical high, but you better not rely on it, for any serious applications.

You can choose a relay that can work with low voltage/low current. Your best bet would be a "solid state relay", since these do not require a coil to be energized and may work on low voltage/current. Check the specs to find one that fits your needs.

Usually, you're ging to power the 3.3V device from something like 5V USB or 9V plug. These sources can often provide the power required to energize the coil of your relay. You will have to make the control signal of your board and switch the "input power" over the coil of your relay. (TODO add diagram, I'm currently unable to, give me 12h)

Mind that some relay breakouts already have circuitry for this. And that your input voltage shouldn't be higher/lower than what the coil is rated for. Your source should be able to supply enough current for the relay.

The coil may "suddenly" take a lot of current, you may see that the voltage on your board drops, or that it resets. Often, the power supply isn't "responsive enough". You can fix this by adding a capacitor to "buffer" the power, so it can be releases at the very moment the coil needs to be energized, and it won't take the power away from the rest of the board.

//end of edit

  1. Just connect it. (The wrong way)**

This might work in some scenario's, but not this scenario. The relay will draw too much current. For connecting a low current data-connection, it can actually work since the 3.3V might be seen as a logic HIGH.

2. The Arduino way.

Buy a TTL Logic Level Shifter - https://www.sparkfun.com/products/12009

This little board will change output 5V, when given 3.3V at the signal in. The only problem, however, is that you will need a 5V on the input of the board.

3. The Electronics way.

You can easily use a transistor or mosfet to switch another (higher) current. This doesn't really differ that much from option 2, but it's a litte more complicated, but cheaper.

4. Another way, like a boss.

Search Stack-Exchange/Google for people with the same problem. I've found that you can actually step up 3.3V to 5V, so that you won't need a 5V supply. https://www.circuitsathome.com/dc-dc/33v-to-5v-dc-dc-converter

5. Workaround

Get a relay that works on your battery voltage and can be triggered from 3.3V. You could consider something like this: http://www.ebay.com/itm/5PCS-3V-3-3V-Relay-High-Level-Driver-Module-optocouple-Relay-Module-for-Arduino-/331413255692

It has an optocoupler, to isolate the arduino from the actual relay. It might be better to get one that actually works on your battery voltage range. So that you can hook it up to the battery (and the signal pin to the Arduino). So the coil isn't activated directly by the arduino, which would draw too much current.

6. Using a 5V supply

You can turn the things around if you really want to. You might want to use an USB-Powerbank (or some self-made/supplied circuitry) for powering your pro mini, the pro mini will be able to take the 5V directly.(https://www.arduino.cc/en/Main/ArduinoBoardProMini)

You can now use the 5V to power your relay using options 2, 3 or 5.

| improve this answer | |
  • \$\begingroup\$ @jippie You're right, immediately edited it when I saw it. \$\endgroup\$ – Paul Jan 23 '16 at 18:52
  • \$\begingroup\$ thanks! I think it would be better to use a 3V relay, in this case I don't need the voltage regulator (which takes much space which I don't have).<br/> I will go with the cheap chinese Songle SRD-03VDC-SL-C (i will only use this for voltages under 20V DC) To drive the Songle relay safely, I need a transistor and a diode (please correct me if I'm wrong) I will go with the NPN 2N2222 and the 1N4007 if that's ok. Here's how my schematics are looking (D5 is Digital arduino pin 5; GND.2 is GND of the arduino): link \$\endgroup\$ – Henry Jan 25 '16 at 2:05
  • \$\begingroup\$ @Henry I don't know that much of Electronics/schematics, but that's not going to work. You need to put the battery in series with coil, and use the transistor as a "switch". So the Arduino can activate the transistor, and let the higher current of the battery to the heavy lifting. I could check if I can make a schematic, but it'll be tomorrow. \$\endgroup\$ – Paul Jan 25 '16 at 2:09
  • \$\begingroup\$ yes i realized i mixed something up there :D i googled a bit and ended up with this new wiring: link Is it correct? thanks in advance! \$\endgroup\$ – Henry Jan 25 '16 at 2:29
  • \$\begingroup\$ @Henry, I was thinking of something like this wired.com/geekdad/wp-content/uploads/2012/09/relay_driver.jpg just google: "transistor drive relay circuit" you're not the first person to do this, so no need to reinvent the wheel (in this case) :) \$\endgroup\$ – Paul Jan 25 '16 at 2:41

This circuit can solve you problem. I hope it works for 3.3 V supply and 5V relay as well. To explain the reason it works, quote from the linked page:

"This circuit allows a 12v relay to operate on a 6v or 9v supply. Most 12v relays need about 12v to "pull-in" but will "hold" on about 6v. The 220u charges via the 2k2 and bottom diode. When an input above 1.5v is applied to the input of the circuit, both transistors are turned ON and the 5v across the electrolytic causes the negative end of the electro to go below the 0v rail by about 4.5v and this puts about 10v across the relay. "

enter image description here

| improve this answer | |
  • \$\begingroup\$ Where does the 5V come from? \$\endgroup\$ – CharlieHanson Jan 23 '16 at 18:56
  • \$\begingroup\$ I missed the point that no other supply was available. Updated the circuit. Thanks for bringing it to my notice. \$\endgroup\$ – Abu Bakar Jan 23 '16 at 19:17

Find a relay that has coil for 3.3volts, or . . .

You are going to need to obtain (or create) a 5 volt supply.

If you search for "step up breakout" you will find products that can step up 3.3v to 5 volts. A device like this will cost a few dollars.

Or, If you are driving AC circuits, you could use a TRIAC driver circuit directly from your 3.3 volts.

An SSR (solid state relay) could also be considered.

EDIT : based upon comments, I just realized you will need a transistor (MOSFET) to drive the coil of the relay.

| improve this answer | |
  • \$\begingroup\$ Your edit invalidates the whole rest of the answer. Once you have the transistor (actually, better bipolar than FET) the MCU voltage mattes little at least in the 3.3v and up range. \$\endgroup\$ – Chris Stratton Oct 12 '16 at 22:59

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