Hi all,
I am trying to map out the analog input read from a 20k potetiometer in order to drive a servo using a UNO board. I am getting the correct readings on my analogRead but the map function does not seem to actually map out the values. Please find below a copy of the commented code and some it's output on the serial monitor.
Code:
#include <Servo.h>
Servo Servo1;
int const PotentiometerPin = A0; //Assign "Potentiometer" to A0 Analog Input
int PVoltage; //Variable for Potentiometer Voltage after ADC (0,1023)
int PAngle; //Variable for Potentiometer Turn Angle (0,179)
void setup() {
Servo1.attach(3); //Assign to PWM 3
Serial.begin(9600);
}
void loop() {
PVoltage = analogRead(PotentiometerPin);//Read potentiometer value
Serial.print("Potentiometer Value:");//Print message
Serial.print(PVoltage); //Print value
PAngle = map(PotentiometerPin, 0, 1023, 0, 179);//Maps Potentiometer Angle to motor angle
Serial.print(" Angle Value:"); //Print message
Serial.println(PAngle); //Print value and jump to next line
Servo1.write(PAngle); //Rotate servo to position between 0 and 179
delay(15); //Delay
}
Serial Monitor:
Potentiometer Value:73 Angle Value:2
Potentiometer Value:165 Angle Value:2
Potentiometer Value:274 Angle Value:2
Potentiometer Value:536 Angle Value:2
Potentiometer Value:662 Angle Value:2
My impression is that the reading at "A0" is correct; however, why does my output for PAngle variable always stay at 2?
Thanks in advance!