I am working on project which contains several 12V (normally closed) solenoids that need to be controlled via a NodeMCU. (The specs on the solenoid say 100mA drawn at 12V)
The setup I am following uses a TIP120 transistor, a resistor from the GPIO pin to the B on the transistor, and 1N4007 diode across the solenoid; the schematic I am using is like the one I found here: Controlling a Solenoid Valve from an Arduino | Martyn Currey (image attatched)
and a similar one I found here: https://www.bc-robotics.com/tutorials/controlling-a-solenoid-valve-with-arduino/ (image attatched)
The code is essentially something like this:
//--------------------------------------------------------
int solenoidPin = 4; //This is the output pin on the Arduino we are using
void setup() {
// put your setup code here, to run once:
pinMode(solenoidPin, OUTPUT); //Sets the pin as an output
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(1000); //Wait 1 Second
}
//-----------------------------------------------------------
The problem I am having is that the solenoid will not open completely when the pin goes HIGH. I do hear the faint click but the valve remains shut.
Here are the steps I’ve taken in trouble shooting so far:
- I tested to make sure the solenoid works, connecting the B pin of the transistor to a separate 5V source and the valve opens. So the solenoid and wiring seems to be correct.
- I tested to see if 3.3V (the value of HIGH on the GPIO pin on the NodeMCU) was enough to make the transistor “turn on”. I connected the B pin of the transistor to the 3.3V pin on my NodeMCU and the valve opened just fine. So 3.3V wasn’t the issue.
- I tested the voltage at the GPIO pin and it was indeed 3.3V when HIGH, so the pin is working.
- Then I assumed that if the voltage wasn’t the issue, the issue was too little current from the pin. The max current allowed safely from the pin is 12mA.
I measured the current in several places:
When connected to GPIO pin: 3-4mA going through the B pin on transistor (from NodeMCU GPIO pin) when HIGH; 70mA going through the solenoid.
When connected to 3.3V pin directly: 40mA going to the B pin on transistor, 75mA through solenoid.
I assumed the 5mA difference was the issue, so I kept lowering the resistor going to the B pin on the transistor until the current was at the max allowed through the pin (I even went further than recommended until 18mA) and the solenoid still remained shut. - Using relays in place of transistor setup, the entire setup works just fine.
- Googling has not given me any further clarification. (Perhaps I’m googling the wrong thing?)
So my questions are:
- Can someone confirm whether the issue is the limited current on the GPIO pin (12mA) that is the issue?
- How can I know how much current is actually needed to turn the transistor “all the way on” to the extent that the solenoid completely opens? Would this be something I can calculate from the transistor spec sheet (https://www.mouser.com/ds/2/149/TIP120-890130.pdf )? I don’t know which lines to look at and how to calculate this.
I apologize for the long post (just trying to give all the details that might be helpful), and also apologize if my question is naïve …
Thanks for any help!
(P.S. Thanks to everybody who answers questions on this forum – I have been helped immensely over the past several months by reading responses to other people’s questions!)