Servo 0 - 180 - 0

Hey,

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,

Bart

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

...R

Possible info:

https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=servo+toggle&btnG=search&domains=http%3A%2F%2Fforum.arduino.cc&sitesearch=http%3A%2F%2Fforum.arduino.cc&gws_rd=ssl

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

 

 

 

 http://arduino.cc/starterKit

 

 

 

 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: ");

 

 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: ");

 

 Serial.println(angle); 

 

 // set the servo position 

 

 myServo.write(angle);

 

 // wait for the servo to get there 

 

 delay(15);

 

}

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: