Hi, I have a arduino eleven and im still fairly new to it. I have a shield on top of it and 4 servos connected in parallel on a breadboard with rails to the arduino. 3 of the servos are connected positive,negative and signal together on the breadboard and the 1 servo has only the the signal connected to the breadboard and the 5v wire and GND to the shield.
I uploaded this sketch for the servos to work and it did work
#include <Servo.h>
// Set digital pin numbers:
const int servoPin = 9; // The number of the Servo pin
const int buttonPin = 8; // The number of the Pushbutton pin
int buttonState = 0; // Variable for reading the pushbutton status
int directionState = 0; // Variable for reading direction of the servo
Servo myservo; // Create servo object to control a servo
int pos = 0; // Variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 8 to the servo object
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (directionState == 0){
//The button is pushed
if (buttonState == HIGH) {
directionState = 1;// The direction for the servo is clockwise
// goes from 0 degrees to 180 degrees in steps of 1 degree
for(pos= 0; pos <=90; pos =pos+90)
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
} else if (directionState == 1) {
// The button is pushed
if (buttonState == HIGH) {
directionState = 0; // The direction for the servo is anti-clockwise
// goes from 180 degrees to 0 degrees in steps of 1 degree
for(pos= 0; pos <=90; pos =pos+90)
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
}
}
and then i decided to upload this new sketch to my board and i had left it for a while
[/b]
#include <Servo.h>
Servo myservo; // creating myservo object
int buttonPin = 8;
int servoPin = 9;
int buttonState = 0; // set buttonState
void setup()
{
myservo.attach(servoPin);
pinMode(buttonPin, INPUT);
}
void loop()
{ buttonState = digitalRead(buttonPin); // read and save to the variable "buttonState" the actual state of button
if (buttonState == HIGH)
myservo.write(0); else
myservo.write(90);
}
but now when i try to upload the first sketch, it would upload but the servos keep jerking to their position. Any ideas?