Controlling a Solenoid with an Arduino

Hello. I tried to follow along using the supplies linked in the tutorial, but whenever i hook up my arduino to my computer, the solenoid value immediately flips into the pressed position and uploading the code does nothing. Im wondering if you have any ways to help troubleshoot? thank you!

Thanks Bryce. But I’ve decided to go down another path. I’ll control the solenoids the old fashioned way and the servos with the Arduino. But now I’ve hit another snag. Servos are supposed to have their own power source, not the Arduino. But is there a limit to that power source, ie max 6v, 9v, 12v, 15v, etc? And the servos are meant to share the GND or the Arduino with the LEDs that I’m using to indicate turnout position. There are several GNDs on an Arduino Uno. Can the LEDs use 1 GND and the servos use a different GND?
Thanks

Can someone help me with recognising the letters in arduino programming.
Example
Let us take a word john
Program should recognise first letter as J
Then go to next step and recognise as o
Similarly

1 Like

The Arduino documentation contains examples of string comparisons.

https://www.arduino.cc/en/Tutorial/StringComparisonOperators

1 Like

Hey I bought everything from the list on this site and run the code, but the solenoid is not deactivated. It is only activated. Looks like the transistor is not doing its job. Are you sure you used the NPN Transistor (2N3904)? what if I use the TIP120 Darlington Transistor?

Hi Francisco, I have exactly the same problem, followed everything on the diagram, the solenoid stays switched on all the time. Have you figured it out?

Looks like you are using the 2N3904 from the instructions, from the supplied pic. It is a small signal transistor and can supply up to 200mA.
The link says power transistor but takes you to the wrong item.
As someone has said, you should use something like a TIP120, it can supply up to 5A.
The data sheet link to the solenoid is not very clear. Spark Fun have a better link which states 1.1A to activate the solenoid.

Using a mulitmeter to measure the voltages and current should enable you to find out why it is not working.

Core Electronics should change the instructions to link this item and update the text to say the solenoid requires 1.1A to operate

Regards
Jim

1 Like

The correct power source for the solenoid depends on the solenoid you are using - it will have a voltage rating, such as 6v or 12v. If you are not sure of the voltage of your particular solenoid you could try connecting it directly to different voltages, starting low and increasing, until it operates reliably with the appropriate load. All the grounds should be the same - it doesn’t really matter where you connect them together, so long as they are all connected, so whether you use one or several ground pins on the Arduino board will depend on what is convenient for you physical layout.

1 Like

Thanks. I’ve gone down the path of using a Mega to control the servos (22 of them) and having separate power supplies for the solenoid, the servos and the Arduino.

1 Like

Hey,
I’m controlling a solenoid valve using the Pololu 24V step-up regulator which has built in reverse-voltage protection.
Does this mean I don’t need a diode between the regulator and the solenoid?
Or, does it mean the regulator protects other components from reverse-voltage it creates?

Hey Chris,

The reverse voltage protection on regulators is for incorrect voltage on the input side, not the output side. You’ll still need to include the flyback diode for the solenoid.

Regards,
Oliver
Support | Core Electronics

Thanks for clarifying mate.

Do you know what diode would I need?
Could I just plug that into the OUT terminals along with the wires on the regulator?

Chris

Hey Chris,

Essentially the diode needs to be included in order for the solenoid not to create a back current when it distributes its kinetic energy into the system which can damage sensitive components when not accounted for (this back current will be in the wrong direction according to Lenz Law) so you’ll need a diode that is able to handle the current that is being produced, while also not allowing a flow of current in the wrong direction through normal use. This simple Schottky diode should be suitable, with a rating of 1A at 40V.

If you have any further questions please let us know.

Bryce
Core Electronics | Support

Hi Bryce,

I bought the transistor, diode and solenoid from the links provided and followed the tutorial but when I turned the power on it seemed like there there wasnt enough power for the solenoid to work properly, because it still stuck in place for 1 second when I pushed it but when it’s released it doesnt pull back.
Is there anything I need to do to make it work? please help!!!

Frank

Looking closer, this project kind of worries me.
Expecting the UNO 5V to deliver 1.1A to hold a solenoid and also power everything else on the board is a ‘bridge too far’ in my opinion. I am not willing to find how much the onboard 5V regulator can deliver before it dies. I don’t want to kill a perfectly working UNO. My rule of thumb is no more than 300mA. If I need more than that I use an external supply.

The data sheet for the NCP1117LP states 1.0A, then states ‘Output Current in Excess of 1.0 A’, then it states ‘Current Limit of 1.1A’. What is the correct amount On Semiconductor ??

I think Core electronics should revisit this Tutorial, using an external supply.

Cheers
Jim

1 Like

Hi All
I really don’t see what the problem is here except maybe the 5V from the Arduino will not drive the solenoid.
I have sketched a circuit below which is basically what Core have in the pix in that tutorial.

As simple as it gets. You could use a Mosfet instead of the transistor but use about 1kΩ series gate resistor and 10kΩ realtor gate to ground.

The solenoid power could be anything but should not exceed Solenoid, Transistor/Mosfet ratings.
Cheers Bob

3 Likes

I did some testing, I found a few of these in my parts bin.
5V across Solenoid 750mA, solid activation.

UNO connected to PC, driving solenoid through TIP3055. 1 sec ON, 4 sec OFF loop.
Sometimes activate, sometimes not, easy to deactivate by moving or touching shaft slightly.

UNO connected to USB 5V supply, no activation, current around 400mA.
UNO Vin connected to 7V supply, no activation, current around 500mA.
Increase Vin to 9V, solenoid activates, current around 550mA. Not solid activation.

My UNO is a Duinotech, (much cheaper than original) probably the 5V regulator limits to around 500mA.

UNO to USB 5V, separate 5V supply to solenoid. 650mA. Solid activation every time.
TIP3055 drops about 0.8V, its a 15A 60V transistor and not the best for this scenario.
Did not have any TIP120’s.

The diode I used was a 1N4001, its just there so the back EMF of the coil has somewhere to go.
You don’t need a Schottky for this setup.

I stand by my original statement, this Tutorial should be revisited using a separate supply for the Solenoid. Also an opportunity to explain why you would do this.

Regards
Jim

2 Likes

Hi James

I did not disagree with this. On the contrary I wholeheartedly agree. The “tutorial” is only half done.

I did say however that maybe the 5V from the Arduino will not drive the solenoid which you seemed to have proved correct.

The circuit I sketched is as per the frizzing diagram in the tutorial with the exception that I indicate an external solenoid supply which I would personally always use in this situation.

The only criticism here would be the 220Ω resistor. Seems a bit low. Would have to drop 4.4V at the required base current of the transistor. The TIP120 is a darlington transistor and would have a high gain and I could not see it requiring 20mA base current to pass the approx 1A of solenoid current.
Choice of this resistor value depends on the required solenoid current and transistor gain and you are quite correct in saying the tutorial could have been a bit more thorough and mentioned this as well as the external supply.

Also it could be mentioned if the transistor’s voltage drop or the transistor base current required too high for comfortable Arduino or RPi operation a Mosfet could be a better choice.

But in all fairness for its purpose the principle remains the same. Up to the experimenter to look after the fine details. A tutorial cannot cover all bases.
Cheers Bob

2 Likes