Introduction: 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.
Supplies
Servo
Jumper Wires
Arduino Uno
Arduino IDE
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
#include
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){
Servo1.write(70);
delay(500);
flag=0; //change flag variable again } } }

Participated in the
Make it Move
8 Comments
2 years ago on Step 2
Please help me if I am using 16 chanal servo controller how i controll each servo with separate switch
Reply 2 years ago
I have never worked with a 16 channel servo controller but i think this instructable might help
https://www.instructables.com/id/Arduino-Multi-Servo-Control-Up-to-16-With-Arduino/
3 years ago
Nice job on your first Instructable :)
Reply 3 years ago
I am happy to hear this thank you so much
3 years ago
A good start You got there. Go.. Go.. for the future. You'r on the right track.
Reply 3 years ago
thanks for the encouragement
3 years ago
Very nicely done! A short video clip of the servo being deminstrated might be an enhancement to consider on future Instructables.
Reply 3 years ago
Thanks for the posotive feedback