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 } } }
![Make it Move](https://content.instructables.com/F5R/7PQL/JZX147QZ/F5R7PQLJZX147QZ.jpg?auto=webp&frame=1&width=320)
Participated in the
Make it Move