1

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:

void setup() {
  Serial.begin(115200);
  pinMode(D2, OUTPUT);

}

void loop() {
  digitalWrite(D2, LOW);
  delay(3000);
  digitalWrite(D2, HIGH);
  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.

3
  • 1
    Do you mean you have connected 3.3V AND D2 to the positive motor wire? Don't you use any kind of motor driver?
    – chrisl
    Dec 4, 2021 at 21:35
  • @chrisl When I plug the 3.3V wire from NodeMCU to the motor, the motor react, but when the loop start and pass digitalWrite(D2, LOW) the motor still works. The same code/circuit on the Arduino Uno works, the motor go HIGH/LOW when the codes indicates. Thanks!
    – semasad
    Dec 4, 2021 at 21:48
  • So basically you are shorting the output pin by setting it to LOW while it is directly connected to 3.3V?
    – chrisl
    Dec 4, 2021 at 21:53

1 Answer 1

2

So you connected 3.3V and pin D2 both to the positive motor wire. When the pin is high the motor runs and gets its current from the 3.3V pin. When you set the pin to LOW you essentially short the 3.3V pin to ground through the output hardware of the pin. That is highly risky. The output hardware of the pin only can withstand a certain amount of current (around 20mA, 40mA absolute max). Since you have nothing that would limit the current in this path you can easily fry the output hardware of the pin. Don't do that! The same is valid for driving a motor directly only from the digital output pin.

The correct way of controlling a motor with an Arduino or ESP is by using a fitting driver. For just turning it on and off a simple transistor or MOSFET is sufficient (depending on the current draw of the motor a MOSFET is better than a bipolar transistor). Google something like "MOSFET as switch" and you will get many tutorials on that. You can also add the term "Arduino" and you will get tutorials specifically for Arduinos.

Why it worked for the Uno but not for the NodeMCU? You didn't describe how exactly you connected it on the Uno (to the 3.3V pin or the 5V pin?). Probably the digital output pin on the NodeMCU cannot sink enough current so that it is not able to lower the voltage enough. Though if it would be able to do this it would also cause a power failure for the whole microcontroller. Maybe that also happened with your Uno difficult to say without more information.

1
  • Thanks @chrisl!
    – semasad
    Dec 5, 2021 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.