1

I have a NodeMCU and im trying to control a servo to move from angle A to B and viceversa. The thing is I want to be able to power off the servo after moving so it could stop getting voltage and current. I decided to use an NPN transistor (2N2222A to be more precise) and the servo red cable is connected from one end of the transistor and the other end is connected to the red line in my breadboard while the middle pin is connected to a pin in the NodeMCU. The thing is, it seems to work with a SG90 perfectly but when an MG90S is connected it doesn't move and you can hear a faint clicking from the servo. When the MG90S is instead connected directly to voltage line it works. I don't understand what the problem is. I also implemented the servo.detach(); function and it works but I don't know if it truly shuts off power to the servo like using a transistor would.

if (buttonState2 == HIGH) {
  digitalWrite(LED2, HIGH);
  digitalWrite(transistor2, HIGH);

  for (pos2 = 90; pos2 < 180; pos2 = pos2 + 1) {
    servo2.write(pos2);
    delay(15);
  }
  digitalWrite(transistor2, LOW);
  digitalWrite(LED2, LOW);
}

This is the code that I have, I would really appreciate some help, Thanks!

2
  • run your code, then turn off the servo power manually at the appropriate time ... doing that shows you the servo behavior if the power was turned off electronically ... does the servo behave as desired when you do that? – jsotola Oct 30 '20 at 17:08
  • You need a PNP or P-channel FET to switch the + (red) connection. An NPN or N-channel FET won't work right. – Majenko Oct 30 '20 at 17:26