-->
Page 1 of 1

Selenoid motor not responding to NodeMCU instructions

PostPosted: Sat Dec 04, 2021 4:05 pm
by semasad
I just start a project migrating from Arduino Uno to NodeMCU, basically this projects control some selenoid motors triggered by a website instructions. For example: if website returns 2, the motor #2 start work.

I hace everything ready, fetching from the website but, the motors are not working. In Arduino Uno works but in NodeMCU did not.

The selenoid motor is this one from AliExpress: the 3v --> https://es.aliexpress.com/item/4000807560712.html

The circuit I made is like this:

NodeMCU / Motor

D2 -> Positive motor wire (red wire).

3.3V -> Positive motor wire (red wire).

GND -> Negative motor wire (black wire).

All this is attached to a protoboard for easy my work, but those are the connections of the circuit.

At otherwise, the code looks something like this:
Code: Select allvoid setup() {
  Serial.begin(115200);
  pinMode(D2, OUTPUT);

}

void loop() {
  analogWrite(D2, 0);
  delay(3000);
  analogWrite(D2, 100);
  delay(3000);

}


I also tried instead of pin name D2 use 4 corresponding of the GPIO number. Didn't work.

The wired part is in Arduino Uno the same code and same circuit works perfectly, but in NodeMCU not.

Re: Selenoid motor not responding to NodeMCU instructions

PostPosted: Tue Dec 07, 2021 6:21 am
by rpiloverbd
Sounds like the solenoid is not getting sufficient current. Have you tried analogwrite(D2,255)? If still no luck, try switching the solenoid with a BJT or MOSFET.

Re: Selenoid motor not responding to NodeMCU instructions

PostPosted: Tue Dec 07, 2021 11:32 am
by QuickFix
It's a pity the seller doesn't specify the current needed by this solenoid, but normally solenoids draw too much current to be driven directly by the GPIO (max current of 12mA) of an ESP8266 and a driver transistor (or MOSFET) is required.
You first need to find the needed current (just use a 3.3V power supply with a current meter in series of the solenoid) before actually trying to connect it to any ­µC (not only an ESP).

Also please add a flyback diode anti-parallel to the solenoid or you'll fry the ESP. :idea:

An example project you can copy it from: WiFi controlled solenoid