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:
Using 2 different NodeMCU esp8266 with same code
Using ESP32
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?
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.
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?
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?