Analog to Digital Conversion

Hello,

I am attempting to perform analog to digital conversion using my Arduino Uno. I currently have the output of my circuit going to A3 on the Arduino, here is mode code to print the values:

int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3

                       // outside leads to ground and +5V

int sensorValue = 0;  // variable to store the value read



void setup()

{

  Serial.begin(9600);  //  setup serial

}



void loop()

{
int sensorValue = analogRead(A0);

float voltage= sensorValue;

Serial.println(voltage);


}

When I have the output of my circuit connected to pin A3 it reads what shown below, but even when nothing is connected to pin A3 the serial monitor reads the same exact thing, it settles down at about 330. Does anyone have an idea of what exactly I'm doing wrong? I don't understand why it's reading such values whether or not the circuit is connected.

328.00 324.00 328.00 324.00 328.00 324.00 327.00 324.00 328.00 324.00 328.00 324.00 328.00 324.00 328.00 324.00 328.00 423.00 423.00 422.00 422.00 421.00 421.00 421.00 420.00 420.00 422.00 420.00 420.00 419.00 419.00 417.00 418.00 416.00 416.00 415.00 415.00 414.00 414.00 413.00 413.00 412.00 412.00 411.00 411.00 410.00 410.00 409.00 408.00 408.00 408.00 407.00 407.00 406.00 406.00 405.00 405.00 404.00 404.00 403.00 403.00 402.00 402.00 401.00 401.00 400.00 400.00 399.00 399.00 399.00 398.00 398.00 397.00 397.00 396.00 396.00 395.00 395.00 394.00 393.00 393.00 393.00 392.00 392.00 391.00 391.00 390.00 390.00 390.00 390.00 389.00 389.00 388.00 388.00 387.00 387.00 386.00 386.00 385.00 386.00

even when nothing is connected to pin A3

You've got a floating input. (There's very little point converting an integer value to floating point unless you're doing serious arithmetic)

Well then sounds like the floating pin is at... around 1.5-2 volts, maybe a little more. Wave your hands around it (but close to it) and it'll change.

Floating inputs will return unpredictable values, because a floating input with no pullup or pulldown will have no reason to be at any one voltage more than another (within the 0-5v range, the protection diodes keep it from getting out of that range).

I understand now, it seems I need to change 'float' to 'int'. Originally it was float because it was converting the sensor value into volts, ill change the float and see if I get better results. Thank you for taking the time to reply.

And you’re reading A0 not A3

Mark

Just noticed that but it didn't help. I believe my input signal just isn't strong enough, I'm going to do a bit of troubleshooting with the circuit on my own and see if I can come up with anything.

What is your input?

The references to "floating" input are nothing to do with the float type. Connect A3 to Ground, or +5 V and you will get a definite reading.

Leave it unconnected and you get an undefined reading, influenced by nearby things like your hand, activity on nearby pins, etc.