Servor Motor + 5 Push Button Control -> Only two buttons work?

Hello,

So I’m using a standard servo motor, the one that comes in the Arduino starter kit. I have 5 push-buttons set up on a board with my servo, each button goes to a digital pin. Basically, push the button and tell the servo to move to a particular angle. Didn’t seem to hard; even put LEDs on the switches to ensure that when I was pushing them that they went HIGH.

Below is my code that I’m using and I attached a picture of my circuit setup. Each LED color is so I know what angle value the button is associated with.

#include <Servo.h>

Servo myservo;

int angle = 0;

const int zero = 5;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
const int ten = 6;
const int thirty = 7; 
const int sixty = 8; 
const int ninty = 9; 

void setup(){
 myservo.attach(10); 
 Serial.begin(115200); 
 pinMode(zero, INPUT); 
 pinMode(ten, INPUT); 
 pinMode(thirty, INPUT); 
 pinMode(sixty, INPUT); 
 pinMode(ninty, INPUT); 
}

void loop(){
  int zeroo = digitalRead(zero); 
  if(zeroo == HIGH)
  { 
    angle = 2;
    myservo.write(angle); 
    delay(15); 
  }
  int tenn = digitalRead(ten); 
  if(tenn == HIGH)
  { 
    angle = 10;
    myservo.write(angle);
    delay(15);
  }
  int thirtyy = digitalRead(thirty);
  if(thirtyy == HIGH)
  { 
    angle = 30;
    myservo.write(angle);
    delay(15);
  }
  int sixtyy = digitalRead(sixty);
  if(sixtyy == HIGH)
  { 
    angle = 60;
    myservo.write(angle);
    delay(15);
  }
  int nintyy = digitalRead(ninty);   
  if(nintyy == HIGH)
  { 
    angle = 90;
    myservo.write(angle);
    delay(15);
  }
}

Red = 2 degrees
Yellow = 10 degrees
Green = 30 degrees
Blue = 60 degrees
White = 90 degrees

My issue is the Red - Green buttons don’t do anything, they light up normally; but the servo is unresponsive. The Blue button seems to move the servo to 90 degrees instead of 60 and the White button seems to move the servo to 60 degrees instead of 90. Not sure what I have hooked up or coded wrong. Maybe my breadboard is damaged or the UNO itself, unlikely but still possible.

As always any insight or direction is greatly appreciated! :smiley:

Cheers,
UST

I can't see the image of your circuit.

BTW Have you tried swaping the colours around. Usually the colour of an LED has a bearing on it's forward voltage. This could also explain why some of your buttons behave differently to the others.

(I haven't even looked at the code yet)

That's a great idea, I will try to put all of the same LEDs, maybe the red standard ones. Also I will try to post the picture again. Also, thanks for the speedy reply xD

UPDATE: Switching the LEDs to all the same colour did not work.

Is the picture working now?