Servo 0 - 180 - 0


I'm totally new to the Arduino experience and i would like to ask you guys if you could tell me where i could find some information for my project.

The project is simple :

1 - button push = servo goes from 0 to 180 degrees
2 - button push = servo goes back from 180 degrees to 0

I know that for you guys this is a project that can be done in two minutes but i can't find or don't (...yet) know how to find the information that i need.

i will be grateful for any information.

Best regards,


Start by looking through the example programs that come with the Arduino IDE. There are examples for button switches and for servos.


Possible info:

There’s a servo example in the IDE Examples, wouldn’t be hard to have it move after reading a button push vs a reading fom analog input.



 Arduino Starter Kit example


 Project 5 - Servo Mood Indicator




 This sketch is written to accompany Project 5 in the


 Arduino Starter Kit




 Parts required:


 servo motor 


 10 kilohm potentiometer 


 2 100 uF electrolytic capacitors




 Created 13 September 2012


 by Scott Fitzgerald




 This example code is part of the public domain 




// include the servo library


#include <Servo.h>


Servo myServo; // create a servo object 


int const potPin = A0; // analog pin used to connect the potentiometer


int potVal; // variable to read the value from the analog pin 


int angle; // variable to hold the angle for the servo motor 


void setup() {


 myServo.attach(9); // attaches the servo on pin 9 to the servo object 


 Serial.begin(9600); // open a serial connection to your computer




void loop() {


 potVal = analogRead(potPin); // read the value of the potentiometer


 // print out the value to the serial monitor


 Serial.print("potVal: ");




 // scale the numbers from the pot 


 angle = map(potVal, 0, 1023, 0, 179);


 // print out the angle for the servo motor 


 Serial.print(", angle: ");




 // set the servo position 




 // wait for the servo to get there 





Note that the "button push" is non-trivial - it requires de-bouncing and transition logic as presumably you do not want the servo to keep cycling if the button is held pushed.

Thank you all for your help :slight_smile: