3
\$\begingroup\$

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:

schematic

simulate this circuit – Schematic created using CircuitLab


Attempt at drawing schematic of video 2

schematic

simulate this circuit


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

schematic

simulate this circuit


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

Does this mean that the problem was current all along?

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

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.

\$\endgroup\$
  • \$\begingroup\$ It's not a voltage level issue \$\endgroup\$ – KyranF Mar 24 '15 at 18:11
  • \$\begingroup\$ 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. \$\endgroup\$ – Keith Mar 24 '15 at 18:18
  • 3
    \$\begingroup\$ 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.. \$\endgroup\$ – KyranF Mar 24 '15 at 18:19
  • \$\begingroup\$ 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); \$\endgroup\$ – tmsimont Mar 26 '15 at 18:12
  • \$\begingroup\$ Glad I could help. Also relieved that I'm not the only one to make this mistake. \$\endgroup\$ – Keith Mar 27 '15 at 1:36
4
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ +1 for noticing that this type of relay module has a built-in driver transistor, and answering based on that fact. \$\endgroup\$ – Wouter van Ooijen Mar 24 '15 at 18:34
  • \$\begingroup\$ 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? \$\endgroup\$ – tmsimont Mar 24 '15 at 21:13
-1
\$\begingroup\$

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

These answers:

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

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

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.

\$\endgroup\$
  • \$\begingroup\$ -1 This type of relay module has a built-in driver transistor. \$\endgroup\$ – Wouter van Ooijen Mar 24 '15 at 18:34
  • \$\begingroup\$ @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. \$\endgroup\$ – KyranF Mar 24 '15 at 18:41
-2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ each pin of the microcontroller cannot do 100mA, that is more like a "package total". \$\endgroup\$ – KyranF Mar 24 '15 at 18:10
  • \$\begingroup\$ @KyranF my wording is poor, I said "micro controller total" \$\endgroup\$ – Colin G Mar 24 '15 at 18:15
  • \$\begingroup\$ 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. \$\endgroup\$ – KyranF Mar 24 '15 at 18:18
  • 1
    \$\begingroup\$ -1 This type of relay module has a built-in driver transistor. \$\endgroup\$ – Wouter van Ooijen Mar 24 '15 at 18:34
  • 1
    \$\begingroup\$ This is wrong. mAh is an amount of charge, not current. \$\endgroup\$ – Greg d'Eon Mar 25 '15 at 19:14

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.