Last active
December 5, 2025 13:44
-
-
Save psychemist/bf0c97baa071391200042c0bf7386653 to your computer and use it in GitHub Desktop.
Arduino Starter Project 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // import Servo library | |
| #include <Servo.h> | |
| // create Servo object from library | |
| Servo myServo; | |
| // declare variables for potentiometer pin, analog input value and servo angle | |
| int const potPin = A0; | |
| int potVal; | |
| int angle; | |
| void setup() { | |
| // connect servo and digital pin 9 | |
| myServo.attach(9); | |
| // initialize serial port between board and computer | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| // read out analog input and read to serial monitor | |
| potVal = analogRead(potPin); | |
| Serial.print("PotVal: "); | |
| Serial.print(potVal); | |
| // scale analog potentiometer values to usable range | |
| angle = map(potVal, 0, 1023, 0, 179); | |
| Serial.print(", Angle: "); | |
| Serial.print(angle); | |
| // move servo to specified angle | |
| myServo.write(angle); | |
| delay(15); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment