I have a project where I have a button on a breadboard which activates a servo via a programmed Arduino. Currently, this is my code:
#include <Servo.h>
Servo sA;
int d=2; // to store on or off value
void setup(){
sA.attach(A0);
pinMode(2,INPUT);
pinMode(A0,OUTPUT);
pinMode(13,OUTPUT);
sA.write(90);
}
void loop(){
d=digitalRead(2);
if(d==0){
sA.write(90);
digitalWrite(13,HIGH);
}elseThe
sA.write(0);}
digitalWrite(13,LOW);
}
The LED is in here as a test of the button (which I had had issues with). When the button is pressed, the LED lights up as intended in the if statement. The servo (TowerPro MG995) is wired up directly to a VEX 7.2 volt battery for power, which I know works for power. However, the button is not activating the servo or registering a response at all. Is there an issue with the code? The servo's data cord is wired straight to pin A0 as in the code.