Devices & Components
Arduino Uno Rev3
Resistor 10k ohm
Breadboard (generic)
Pushbutton switch 12mm
Jumper wires (generic)
SG90 Micro-servo motor
Software & Tools
Arduino IDE
Project description
Code
Project code:
c_cpp
I used arduino IDE to do the code
1int button = 2; //pin of the first button 2int button1 = 3; //pin of the second button 3#include<Servo.h> //include the servo library 4Servo servo; //create a servo object 5int pos = 0; //initial position of the servo 6void setup() { 7 // put your setup code here, to run once: 8 servo.attach(9); //pin used by the servo 9 pinMode(button, INPUT_PULLUP); //define first button as input pullup 10 pinMode(button1, INPUT_PULLUP); //define second button as input pullup 11 /* 12 INPUT_PULLUP send to arduino LOW signal, so, when you press the button, you send a LOW signal to arduino 13 */ 14} 15 16void loop() { 17 // put your main code here, to run repeatedly: 18 if (digitalRead(button) == LOW) { //if Value read of the button ==LOW: 19 pos++; //increases the value of the "pos" variable each time the push button of the left is pressed 20 delay(5); //5 milliseconds of delay 21 servo.write(pos); //servo goes to variable pos 22 } 23 if (digitalRead(button1) == LOW) { //if Value read of the button ==LOW: 24 pos--; //decreases the value of the "pos" variable each time the push button of the right is pressed 25 delay(5); //5 milliseconds of delay 26 servo.write(pos); //servo goes to variable pos 27 } 28}
Downloadable files
Circuit diagram
I used TinkerCad to do this diagram
Circuit diagram

Circuit diagram
I used TinkerCad to do this diagram
Circuit diagram

Comments
Only logged in users can leave comments