NodeMCU with 12V solenoid and TIP120 transistor issue

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:

  1. 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.
  2. 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.
  3. I tested the voltage at the GPIO pin and it was indeed 3.3V when HIGH, so the pin is working.
  4. 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.
  5. Using relays in place of transistor setup, the entire setup works just fine.
  6. Googling has not given me any further clarification. (Perhaps I’m googling the wrong thing?)

So my questions are:

  1. Can someone confirm whether the issue is the limited current on the GPIO pin (12mA) that is the issue?
  2. 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!)

sch1.png

Sounds like you might have the TIP120 terminals backwards, should be:
12V + to valve, other valve wire to TIP120 collector (middle pin), TIP120 emitter (right pin) to ground, Arduino output pin to 1k resistor to TIP120 base (left pin), 12V ground connected to Arduino ground.
And make sure you have the diode in place and polarity right, cathode (end with band) toward 12V +.

Did you check the 12V supply when the valve was powered, the voltage drop from collector to emitter? The TIP120 has current gain of about 1000 so 4 mA into the base should fully saturate it. Being a Darlington, it does drop a volt +. A common 2N2222 could work there (rated 600 mA) with 330 or 220Ω base resistor, do you have one?

how do you expect the valve to fully open with your sketch like this

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
}

solenoid valve has like 300,000 life cycles, and your sketch opens/closes it in every 2 secs,

you are straining it , and it won't even last

for your info digitalWrite(solenoidPin, HIGH); just keeps the valve 50% open

flowing water (under pressure) does make it to the 100% opening

Thank you outsider and KASSIMSAMJI for your replies!

outsider - - I went back to take the measurements you suggested, and much to my surprise, the valve is working now! I haven't changed a thing, still using the same setup etc, I have no idea what was different that made it work now and not work during the past several days...!
(Voltage now between emitter and collector is 12V when off and 0.75V when on, which is what I would expect...)

KASSIMSAMJI - - As for the coding, my actual project has the valve open only when a button is pressed (not nearly every 2 seconds, only when i need the airbag to inflate), but I went back and changed it to exactly what the tutorial said thinking maybe the issue was my code. But thanks for the input!