I have what I thought was a simple relay circuit but the relay is always on.

This is the part of the project that is not working

Q5 never switches off.

To simplify it further I removed the relay and fly back diode to rule them out as part of the problem it now looks more like this

enter image description here

When I measure the voltage difference between R14 and Q5 while pulling LCLOSE high and low the voltage difference only drops ~ 1.5v so at its lowest its still enough to keep the coil on.

BTW S12 is nominal voltage and was more like 14v.

Datasheet for S8050

Datasheet for 817C

Thanks in advance for any help.

  • \$\begingroup\$ What is the voltage at the base of Q5? \$\endgroup\$
    – jwh20
    Sep 10, 2021 at 11:05
  • \$\begingroup\$ Another strange observation is the voltage at the base jumps between 0.8v and -0.5 as LCLOSE is changed between 0v and 3.3v by the MCU.... \$\endgroup\$
    – AndrewT
    Sep 10, 2021 at 11:09
  • 2
    \$\begingroup\$ Normally you’d see a pulldown resistor on the base of Q5 to ensure it is turned off. Note gnd should point down by convention. Q5 should be rotated 90degrees clockwise. \$\endgroup\$
    – Kartman
    Sep 10, 2021 at 12:01
  • \$\begingroup\$ Your "relay always on problem" is a common one. \$\endgroup\$
    – tlfong01
    Sep 10, 2021 at 12:01
  • 1
    \$\begingroup\$ Even if you solve a possible failure or misconcept with the optocoupler, a pulldown resistor at the base of Q5 would be a good design practice, and probably it would solve your problems. \$\endgroup\$
    – mguima
    Sep 10, 2021 at 13:17

1 Answer 1


Adding a pulldown resistor to the base should solve your problem. Something like 10k would do. You don’t want the value too low as it forms a voltage divider with R8.

Also consider if you really need the opto coupler. Many assume that these have magic properties that will ‘protect’ the microcontroller. If the gnd/0V is shared between your 12V supply and microcontroller, then the opto is effectively superfluous.

  • \$\begingroup\$ Good tip on the optocoupler the MCU is indeed sharing the same GND. So I would be low side switching ~15v with 3.3 for the coil, would save me 12 components. More to think about cheers. \$\endgroup\$
    – AndrewT
    Sep 11, 2021 at 2:18
  • 1
    \$\begingroup\$ for four circuits to switch 12V relays. I'd use a uln2003. Has all you need in one cheap chip. \$\endgroup\$
    – Kartman
    Sep 11, 2021 at 4:03
  • \$\begingroup\$ I did make the switch to using the uln2003 IC mentioned by @kartman, replaced about 15-20 components with it and they are very cheap :) \$\endgroup\$
    – AndrewT
    Oct 25, 2021 at 22:00
  • \$\begingroup\$ @AndrewT. Good to hear. With the uln2003 there’s some things to be aware of that catch a lot of people out. First is the on voltage or voltage drop - being a darlington configuration means the transistor is never fully turned on so this can give a drop of up to 2V. Usually not an issue on a 12V circuit but with switching 5V relays, it can become marginal. The second is power dissipation. Whilst each output is good for 200mA, 7 outputs at 200mA will get the chip toasty. Be sure to estimate the worst case load and temperature rise. In all cases, read the datasheet! \$\endgroup\$
    – Kartman
    Oct 25, 2021 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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