Description: A two-way toggle switch with an Arduino Nano is used to control the movement of a micro servo.
Supplies:
1 – Breadboard 830 Points
1 – Arduino Nano
1 – Two Position Toggle Switch >> Link <<
1 – Micro Servo >> Link <<
Arduino Code:
#include <Servo.h> Servo myservo; int pos = 0; int switch_pin = 5; void setup() { pinMode(switch_pin, INPUT_PULLUP); myservo.attach(9); } void loop() { if(digitalRead(switch_pin) == HIGH) { myservo.write(0); delay(15); } if(digitalRead(switch_pin) == LOW) { myservo.write(180); delay(15); } }