I am new to Arduino I am trying to get the servo motor to point in the direction of the potentiometer for the student kit lesson 6 project. I have watched videos and tried every thing I can think of. I have checked my circuit over and over again and it is just like the instructions say. I have done the same with the code. I don't know what else to do to get it to work. Please help me, thank you.
Start by reading the forum rules and then publish your code and a picture of a hand-drawn diagram showing all your connections, especially those related to how you are powering your circuit
In which direction is the potentiometer?
#include <Servo.h>
Servo myServo;
const int potPin = A0;
int potValue = 0;
int servoAngle = 0;
int servoPin = 9;
void setup() {
myServo.attach(servoPin);
Serial.begin(115200);
}
void loop() {
potValue = analogRead(potPin);
servoAngle = map(potValue, 0, 1023, 5, 175);
myServo.write(servoAngle);
Serial.print("potValue: ");
Serial.print(potValue);
Serial.print(", servoAngle: ");
Serial.println(servoAngle);
delay(100);
}
Arduino Student Kit Syllabus
Arduino_Student_Kit_Syllabus.pdf (102.7 KB)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.