Need help adding a button to my servo motor Project

Hello, i'm doing a project with an uno. I'm somewhat of a beginner, i'm watching Paul Mcwhotter but still need help. My hobby project is to get a servo motor to sweep from o to 180 degrees and back again when i push a button.
Then I'd like to play around with degrees and delays which I'm comfortable with.
I'm sure someone has done this before can i use code that already out there and modify it and add to it. This my first post .
Many thanks

I feel confident that if you look at the Sweep example that comes with the Servo library, and a basic usage example that will be included in pretty much every button library under the sun that you will find all the code you need.

And I'm also confident that you will find, after a little thought, that you are perfectly capable of combining them into a functional whole.

Here is a very basic sketch to do what you need:

#include <Servo.h>

const int buttonPin = 12;  // the number of the pushbutton pin
const int servoPin = 5;    // the number of the servo pin


Servo myservo;  // create Servo object to control a servo

void setup() {
  pinMode(buttonPin, INPUT);
  myservo.attach(servoPin);  // attaches the servo on pin 9 to the Servo object
}


void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  if (reading == HIGH) {


    myservo.write(0);
    delay(500);
    myservo.write(180);
    delay(500);
    myservo.write(0);
    delay(500);
  }
}

thank you

thanks for this much appreciated

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.