I am making a school project for the science fair. I have designed the circuit and written the code, and it works in a simulator, just not in real life. I have tried removing one of the servos from the code and just using the other, and it works fine, but when I try both servos, nothing happens. The servos just buzz a bit and twitch, but they don't move when I press the button.
I am using an Arduino Uno.
Circuit diagram is attached.
Code:
//install servo drivers
#include <Servo.h>
//set button pins
const int buttonFull = 2;
const int buttonHalf = 12;
//create servo objects
Servo servoFull;
Servo servoHalf;
//button status variables
int buttonStateFull = 0;
int buttonStateHalf = 0;
//servo position variables
int servoPosFull = 0;
int servoPosHalf = 0;
void setup() {
// put your setup code here, to run once:
//set button pins to input
pinMode(buttonFull, INPUT);
pinMode(buttonHalf, INPUT);
//attach servos to pins
servoFull.attach(3);
servoHalf.attach(11);
}
void loop() {
// put your main code here, to run repeatedly:
//set button state variable to button input
buttonStateFull = digitalRead(buttonFull);
buttonStateHalf = digitalRead(buttonHalf);
//if green button (full) is pressed, move servos
if (buttonStateFull == HIGH) {
//move servos to 180 degrees
for (servoPosFull = 0; servoPosFull <= 180; servoPosFull += 1) {
servoFull.write(servoPosFull);
delay(15);
}
//wait 10 seconds
delay(10000);
//move servos to 0 degrees
for (servoPosFull = 180; servoPosFull >= 0; servoPosFull -=1) {
servoFull.write(servoPosFull);
delay(15);
}
}
//if red button (half) is pressed, move servo
if (buttonStateHalf == HIGH) {
//move servo to 180 degrees
for (servoPosHalf = 0; servoPosHalf <= 180; servoPosHalf += 1) {
servoHalf.write(servoPosHalf);
delay(15);
}
//wait 10 seconds
delay(10000);
//move servo to 0 degrees
for (servoPosHalf = 180; servoPosHalf >= 0; servoPosHalf -=1) {
servoHalf.write(servoPosHalf);
delay(15);
}
}
}
Please help!