Hey guys, I'm extremely new to electronic circuits and fairly new to programming. I was using the starter kit and have had no real issues till the most recent project, 05. Essenially it uses a pot to control a servo motor. Here is my code:
const int potMeterPin = A0;
const int ServoOutputPin = 10;int angle;
int potValue;#include <Servo.h>
Servo theServo;
void setup (){
Serial.begin(9600);
theServo.attach(ServoOutputPin);}
void loop ()
{potValue = analogRead(potMeterPin);
angle = map(potValue, 0, 1023, 0, 179);
Serial.println("The pot value is: ");
Serial.println(potValue);
Serial.print("The angle is: ");
Serial.println(angle);theServo.write(angle);
delay(500);}
A few problems come up. The pot is twisted as far as it goes on one end and I'm getting these readings: keep in mind the servo motor is not responding.
The pot value is:
406
The angle is: 71
The pot value is:
386
The angle is: 67
The pot value is:
372
The angle is: 65
The pot value is:
361
The angle is: 63
The pot value is:
354
The angle is: 61
The pot value is:
347
The angle is: 60
The pot value is:
340
The angle is: 59
The pot value is:
335
The angle is: 58
The pot value is:
331
The angle is: 57
The pot value is:
329
The angle is: 57
The pot value is:
329
The angle is: 57
The pot value is:
331
The angle is: 57
The pot value is:
335
The angle is: 58
The pot value is:
It stabilizes at 58 - 60, but it doesn't do anything, even if I twist the pot to a different value. I've tried replacing the pots and the wires but I keep getting the same results. Servo.write also wouldn't work if I did
const int potMeterPin = A0;
const int ServoOutputPin = 10;int angle;
int potValue;#include <Servo.h>
Servo theServo;
void setup (){
Serial.begin(9600);
theServo.attach(ServoOutputPin);}
void loop ()
{potValue = analogRead(potMeterPin);
angle = map(potValue, 0, 1023, 0, 179);
Serial.println("The pot value is: ");
Serial.println(potValue);
Serial.print("The angle is: ");
Serial.println(angle);theServo.write(angle);
delay(500);}
In the end I tried using the prebuilt example in the IDE, but I got the same results. Maybe it's something in the circuit? Here's a picture of the circuit I made(excuse me for the crappy management). Imgur: The magic of the Internet
Thanks for the help.