Good Afternoon Everyone,
I am trying to control the position of a servo via a toggle switch. Quite simply; switch in OFF position correlates to servo at 90 deg, switch in ON position correlates to servo at 100 deg. When the switch is turned back off it would then just go back to 90.
I have read and tried to implement a few examples I found on here but am not getting a response from the servo motor. Attached is the connection diagram I have generated, Including a capacitor to help the board with the initial current draw of the servo, and a resistor to pull down the voltage.
Here is the code I am working with (from this forum)
#include <Servo.h>
int button = 4; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;
void setup()
{
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(9); //pin for servo control signal
digitalWrite(4, HIGH); //enable pullups to make pin high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
servo.write(90);
toggle = !toggle;
}
else
{
servo.write(100);
toggle = !toggle;
}
}
delay(500); //delay for debounce
}
Greatly appreciate your help