Hey!
I am trying to test out a servo with my Arduino. I cannot seem to be able to control the servo for some reason. The servo should work, and I am using an external power source if 4 AA batteries, which output 6V.
I opened up the servo and gave it current directly, and it turns, but controlling it doesn't seem to do anything. Here's my code. I tried to keep it as simple as possible as to make no mistakes:
The led tells me that the loop is running, but the servo is not responding.
What gives?
EDIT:
I tested the analog pin with a LED and it works as intended. The power supply also should be stable. The loop like mentioned earlier is running.
I am trying to test out a servo with my Arduino. I cannot seem to be able to control the servo for some reason. The servo should work, and I am using an external power source if 4 AA batteries, which output 6V.
I opened up the servo and gave it current directly, and it turns, but controlling it doesn't seem to do anything. Here's my code. I tried to keep it as simple as possible as to make no mistakes:
Code:
#include <Servo.h>
Servo servo;
int servoPosition = 0;
int servoPin = 3; // I originally used 9 but that pin did not seem to function either.
int ledPin = 13;
void setup() {
servo.attach(servoPin);
pinMode(ledPin,OUTPUT);
}
void loop() {
servo.write(servoPosition);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
servoPosition += 90;
servo.write(servoPosition);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
servoPosition += 90;
servo.write(servoPosition);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
servoPosition = 0;
}
What gives?
EDIT:
I tested the analog pin with a LED and it works as intended. The power supply also should be stable. The loop like mentioned earlier is running.
Last edited:
