Hi Guys
Trying to make my project work and finding a lot of difficulty
I am trying to connect a servo motor to two buttons where each button makes the servo rotate by 90 degrees
the coding is this:
#include <Servo.h>
Servo myservo;
byte myservoPin = 9;
byte myservoGoOneWayButton = 2; //wire buttons from pin to ground
byte myservoGoOtherWayButton = 3;
byte minPos = 5; //I like to keep away from the end stops
byte maxPos = 175;
void setup()
{
Serial.begin(9600);
Serial.println(".... servo controlled by two buttons ....");
Serial.print("Created: ");
Serial.print(TIME);
Serial.print(", ");
Serial.println(DATE);
Serial.print("File: ");
Serial.println(FILE);
//by default will start at midpoint=90
// uncomment one of these next lines if you want to start at one side
//myservo.write(minPos);
//myservo.write(maxPos);
myservo.attach(myservoPin);
pinMode(myservoGoOneWayButton, INPUT_PULLUP); //wire buttons from pin to ground
pinMode(myservoGoOtherWayButton, INPUT_PULLUP);
Serial.println("press a button..."); Serial.println(" ");
} //setup
void loop()
{
if (digitalRead(myservoGoOneWayButton) == LOW) //buttons with input_pullup are low when pressed
{
myservo.write(minPos);
// this approach just zooms the servo at full speed, see https://www.arduino.cc/en/Tutorial/Sweep if that's a problem
Serial.println("going one way");
}
else if (digitalRead(myservoGoOtherWayButton) == LOW) //buttons with input_pullup are low when pressed
{
myservo.write(maxPos);
// this approach just zooms the servo at full speed, see https://www.arduino.cc/en/Tutorial/Sweep if that's a problem
Serial.println("going other way");
}
} //loop
Finally i have wired the servo to the vin, ground and d9, i have also wired each button to d2 and d3 and both to the same ground, i have also wired the ground to the panel mount barrel jack and also to the vin, when plugged in and turned on the power light on the arduino is lit however the buttons do not work
Any help would be very appreciated
Cheers
Jake