# Why does my microcontroller's 5V out fail to activate my 5V relay?

I am using a small microcontroller with 5V output lines to try to turn a relay on and off.

I bought the relay module from Amazon and unfortunately I don't know much about what is on the relay module's board, but I do know the relay is a SRD-05VDC-SL-C

I tried to follow an Arduino tutorial and I've almost got the setup working...

I say almost because the relay IN line doesn't seem to get enough power, and the Green LED on the module that indicates the IN line's voltage is very dim.

I tested the module by putting the IN line directly on the 5V input, and it seems to work fine.

I made a video that explains and demonstrates the problem

You can also connect an external power source to the microcontroller, and I tried that, too, with similar results

Can anyone help me understand why the relay doesn't work when hooked up to the 5V output line of the microcontroller?

EDIT

Attempt at drawing out configuration in first video, where the A* microcontroller is getting 5V of power from its usb plug:

simulate this circuit – Schematic created using CircuitLab

Attempt at drawing schematic of video 2

simulate this circuit

Attempted schematic for a new 3rd video, trying to power the relay separately.

simulate this circuit

Actually got it working with 2 pins in this 4th video

Does this mean that the problem was current all along?

• It is because the relay coil needs more current than your microcontroller output can provide. – KyranF Mar 24 '15 at 18:00
• What @KyranF said. – efox29 Mar 24 '15 at 18:01
• ^Agreed. Use a transistor to switch a higher current power supply into your relay – DerStrom8 Mar 24 '15 at 18:03
• @tmsimont: there is more to the story than voltage, you also need enough current. – whatsisname Mar 24 '15 at 18:04
• @tmsimont: current is always measured in amps, it is never measured in volts. – whatsisname Mar 24 '15 at 18:05

Are you setting the pin on your microcontroller as an output? The behavior of the LED makes me think you did not. You might get a volt or so, enough to light the LED a little but not enough activate the relay. I had this problem recently and nearly tore my hair out, so I thought I should suggest this in case it is indeed your problem.

• It's not a voltage level issue – KyranF Mar 24 '15 at 18:11
• I wouldn't be so quick to rule it out. If you watch the video you can see the LED is very dim when the relay is switched by the micro controller pin, and is bright when the pin is connected to the 5v supply. I know it is likely to be a current issue, but it could be a voltage level issue as I described. – Keith Mar 24 '15 at 18:18
• When an output pin cannot source enough current, the load and the output impedance effectively form a "voltage divider" which is how shorting a load (or trying to drive the coil for example) brings down the voltage making things like LEDs appear dim or turn off.. – KyranF Mar 24 '15 at 18:19
• this was it all along! I wasn't sure what you meant until I start digging a little further today. I was missing this code in the setup: pinMode(1, OUTPUT); – tmsimont Mar 26 '15 at 18:12
• Glad I could help. Also relieved that I'm not the only one to make this mistake. – Keith Mar 27 '15 at 1:36

The relay module in the photo has a driver transistor on board (as well as a couple indicator LEDs and a catch diode)-- the input impedance looks to be in the 2K ohm range, which is pretty low, but your micro should be able to supply it.

You need to supply a solid 5V supply to the relay unit for it to be able to work. The input is just a control input. If you don't have a separate 5V supply, the on-board transistor will not be able to amplify the weak output of the micro- the relay takes far more current than the micro can supply. Make sure there is a solid common ground connection. This is very important.

Check that the supply voltage is 5V (input on or off) and that the input voltage is at least 3V (on), and it should work.

• +1 for noticing that this type of relay module has a built-in driver transistor, and answering based on that fact. – Wouter van Ooijen Mar 24 '15 at 18:34
• I just tried this and it still has the same result. I added a 3rd video and an attempt to draw this out in a schematic. Is this third video I have what you describe I should do? – tmsimont Mar 24 '15 at 21:13

Your relay needs about 70 mA to operate, and your microcontroller can only do about 50mA on each output pin, which isn't enough.

Can provide you some guidance on how to interface your microcontroller with a transistor to control the relay.

• -1 This type of relay module has a built-in driver transistor. – Wouter van Ooijen Mar 24 '15 at 18:34

You need to supply the coil 70-90mA depending if it's the standard or high sensitivity version of that relay.

Your microcontroller would be lucky if it's output port can supply more than 40mA. In fact, that's most likely the max ratings and you are effectively causing a short circuit/pulling max current from the pin trying to do this.

Not only that, but you are driving an inductive load (the coil) directly with a sensitive microcontroller pin. You should use an NPN BJT or N channel MOSFET to switch a high current supply (like the VCC rail to your micro) into the coil, using a "low side power switch" configuration for the easier circuits.

The coil should have a protection diode across it as well, to avoid inductive voltage spikes going into the microcontroller pin, and/or to protect the FET/BJT used to switch the coil.

• -1 This type of relay module has a built-in driver transistor. – Wouter van Ooijen Mar 24 '15 at 18:34
• @WoutervanOoijen my bad, didn't check the actual module PCB he bought. I can see the little SOT23 NPN transistor there now I look. The issue then is available source current for the 5V "input" to the relay module. – KyranF Mar 24 '15 at 18:41

The coil inside that relay needs about 100mAh running through it to trigger. The micro controller total can only supply 100mAh according to this document.

Since some of the current will be used by the micro controller and status LED's, the relay doesn't get enough current flowing through it.

• each pin of the microcontroller cannot do 100mA, that is more like a "package total". – KyranF Mar 24 '15 at 18:10
• @KyranF my wording is poor, I said "micro controller total" – Colin G Mar 24 '15 at 18:15
• The link between the concept of total current (from all pins + internal uses) being 100mA to the fact the output drivers on the individual logic pins cannot source that much was not obvious that's all.. Perhaps the OP could rig up multiple output pins in parallel to source enough current, but overall it's a bad idea. – KyranF Mar 24 '15 at 18:18
• -1 This type of relay module has a built-in driver transistor. – Wouter van Ooijen Mar 24 '15 at 18:34
• This is wrong. mAh is an amount of charge, not current. – Greg d'Eon Mar 25 '15 at 19:14