Hello Everyone,
I have a couple of questions... I using a scale voltage divider to read the value of a car battery. Below is a rough schematic and code that I am using. the voltage I am reading with the arduino between sensorValue and GND does not match the voltage I am reading with my Multimeter. I am assuming the default analogReference is External is this correct?
In the code below if I change the refVolt to what I read on my multimeter between aRef and GND then the voltage matches, but I notice the voltage on Aref is constantly changing.
In another part of my circuit(not shown below) I have a +5V Fixed-Voltage Regulator. is there a way I could set aRef to be a fixed 5 volts?
float refVolt = 5.0;
void loop(){
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (refVolt / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
I suspect that you have misunderstood what the reference voltage does.
Read this page analogReference() - Arduino Reference if you have not already done so.
You are dividing the voltage by 9 or so, giving you a voltage range on the analog pin of 0 - 5V for an input of 0 - 45V or so.
If you change the 10K resistor to 50K, you will get a 0 - 5V range on the pin for 0 - 15V on the input to the voltage divider. Try that and see what the result is.
There are indeed 1024 points between 0 and 1023, but only 1023 steps. If you would subdivise 1 km into meters and use the "1024" logic, each kilometer would be 1000 * (1000/1001) m or 999 m.
And I believe your logic is flawed.
A 1 bit successive approximation ADC can only indicate two states; less than half the reference voltage and greater than or equal to half the reference voltage (or less than or equal to half the reference voltage or greater than half the reference voltage)
A ten bit ADC cannot indicate 5V with a 5V reference, only 5V - 4.882mV.
The number of steps between 0 and 1023 (analogRead range) is 1023 and not 1024. So say you are measuring a voltage variation from 0V to 5V:
By your logic, a byte only has 7 bits, numbered 0 - 7.
A 10 bit value has 1024 possible combinations of zeros and ones. They happen to be represented by bit combinations of 0000000000 through 1111111111.
It does not need to be 'corrected' to 1024 in the Reference section, because that statement reads: Returns int(0 to 1023),
which just happens to be 1024 values.
chute:
I stand corrected, AWOL. Now that you explain it with the way an ADC operates, I see it clearer.
No, it's not even that. Yes, that's the way the ADC works, but it gives you 1024 VALUES.
Look, hold up your left hand. How many digits do you see? 5, right? Now place your right index finger on the little finger. Let's pretend that this is your first value. Call it 0. Move your index finger to each other finger in succession, and count... 1, 2, 3, 4, and there you are at the thumb. Wait a minute? you have 5 digits, not 4. Well sir, you have just succeeded in counting the spaces between your digits, not the digits themselves.
It's the same thing you did when you counted from 0 to 1023 and declared that there were only 1023 states.
Thanks everyone for the feedback, after playing around I finally got something to work.
using Wikipedia and modified the map function
this is pretty much right on.