How to Control a Servo With a Single Pushbutton

hi, this is my first instructable it is on how to control a single servo with a single pushbutton. I am using this circuit to animate a spiderman mask so it has moving lens. Please comment if you have any advice or uses for this circuit.



Jumper Wires

Arduino Uno

Arduino IDE

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Wiring the Servo

Brown wire from servo to ground

Red to 5v

orange/yellow to digital 2

one wire from the button should go to ground and the other to digital 3

Step 2: Arduino Code


const int buttonPin = 3;

int servoPin=2; Servo Servo1; i

nt buttonState = 0; int flag=0;

void setup(){

pinMode(buttonPin, INPUT_PULLUP);

Servo1.attach(servoPin); }

void loop(){

buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {

if ( flag == 0)

{ Servo1.write(0);

delay(500); flag=1; //change flag variable }

else if ( flag == 1){



flag=0; //change flag variable again } } }

Make it Move

This is an entry in the
Make it Move

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    3 Discussions


    14 days ago

    Very nicely done! A short video clip of the servo being deminstrated might be an enhancement to consider on future Instructables.


    17 days ago

    A good start You got there. Go.. Go.. for the future. You'r on the right track.