- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
With an engineer's wet finger, I would say they need to actuate in about 0.1 seconds to reasonably impress. If it took a second to move up or down, it wouldn't look right.
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
That's not correct. Read what I had to say about it (immediately above your post).
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
I think you are mistaken there. Take another look at the Fritzing diagram. The button is shown with a black wire to the blue rail of the breadboard and that rail is shown connected to GND on the Pi header. The other side of the switch has a blue wire going to the gpio input and a pullup resistor.Z80 Refugee wrote: ↑Thu Jul 12, 2018 5:15 pmThat's not correct. Read what I had to say about it (immediately above your post).
Re: Controlling homemade solenoids using Rpi Z W
That's more what I expected. It would feel almost instant at that. It's a rather critical parameter for choosing the actuator.Z80 Refugee wrote: ↑Thu Jul 12, 2018 5:13 pmWith an engineer's wet finger, I would say they need to actuate in about 0.1 seconds to reasonably impress. If it took a second to move up or down, it wouldn't look right.
- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
I don't. Look at how the bottom row of solenoids are connected, then observe that the top row are indeed connected to 0V but the wire is shown as if stripped at the end (as is the red wire, indicating it is intentional that the positive side goes to the GPIO).PiGraham wrote: ↑Thu Jul 12, 2018 6:09 pmI think you are mistaken there. Take another look at the Fritzing diagram. The button is shown with a black wire to the blue rail of the breadboard and that rail is shown connected to GND on the Pi header. The other side of the switch has a blue wire going to the gpio input and a pullup resistor.
However, I have just noticed that five of the six diodes are shown the wrong way around (it just happens that the one I looked at is correct), so five of the six solenoids wouldn't do anything as shown anyway!
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
0.5 seconds to go up and 0.5 seconds to go down would be ideal. The biggest goal we're trying to achieve for this is to make it as compact as possible.
- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
If all you are trying to demonstrate is some balls moving up and down, maybe. For a reasonable reproduction of a Braille output device, you need to realise that people who can read Braille will find two characters per second excruciatingly slow.
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
I did miss those green lines. Is that a quirk of Fritzing a deliberate attempt to convey information, I wonder?Z80 Refugee wrote: ↑Thu Jul 12, 2018 10:02 pmI don't. Look at how the bottom row of solenoids are connected, then observe that the top row are indeed connected to 0V but the wire is shown as if stripped at the end (as is the red wire, indicating it is intentional that the positive side goes to the GPIO).PiGraham wrote: ↑Thu Jul 12, 2018 6:09 pmI think you are mistaken there. Take another look at the Fritzing diagram. The button is shown with a black wire to the blue rail of the breadboard and that rail is shown connected to GND on the Pi header. The other side of the switch has a blue wire going to the gpio input and a pullup resistor.
E8045877-8E9D-4952-8AD4-FAE2B419E35D.jpeg
However, I have just noticed that five of the six diodes are shown the wrong way around (it just happens that the one I looked at is correct), so five of the six solenoids wouldn't do anything as shown anyway!
Coils commoned to 5V would fit with the polarity of all but one of the six diodes. The diodes are wrongly connected in any case. They should go across the coil, not in series with it.
The button is clearer and definitely seems to switch to GND with a pull-up to 5V. Still bad practice.

- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
I already said that.
I already said that.
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
Relax. We agree.
- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
Yeah, well, I just get the impression you are posting without reading the other posts.
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
Right now they're half an inch long and only have 300 turns so they're pretty thin as well.
The radius is pretty small too since we're only using lollipops because we're still trying to find a metal core that is as small as that.
Re: Controlling homemade solenoids using Rpi Z W
We just noticed awhile ago that the pi isn't detecting our camera so it's either we broke the camera or broke the camera board because of what we did yesterday
Re: Controlling homemade solenoids using Rpi Z W
How about using miniature neodymium magnets as the cores?
Re: Controlling homemade solenoids using Rpi Z W
Now you've confused even me!
according to earlier posts, the coil (300 turns round a non-ferrous (?) lollipop stick) pulls a pin (probably iron) down
So using a magnet for the core would just hold the pin permanently down.
I'd use a steel screw for the core, with a (possibly neodymium) magnet to be pulled.
Re: Controlling homemade solenoids using Rpi Z W
The coil creates a magnetic field that engages with the magnet's field. Normally, in a solenoid, motor, transformer and the like soft iron or maybe ferrite cores are used to concentrate the field and minimise air gaps. But there are various electromagnetic devices where the coil acts directly on a permanent magnetic field. For example, hard disk drive heads are moved by an air-cored coil between two very powerful magnets. Moving coil meter do similar. Place a coil around a magnet and energise it as the magnet will move, (or the coil will move). There is a force between them.Burngate wrote: ↑Fri Jul 13, 2018 5:45 pmNow you've confused even me!
according to earlier posts, the coil (300 turns round a non-ferrous (?) lollipop stick) pulls a pin (probably iron) down
So using a magnet for the core would just hold the pin permanently down.
I'd use a steel screw for the core, with a (possibly neodymium) magnet to be pulled.
Normally solenoids just have a soft iron pin and a soft iron cage or core and no permanent magnet.
It just occurs to me that reacting against a magnet should work and magnets of about the required size are easily found.
The magnet won't hold the pin because the magnet is the pin and there is nothing else magnetic present.
Re: Controlling homemade solenoids using Rpi Z W
The magnet and screw will stick together.Burngate wrote: ↑Fri Jul 13, 2018 5:45 pmNow you've confused even me!
according to earlier posts, the coil (300 turns round a non-ferrous (?) lollipop stick) pulls a pin (probably iron) down
So using a magnet for the core would just hold the pin permanently down.
I'd use a steel screw for the core, with a (possibly neodymium) magnet to be pulled.
A bit of iron rod from B&Q is probably better than a steel screw. If you use a core the coil turns that into a maget and makes it attract the frame. When the current stops you want the manetic fields to dissipate rapidly.
Re: Controlling homemade solenoids using Rpi Z W
It's very unlikely that we can find a neodymium magnet to use as a core here so we'll probably stick with the lollipop core and just compensate by using a bigger voltage battery to power the solenoids.
Just a quick question about the transistors since we've decided to use them.
Given that the PI can only output 0.10 mA at 3.3V and the solenoid needs 400mA to function and we'll be using a 5V battery. Would a NPN 2n222 transistor suffice or is there a better alternative? Should we also increase the battery voltage?
Just a quick question about the transistors since we've decided to use them.
Given that the PI can only output 0.10 mA at 3.3V and the solenoid needs 400mA to function and we'll be using a 5V battery. Would a NPN 2n222 transistor suffice or is there a better alternative? Should we also increase the battery voltage?
Re: Controlling homemade solenoids using Rpi Z W
Where are you that you can't get magnets shipped to your door?dibolero wrote: ↑Sat Jul 14, 2018 4:01 amIt's very unlikely that we can find a neodymium magnet to use as a core here so we'll probably stick with the lollipop core and just compensate by using a bigger voltage battery to power the solenoids.
Just a quick question about the transistors since we've decided to use them.
Given that the PI can only output 0.10 mA at 3.3V and the solenoid needs 400mA to function and we'll be using a 5V battery. Would a NPN 2n222 transistor suffice or is there a better alternative? Should we also increase the battery voltage?
I recommend you use a Darlington driver chip like ULN2003. It has high gain (Hfe or ratio of base current to collector current.)
It has flayback diodes to protect against back emf as the coils turn off. It works over a wide voltage range.
It is available for very low cost on a PCB with connectors and often indicator LEDs. All for about £1 each.
It has seven channels sone one device does all your switching.
This standard device has proven ubiquity and versatility across a wide range of applications. This is due to integration of 7 Darlington transistors of the device that are capable of sinking up to 500 mA and wide GPIO range capability.
The ULN2003A device comprises seven high-voltage, high-current NPN Darlington transistor pairs. All units feature a common emitter and open collector outputs. To maximize their effectiveness, these units contain suppression diodes for inductive loads. The ULN2003A device has a series base resistor to each Darlington pair, thus allowing operation directly with TTL or CMOS operating at supply voltages of 5 V or 3.3 V. The ULN2003A device offers solutions to a great many interface needs, including solenoids, relays, lamps, small motors, and LEDs. Applications requiring sink currents beyond the capability of a single output may be accommodated by paralleling the outputs.
http://www.ti.com/lit/ds/symlink/uln2003a.pdf
If you want to make your own from discrete components you can do that.
2n222 gain is tyically 100+ at higher Ic currents. To allow for variations let's take a worst case Hfe of 35
400/35 = 11.4mA round up to 12mA
Allow extra to ensure the transistor is in saturation or it will overheat
For base base resistor 12mA / (3.3 - 0.7V) = 4.6 kOhms. Nearest standard values 4k7 or 4k2 should do.
You will need flyback diodes.
Check the spec sheets for the actual components you use as they do vary by manufacturer.
edited to fix nonsense Hfe calc]
Last edited by PiGraham on Sat Jul 14, 2018 12:23 pm, edited 3 times in total.
- Z80 Refugee
- Posts: 359
- Joined: Sun Feb 09, 2014 1:53 pm
Re: Controlling homemade solenoids using Rpi Z W
That's not relevant. To turn on a transistor you need less that 1V, and the RPi is capable of driving 16mA.
At last we have a figure for the solenoid current! Now we are getting somewhere.
With 16mA* to switch 400mA, you need a transistor with a current gain (Hfe) of 25.
I think you probably mean 2N2222 - it would be OK, but only just. My recommendations are in the article I have already linked you to.
Why? If the solenoid works to your satisfaction on 5V, increasing the voltage would increase the current as well for no benefit. If you want to improve the speed of action, then increase the voltage if you like - but take care not to exceed the maximum current for the transistor, or the current from the RPi x transistor gain.
* The current into the base of the transistor defines whether the transistor is fully turned on for any particular current through the load. You need at least the load current divided by the current gain (and the current gain varies according to load and voltage, so you have to look at the Hfe charts). The base current is limited by what the GPIO output can provide and any resistor network between the output and the transistor base.
To use a 2N2222 transistor to drive a 400mA load, use a 220 ohm resistor between the GPIO and the transistor base (with a 10 kohm resistor from base to ground - not absolutely necessary but I would put one in). You need a protection diode wired across your solenoid (cathode to +ve), as well as the diode across the transistor.
However, I would prefer to use a transistor that was easily capable of driving the solenoid rather than only just able to. See my article. The 8-way Darlington driver IC (as suggested in a previous post) would be a good choice (also described in my article).
Beginners Guide to Wiring Things to the GPIO
Military and Automotive Electronics Design Engineer (retired)
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!
Re: Controlling homemade solenoids using Rpi Z W
We live in the Philippines and yeah it's kinda shocking how stuff is so hard to get here even the pi's prices are ridiculously marked up .
Luckily we were able to go to an electronics shop and the owner helped us out and gave us some tips. We bought 12V Relays as they were the smallest ones there that would fit our design(We could've gotten solenoids at 5v but they go for around 12$ each here) and use them for our up down mechanism instead of using our homemade solenoids. We also bought 3 ULN2003 so that we could use each to drive 2 relays as he suggested.
We are extremely grateful for all of your help. We would've still been banging our heads on a wall without the answers given here. Just for background, we're doing this for a national innovation competition and before everyone's help we all felt really hopeless but now it seems like we might have a shot!
We will still be figuring out how to put all of these components properly in the circuit and we'll make sure we consult engineers before we turn anything on so we won't fry our new pi. I'll make sure to let you guys know how things work! Again we are so thankful!

Luckily we were able to go to an electronics shop and the owner helped us out and gave us some tips. We bought 12V Relays as they were the smallest ones there that would fit our design(We could've gotten solenoids at 5v but they go for around 12$ each here) and use them for our up down mechanism instead of using our homemade solenoids. We also bought 3 ULN2003 so that we could use each to drive 2 relays as he suggested.
We are extremely grateful for all of your help. We would've still been banging our heads on a wall without the answers given here. Just for background, we're doing this for a national innovation competition and before everyone's help we all felt really hopeless but now it seems like we might have a shot!
We will still be figuring out how to put all of these components properly in the circuit and we'll make sure we consult engineers before we turn anything on so we won't fry our new pi. I'll make sure to let you guys know how things work! Again we are so thankful!




Re: Controlling homemade solenoids using Rpi Z W
Soo we're probably stuck again.
We got the ULN2003APG and followed this diagram https://imgur.com/a/cXkL5Wq on youtube except we didn't use the headers. Unfortunately the switch works on LEDS but not on our solenoid(We tested solenoids again because it was hard to find 12v batteries for the relays).
Our solenoid right now draws 180 mA at 3v but when we tested it on the circuit with the ULN it was only pulling 10mA. I'm not sure if this a problem with the type of component we bought or a problem with the circuit diagram we're following.
We got the ULN2003APG and followed this diagram https://imgur.com/a/cXkL5Wq on youtube except we didn't use the headers. Unfortunately the switch works on LEDS but not on our solenoid(We tested solenoids again because it was hard to find 12v batteries for the relays).
Our solenoid right now draws 180 mA at 3v but when we tested it on the circuit with the ULN it was only pulling 10mA. I'm not sure if this a problem with the type of component we bought or a problem with the circuit diagram we're following.
Re: Controlling homemade solenoids using Rpi Z W
Do you have any resistors in sries? The diagram shows LEDs with current limiting resistors, as needed for LEDs, but you don't want to add resistance to the solenoid circuit.
What voltage do you measure at the ULN pin when the switch is on? What voltage do you measure at the battery +ve terminal when the switch is on?
What voltage do you measure at the ULN pin when the switch is on? What voltage do you measure at the battery +ve terminal when the switch is on?
Re: Controlling homemade solenoids using Rpi Z W
According to [ur=https://toshiba.semicon-storage.com/ap- ... 03APG.html]the datasheet for that particular part numberdibolero wrote: ↑Mon Jul 16, 2018 1:14 pmSoo we're probably stuck again.
We got the ULN2003APG and followed this diagram https://imgur.com/a/cXkL5Wq on youtube except we didn't use the headers. Unfortunately the switch works on LEDS but not on our solenoid(We tested solenoids again because it was hard to find 12v batteries for the relays).
Our solenoid right now draws 180 mA at 3v but when we tested it on the circuit with the ULN it was only pulling 10mA. I'm not sure if this a problem with the type of component we bought or a problem with the circuit diagram we're following.
[/url]
Input voltage VIN (ON) ULN2003A 2.8V(output on) (IOUT = 400 mA)
So Pi gpio output high should be at least 2.8V and the device should be abale to pass at least 400mA
However, Collector- emitter saturation voltage is given as 1.3V max so you may only have 2V across the soil if driving from 3.3V. Try increasing the solenoid supply voltage.
Last edited by PiGraham on Mon Jul 16, 2018 7:35 pm, edited 1 time in total.