I can't get my SG90 working. I'm powering my uno with a barrel jack, which is in parallel with a step down converter (LM2596) that converts 12v to 5v for the servo. The power supply is rated at 2A and the converter should do 3A from what I've seen on the internet.
I've probed all the output voltages and they look fine. There is continuuity between arduino's, servo's and power supply's ground. Still I can't get the servo to do anything. I've tried adding another connection between converter's out- and arduino ground - no luck. Any tips would be greatly appreciated. Code and a crude diagram below.
#include <Servo.h>
Servo myServo; // Create a servo object to control a servo motor
int servoPin = 7; // Define the pin to which the servo is connected
void setup() {
Serial.begin(9600);
myServo.attach(servoPin); // Attaches the servo on pin 9 to the servo object
for (int angle = 0; angle <= 180; angle++) {
myServo.write(angle); // Set the servo position
Serial.println(angle);
delay(15); // Wait for servo to reach the position
}
delay(2000);
// Sweep the servo from 180 to 0 degrees in steps of 1 degree
for (int angle = 180; angle >= 0; angle--) {
myServo.write(angle); // Set the servo position
delay(15); // Wait for servo to reach the position
}
}
void loop() {
}
Since you don't have serial monitor output on this setup, try with onboard LED pin 13 so you have at least some visual indicator confirming arduino is sending pulses.
Control that your wiring has solid connections.
void setup() {
Serial.begin(9600);
myServo.attach(servoPin); // Attaches the servo on pin 9 to the servo object
for (int angle = 0; angle <= 180; angle++) {
myServo.write(angle); // Set the servo position
Serial.println(angle); <==========================================
delay(15); // Wait for servo to reach the position
}
delay(2000);
// Sweep the servo from 180 to 0 degrees in steps of 1 degree
for (int angle = 180; angle >= 0; angle--) {
myServo.write(angle); // Set the servo position
delay(15); // Wait for servo to reach the position
}
}
Thanks all. I compile and upload. Serial prints work as expected (prints hello, angles etc - I can read it in the serial monitor). To simplify and narrow down the issue I switched to an external 5v power supply. See the diagram below.
#include <Servo.h>
Servo myServo; // Create a servo object to control a servo motor
int servoPin = 7; // Define the pin to which the servo is connected
void setup() {
Serial.begin(9600);
myServo.attach(servoPin); // Attaches the servo on pin 9 to the servo object
for (int angle = 0; angle <= 180; angle++) {
myServo.write(angle); // Set the servo position
Serial.println(angle);
delay(15); // Wait for servo to reach the position
}
delay(2000);
// Sweep the servo from 180 to 0 degrees in steps of 1 degree
for (int angle = 180; angle >= 0; angle--) {
myServo.write(angle); // Set the servo position
delay(15); // Wait for servo to reach the position
}
}
void loop() {
}
unfortunately it still doesn't work. Don't know why. Tried with two separate servos. One randomly switches a little bit (without any code, just power)??
pulse width from ~800 us to ~2200 us, rep rate 50 hz, means at best 10% of 5V. So yes, the OP might see something, or not.
I'm suspecting that if all jumpers are intact, pin 7 has been fried somehow, so the OP should switch to another pin for testing.
@TomGeorge - the voltage is 0 when measured to the psu gnd and around 0.5v when measured to the uno directly. So I would assume that my issues are ground connected after all. However I don't understand why it is this way... I measure 5v when probing the + and either of - on the psu leads