D1 Mini Servo Not Working

Hello im very new in arduino, I want to make my servo(Tower Pro SG90) rotate but it doesnt work.

This is my code:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(13);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
}

What I've tried:

  1. Using 2 different NodeMCU esp8266 with same code
  2. Using ESP32
  3. Tryout every single pin available

I watch many youtube tutorial and none of them works with me

All things I tried didn't work, but when I try the code with Arduino Nano, it works.
So why doesn't it work with my D1 Mini?

Show us the ESP32 wiring connections, and the ESP32 SKETCH.

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

Was it like this ?


See this:

Yes exactly but without the web server
And this is my wiring

Yellow to Signal
Blue to GND
Green to VIN

Nano's 5V, but aren't the D1 and the others that don't work 3V3?

(Not that you should provide power from the uC anyway, not even a 5V one.)

edit... hmmm the video shows it working as wired in post #3, but it also mentions using a specific version of the servo library.

I'm very new in this microcontroller world, I know coding but very little knowledge of wiring stuffs, I only follow tutorial from youtube for now, what I know is, the servo should work on 3V3 like the tutorials I saw, but it doesn't work on mine, it works only in Arduino Nano, I don't know what's wrong with it, is it because of the voltage? but why everyone working but not me? I'm still figuring this out.

Yes the video shows it working as wired in post #3, but it also mentions using a specific version of the servo library.

Your servo power lead is connected to +5V ?

All of the data sheets that I see for the SG90 servo states power minimum is 4.8V. Expecting the servo to work at 3.3V is optimistic, at best.

I Downloaded same version from here

D1 Mini has 5V, and the red cable is connected 5V

I tried to use servo with D1 Mini , I assume it worked because D1 mini has 5V pin, but it didn't work

What voltage is the signal?- if it's 3V3 is that high enough to be a "high"?

I dont know what you mean... can you elaborate? sorry.

Well apart from the power supply needing to be 5V (that is 5V across the red and black) the signal voltage (the voltage across the yellow and black) also needs to be high enough for the servo to recognise it as high. The signal switches from low to high and sends a high pulse of certain duration and the servo's electronics interprets that duration as a position.

So I'm wondering if the ESP device which I thought was 3V3 not 5V, provides a high enough high?

But that all said, even if the voltages are ok, perhaps the ESP can't provide enough current.

Easiest way to resolve this might be to use an external 5V supply for the servo; that's in any case best practice.

Oh, from your explanation above now I have more understanding about the problems, I'll try with the external power supply. But the question is why everybody working but no mine? is it involve luck to run it on 3V3?

Well as pointed out above:

... so probably, yes.

edit:

Connect the grounds.

Allright then, I'll try it first with the external power, thank you all for replying :smiley:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.