Purpose of attached circuit: driving a solenoid (cabinet lock) from microcontroller through relay with a 5 volt coil.


  1. ATMEGA8
  2. Relay 5 volt with NO Contact
  3. Solenoid 12 volt
  4. power supply 12 volt
  5. Regulator 7805 to generate 5 volts

enter image description here enter image description here


  1. On state of controller pin: relay is energized and the contacts close and 12 volt feeds the solenoid and it is working well.
  2. Off state of controller pin: relay is still energized and for sure the solenoid is still active. ( 3.9 volt is still there on the output pin of the controller.)
  3. Off state of controller pin (in case the solenoid is disconnected from the circuit): relay is ee-energized, and it is working well as expected.


  1. Logic in controller drives the output only.

  2. The 7805 regulator is not mentioned in the above circuit.

    Can you help me to find the issue which leads the output of the controller to be forced to high when the solenoid is connected and the controller output should be low?

  • \$\begingroup\$ Is it a BJT where "Input from MC" is written ?? \$\endgroup\$
    – Sadat Rafi
    Mar 31, 2020 at 17:18
  • \$\begingroup\$ Plus the diode is in the wrong place. It should be across the coil. \$\endgroup\$
    – Sadat Rafi
    Mar 31, 2020 at 17:18
  • \$\begingroup\$ @SadatRafi doide between termianl of coil (5)and ground(2) i mean output from mc and input to interface circuit \$\endgroup\$ Mar 31, 2020 at 17:25
  • \$\begingroup\$ This circuit totally wrong. Wait I'll give a diagram soon. \$\endgroup\$
    – Sadat Rafi
    Mar 31, 2020 at 17:26
  • \$\begingroup\$ @Sadat: The OP's diode is across the coil and it's even the right way up. Have another look. OP is switching relay positive, not GND, and directly from the MCU (which may have been overloaded and the output is now stuck on high). \$\endgroup\$
    – Transistor
    Mar 31, 2020 at 17:47

2 Answers 2


Your circuit should be like this.

enter image description here

enter image description here

These two are screenshots of the proteus simulation results. You have placed diode in the wrong position, plus haven't used a BJT / MOSFET. ATMEGA 8 can have a maximum 5.5 volts. I hope this will work.

  • \$\begingroup\$ thanks for your help ,the relay which connected to solenoid is 5 volt why i need to add transistor ? \$\endgroup\$ Mar 31, 2020 at 17:45
  • \$\begingroup\$ ATMEGA 8 can provide a maximum 40mA current per pin and 200mA per register. That's why you will need a transistor to increase the current. I prefer MOSFET over BJT. \$\endgroup\$
    – Sadat Rafi
    Mar 31, 2020 at 17:57
  • 1
    \$\begingroup\$ His diode is in the same position @SadatRafi \$\endgroup\$
    – skvery
    Apr 1, 2020 at 10:17
  • \$\begingroup\$ He hasn’t used BJT. \$\endgroup\$
    – Sadat Rafi
    Apr 1, 2020 at 20:29

You need a transistor or mosfet to handle the relay current.

For me the simplest would be the circuit below:


simulate this circuit – Schematic created using CircuitLab

  • \$\begingroup\$ if current of Solenoid is 600ma why i can't use MOSFET direct to control the solenoid without relay in between. \$\endgroup\$ Apr 1, 2020 at 12:28
  • \$\begingroup\$ Yes you can. Just make sure that 600 mA is the peak and not the average current or link a datasheet in your question. You can also then use nmos like VN10KM \$\endgroup\$
    – skvery
    Apr 1, 2020 at 13:45

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.