I'm attempting to read the voltage as I turn the dial. This does not happen however. The output on the serial port starts showing figures when I turn the 24V power supply on but it just flucuates between 0-70 (I havent set the code to convert that yet) every 5 seconds now matter how high or low the dial is. Does anyone have any ideas as to why this is happening?
You mention the voltage divider but didn't detail the values of the resistors chosen for R1 & R2. Have you gone for two of the same value to halve the input range to 0-5V, or some other values?
Have you got a multimeter to confirm the voltage output when you're getting your reading of 70? Finally, can you also copy and paste the Arduino code you're using in between CODE tags just so we can doublecheck what you've done there too?
I'm using two 1k ohm resistors to half the voltage.
const int analogPin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
float val = analogRead(analogPin); // read the value from the sensor
Serial.println(val); // print the value
delay(300);
}
I just wanted to check the value on the sensor changed initially but this doesn't happen.
I have access to a voltmeter to check the output is right but I need to drive to get it, would that be the first thing you recommend I do?
If you don't have a voltmeter handy, it's not the first thing you need so that's all good.
A fluctuating value is what you'd expect if there's not a good connection between your input and that analog input as it will pick up random noise when disconnected. So the first thing to ensure is your input is actually connected to your Arduino Analog pin 0, and not accidentally to digital pin 0. The analog pins, if you're using a Uno, are on the same side of the board as the 5V, 3.3V GND and VIN pins in the adjacent power block, and 0 should be the analog input physically nearest those power pins.
float val = analogRead(analogPin); // read the value from the sensor
A minor niggle, but the analogRead function returns an integer type. So, following your style this would be preferable...
int val = analogRead(analogPin); // read the value from the sensor