I've been studying the PICAXE microcontroller as a driver for a set of three 12VDC solenoid valves (though I may choose the 24V models). For reference, the controller will use a temperature sensor to determine when to actuate the solenoids, in addition to elapsed time (via the firmware).

Conceptually, the use of a relay to control each solenoid makes sense to me since they operate at a higher voltage than the microcontroller. However it has been about 20 years since I last studied electronics in high school, and I get a bit confused when I see slightly more complicated solutions to this problem.

Here is a schematic of how I thought I should build the circuit, simplified to one output pin and one solenoid for brevity.

enter image description here

I then found the "Standard Circuit" in the PICAXE Interfacing Circuits manual, which is represented as follows.

enter image description here

Why is a transistor is required to actuate the relay? Perhaps the output current of the microcontroller pin (~20mA) is insufficient to power the coil in the relay?

Finally, I became concerned with the space that three relays would occupy on my circuit board and though I might be able to use an AND gate chip as follows. The benefit being that such chips usually contain four gates, and thus replacing three relays with one smaller chip.

enter image description here

In this example, one gate input is fixed at 12V. Is this gate solution feasible? That is, if the two "high" inputs are different, but recognized as a high by the chip, will the output voltage generally be the max of the two inputs? I found a data sheet for the BU4081B chip, but I am having difficulty finding the answer to this question in it.

  • \$\begingroup\$ Similar question: electronics.stackexchange.com/questions/35478/… \$\endgroup\$ – Steve Guidi Jan 2 '17 at 18:25
  • 2
    \$\begingroup\$ Your middle schematic seems reasonable, if the coil of the relay is rated for 5V. You are correct about the transistor. Possibly, you do not need a relay, and thus could connect your solenoid directly instead of the relay. Without additional information it's difficult to say. In fact, the coil of your relay is also a solenoid. electronics.stackexchange.com/questions/154636/… \$\endgroup\$ – Nazar Jan 2 '17 at 19:47
  • 1
    \$\begingroup\$ The gate array chip to would work IF it could provide sufficient current. \$\endgroup\$ – Nazar Jan 2 '17 at 19:54
  • 1
    \$\begingroup\$ @Naz The final diagram wouldn't work as the Vih(min) is about 70% of the supply voltage - in other words anything less than 70% of the 12V supply will not necessarily be considered a logic 1. In fact given that 5V is less than 50%, the input signal is pretty much guaranteed never register as a logic 1. \$\endgroup\$ – Tom Carpenter Jan 2 '17 at 22:16
  • \$\begingroup\$ @TomCarpenter -- totally missed that in the data sheet. Thanks for pointing that out! \$\endgroup\$ – Steve Guidi Jan 3 '17 at 2:14

Why use a transistor to drive a relay?

Because the transistor can handle a lot more current than a digital output of a microcontroller. A relay might need 60 mA at 5 V, whereas a microcontroller output might only be able to deliver 20 mA. The transistor provides current gain. It can be controlled with only a few mA, and can then switch considerably more than that.

Driving a solenoid

Your ultimate goal is to drive a solenoid from a digital logic signal. First driving a relay, then having the relay drive the solenoid is unnecessary complication. With the right circuit, the solenoid can be driven using transistors as amplifying devices instead of relays. This is desirable because transistors are smaller, cheaper, more reliable, and the result will be more efficient.

Consider that the coil of a relay is a solenoid. You already know how to drive one. The only difference might be that the solenoid you really want to drive requires more current than the coil of a relay to switch the solenoid.

However, that's just a matter of choosing the right active part to drive the solenoid. For example, here is a circuit that can drive a 24 V solenoid from a 0-5 V digital logic signal:

This transistor can support several amps, and has a maximum on resistance of only 29 mΩ with 4.5 V gate drive. At 2 A, for example, it will dissipate no more than 116 mW. Unless your solenoids need more than 2 A or so, this will do fine.

  • \$\begingroup\$ This is the important part: the relay IS a solenoid! Even if you manage to find a low current relay remember that for a small fraction of a second when you first activate the relay before the coil generates sufficient magnetic field that coil is basically a wire so the instantaneous current draw when first energised may be much higher than the rated current. \$\endgroup\$ – slebetman Jan 3 '17 at 0:34
  • \$\begingroup\$ @sleb: No, you have it backwards. The coil is a inductor. When voltage is first applied, the current builds linearly. If it were a perfect inductor, the current would rise linearly indefinitely with the same voltage applied. Since it has resistance too, the current asymptotically approaches the voltage divided by the resistance. \$\endgroup\$ – Olin Lathrop Jan 3 '17 at 11:49

Given the correct transistor there is no reason why your second diagram could not drive the solenoid directly. The level shifting to the solenoid voltage is already there because the drive to the transistor is referenced to 0V- This means that the voltage level at the top end of the relay can be 12V or 24V you just substitute the solenoid for the relay coil.

The transistor needs to be able to handle the solenoid current and have enough gain to saturate with the base drive. We can help you with that if you give us the details of the solenoid.


There are several possible answers for this at the top of my head:

  1. To use MOSFETs (cheaper): make sure you understand them (Rds_ON and V_GS). The similar question you posted have good explanation.

  2. To use SSRs (easier): SSR stands for Solid State Relay. As the name implies, it is a relay that uses electronics and optocouplers to switch rather than mechanical parts. SSRs can be compact and come with DIP package and even SMD packages. Just be sure to choose one that accepts 5V for control and could handle the solenoid current. An example is this chip AQV212, datasheet: http://www.farnell.com/datasheets/911523.pdf


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.