0
\$\begingroup\$

As the title says I am trying to control a solenoid with a raspberry pi. I am currently using an npn transistor (will post link with parts at the bottom) however I am having a hard time getting it to work. The collector is at 12V and the gate is controlled by the raspberry pi gpio pin (runs at 3.3V and 16mA (this is the max amount I believe)).

Attached is a picture of a circuit I used to verify my solenoid circuit. It is essentially the same except that it has LEDs and that it runs on 3V instead of the 12V for the solenoid. Unfortunately I do not have any pictures with the solenoid. It would look roughly the same except that the two positive legs on the solenoid replace the LEDs and the single ground wire is hooked up to the negative row on the breadboard.

This verification circuit works perfectly, but the solenoid circuit does not. I have read online that MOSFETs can also be used as a switch, would this be better? In the case that it is, I would like to try to get the NPN transistor to work as I would rather not use more money.

Any help is greatly appreciated.

Thanks.

Solenoid (15mm version): https://www.pneumadyne.com/way-normally-closed-latching-solenoid-valves-p-1448.html#1-YToxOntzOjQ6ImdyaWQiO2k6MDt9

Transistor: https://www.mouser.com/ProductDetail/Diodes-Incorporated/ZTX688B?qs=sGAEpiMZZMshyDBzk1%2fWizF0eVyYE44ZxbGt8e1SnMg%3d

Images: https://imgur.com/a/gOnuPFT

I have included a diagram of what my solenoid circuit looks like. For reference on the transistor labeling, as I am not sure what is common. B - base (gate) C - collector E - emmitter

\$\endgroup\$
  • \$\begingroup\$ You say an NPN transistor, but then you talk about a gate, which NPN transistors don't have. Is this a typo? Additionally, please add a schematic. \$\endgroup\$ – Hearth Jan 20 at 21:09
  • \$\begingroup\$ Hi, I'm not very confident on the actual terminology so by gate I meant the base (I hope that this is correct). So like the middle pin if that makes sense. Also by schematic did you mean something like online. I think I have a rough circuit in the images I have linked. Would you like something more specific?Thanks. \$\endgroup\$ – Pfrances Jan 20 at 22:18
  • \$\begingroup\$ Welcome to EE.SE. We need to see a proper schematic for your circuit; photos of your breadboard won't do the trick. Also, please explain the difference between your "verification circuit" and the "final circuit". We also need to see a datasheet for the 12V power supply. \$\endgroup\$ – Elliot Alderson Jan 21 at 0:16
2
\$\begingroup\$

Your circuit does not work for the solenoid or supply voltage that you have.

You have a 3 wire (2 coils) self latching solenoid that specifies the common as the negative pin. The data for the solenoid shows that you have a 4W drive requirement. This means that at 12VDC you need about 340mA to activate each of the solenoid coils (latch and release).

enter image description here

The transistor you selected is completely unsuitable for your task. It has enough Collector current capability but has a V(CBO and V(CEO) of only 12V. You would never use a device at its absolute maximum rating.

enter image description here

You are going to have to buy suitable devices to drive your solenoid.

A potential circuit would be as follows and you would need two GPIO pins to drive the latching solenoid:

schematic

simulate this circuit – Schematic created using CircuitLab

It would be up to you (in software) to ensure the A or B coil is activated for the appropriate length of time to latch and unlatch.

Note: You must have the pulldown resistors on M3 and M4 to ensure that neither coil is activated as you turn on and boot the R'Pi. The GPIO pins are all set as inputs on power-up, so the 10K Ohm resistors keep M3 and M4 off.

Update: The documentation for the solenoid switch you use specifies the polarity of activation (I assume this is required since the latching is by a magnet, so pole polarity sensitive):

enter image description here

\$\endgroup\$
0
\$\begingroup\$

When using transistors in switching applications, it is always a good idea that they are referenced to a voltage that will not move on you. If you notice on @peter bennett ‘s suggested circuit, the NPN is driven by the GPIO of the RasberryPi referenced to GND (emitter is at GND, and the base is driven by the GPIO which supplies the base current via the base resistor as (Vgpio - 0.7)/Rbase), and the base of the PNP is driven referenced to the “fixed” battery voltage at its emitter. Notice as @Jack Creasy pointed out, that you need a current limiting resistor in series with the collector of the NPN used to drive the PNP, or you will probably fry them both. Otherwise, that should be a perfectly good circuit for driving a regular solenoid.

I need to review how the latching solenoids work—-if i remember, once they no lnger need to be driven anymore . However, to disengage them, i think you need to drive the current through the solenoid in the opposite direction. If so, @Peter Bennet’s circuit will not achieve that. You could accomplish this by using an H-bridge.

\$\endgroup\$
  • \$\begingroup\$ The OP is using a two-coil latching solenoid - energizing one solenoid momentarily will open the valve. energizing the other solenoid momentarily will close the valve. \$\endgroup\$ – Peter Bennett Jan 21 at 2:11
0
\$\begingroup\$

As mentioned by Peter Bennett, you should change the transistor so that it doesn't work at its limit, and wire it as shown here below. I would also add a diode to protect the transistor from the spikes caused by switching the inductive load. BTW, the transistor value is just the default part that comes up when I drew the schematic. Please look up the datasheet for the absolute maximum values.

I suggest that if you're are in doubt of how a circuit works (or doesn't) try simulating it in LTSpice; It is free, and fairly easy to use, and it will save you a lot of headaches.

schematic

simulate this circuit – Schematic created using CircuitLab


As it has been pointed out that the solenoid is polarised, and that OP is a newbie, I shall present the easiest and probably cheapest solution possible. it also includes a protection from activating both coils at the same time.

schematic

simulate this circuit

The relay board can be found for just over a dollar on Aliexpress generic relay module

\$\endgroup\$
  • \$\begingroup\$ Thanks Elmesito, that makes sense as well. I have found circuits like the one above however I have a solenoid with three wires as it is magnetically latching. How would this affect the diagram? \$\endgroup\$ – Pfrances Jan 20 at 22:06
  • \$\begingroup\$ The common of the 3 wire solenoid is the negative rail. So this simply does not work. \$\endgroup\$ – Jack Creasey Jan 21 at 1:12
  • \$\begingroup\$ nowhere in the documentation is mentioned that the common must be negative. \$\endgroup\$ – Elmesito Jan 21 at 9:20
  • \$\begingroup\$ @Elmesito You need to read the documentation: pneumadyne.com/documents/Latching_Valves.pdf It is indeed polarity sensitive. \$\endgroup\$ – Jack Creasey Jan 21 at 16:41
  • \$\begingroup\$ @JackCreasey you are correct, I had not seen that document. I would however suggest to OP to try powering the common to +12V (after verifying there are no internal protection diodes)and driving each coil to ground in turn, and see if it just means that the open and close coils become swapped. It might be a long shot, but worth a try. \$\endgroup\$ – Elmesito Jan 21 at 16:50
-1
\$\begingroup\$

First, the Absolute Maximum collector-to-emitter voltage for that transistor is 12 volts. It may be barely adequate for your circuit - I'd prefer something rated at 20 volts or more - you should never run anything at its Abolute Maximum rating.

Second, you are apparently using the transistor as an emitter follower - you have the load between emitter and ground. Unfortunately, the emitter voltage will always be about 0.7 volts below the base voltage - since the Pi operates on 3 volts, your circuit can't apply more than 2.3 volts to the 12 volt solenoid.

You should ground the emitters, and place the solenoid between the collector and the positive supply. You also need resistors (1K or so) between the Pi outputs and the transistor bases.

edit: It appears that the common wire on that solenoid must be negative, and you need to apply a positive pulse to the brown or blue wire to switch the solenoid. Something like this would work:

schematic

simulate this circuit – Schematic created using CircuitLab

The transistor and diode types are defaults in the CircuitMaker program - not necessarily appropriate for your use.

\$\endgroup\$
  • \$\begingroup\$ Hi Peter, thanks for the comment. The voltage limit makes sense to me I hadn't realized this was such an issue. I will definitely try switching the transistors around. I am confused how you found that the circuit can't apply any more than 2.3 V to the solenoid though (this is my first time using transistors and I haven't had proper instruction to be clear). Will that issue be fixed by switching the transistors? Also how will the resistor help here? I have found sites that recommend this but no explanation as to why. Thanks. \$\endgroup\$ – Pfrances Jan 20 at 22:04
  • \$\begingroup\$ Looking over my diagram again, I do not see how to make it so that I can control the solenoid and have the transistors after the solenoid in the circuit. Did you happen to have anything in mind?Thanks. \$\endgroup\$ – Pfrances Jan 20 at 22:12
  • \$\begingroup\$ In NPN transitors, the base will always be about 0.7 volts (1 diode drop) above the emitter when the transistor is conducting - that is just the way they work. (For a PNP transistor, the base will be about 0.7 volts below the emitter.) Many beginners run into this problem as they try to use an emitter-follower configuration to drive a load. The resistor between the Pi output pin and the base limits the base current and the current drawn from the Pi output pin. See the drawing in @Elmesito's answer for the recommended drive circuit. \$\endgroup\$ – Peter Bennett Jan 20 at 22:15
  • \$\begingroup\$ This circuit is wrong. There needs to be a resistor in the collector of Q1 otherwise there is no current limit (other than that imposed by Hfe) on Q1. You will destroy Q1 or Q2 by using it. \$\endgroup\$ – Jack Creasey Jan 21 at 0:50
  • \$\begingroup\$ @JackCreasey: well, I did say "something like". Added resistor R3 - value is a wild guess... \$\endgroup\$ – Peter Bennett Jan 21 at 2:07

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.