# Can Not Read Proper Voltage?

Hello,

So I have a project that is using a simple voltage divider. Two 10K resistors from a 5V. When I try and read it with the Teensy, I am getting around 4.0 voltage, but I even verified it with my fluke that it is at 2.5V!!! Why would my teensy not read the proper voltage.
Here is the Code I am using. Could the ADC be screwed up? It does change when I change the voltage divider, but it kinda seems it is always 1V above the true voltage.

void setup()
{
Serial.begin(9600);
}

void loop()
{
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
}

If so, 2.5volt = ~76% of the A/D range = 3.8volt.
Leo..

Nope. I have the Teensy 3.1. I am powering both the teensy and the voltage divider by 5V.

Maybe the DAC is messed up? Any ways to test that? None of this makes sense. :o

Is there not an on-board 3.3V regulator on the teensy board? I think 2 holes down from VIN is "3V", if you check that and it is 3.3V then yes there is a on-board regulator.

EDIT: Or set any digital output pin high and measure the voltage on that pin, whatever that voltage is should represent your reference voltage (for use in sensorValue * (5.0 / 1023.0))

Yes there is one on it, but I am not using the 3.3 supplied voltage.

I just looked at a teensy circuit diagram.
This one.
Both USB in and Vin connect (via a series diode) to a voltage regulator input (inside the micro).
As far as I can see, everything runs on 3.3volt.
Leo..

Ah gotcha, so you are putting bypassing the regulator and putting 5V straight to the chip? Did you catch the EDIT I made above about reference value?

5volt on the resistor divider is halved to 2.5volt.

OP is powering the teensy also from 5volt (USB or Vin), but that is internally regulated to 3.3volt.
Vref must therefore also be 3.3volt.

If you measure 2.5volt with a 3.3volt micro, and use "5volt" in the code (5.0 / 1023.0), you get a ~3.8volt readout.

Measure the 3.3volt pin with a DMM, and enter the exact value in the code for increased accuracy.
e.g. (3.32/1023.0)
Leo..

I am in total agreement with you Wawa, that was what I was getting at above. I suggested doing a digitalWrite and measuring the voltage at the pin simply for the OP to determine beyond a doubt what voltage the chip is actually being supplied (as digitalWrite voltage will be equal to the voltage supplied to the chip itself, not what is supplied to the board).

BH72:
I am in total agreement with you Wawa, that was what I was getting at above. I suggested doing a digitalWrite and measuring the voltage at the pin simply for the OP to determine beyond a doubt what voltage the chip is actually being supplied (as digitalWrite voltage will be equal to the voltage supplied to the chip itself, not what is supplied to the board).

I don't get this.
Reading the chip's supply with a Vref that is the same as the chip's supply will always give you a value of 1023.
No matter what the supply is.
Leo..

Wawa:
I don't get this.
Reading the chip's supply with a Vref that is the same as the chip's supply will always give you a value of 1023.
No matter what the supply is.
Leo..

I should have phrased this better.

Measure the output produced by digitalWrite with a DMM, this becomes the reference voltage to put in the formula.

Ahh, I see.
You want to set an output pin to “high”, and measure it to see if it’s 3.3volt or 5volt.
Sure, but measure the true voltage afterwards on the corresponding supply pin.
Leo…

Wawa:
Ahh, I see.
You want to set an output pin to "high", and measure it to see if it's 3.3volt or 5volt.
Sure, but measure the true voltage afterwards on the corresponding supply pin.
Leo..

Exactly, check the pin with a DMM to get past this 3.3V/5V thing and then check the supply pin to get the proper reference for the formula.

And the conversion should not be (5.0 / 1023.0) but (5.0 / 1024.0)

Haha, was just thinking of that. but I can't explain.

"Sensorvalue" can be 0-1023, so 1023 max.

If the formula is "sensorvalue (5 / 1024)", I get 4.995117volt on my calculator (~4.995volt).
If the formula is "sensorvalue (5 / 1023)", I get 4.999999volt on my calculator (~5volt).
(calculator rounds)

Leo..

Hint: A perfectly in-spec applied voltage of 5.1V would also read 1023.

I was hoping Grumpy_Mike would explain, because he was the one correcting it.

And yes. 5.2volt will also read 1023, but what has that got to do with it.
Leo..

And yes. 5.2volt will also read 1023, but what has that got to do with it.

It's a clue.

Another clue is the existence of devices like the ADR380 and LM4040 voltage references.

You still haven't said what you think the right answer is.

Well, I didn’t correct anything.

There are 1024 digital steps, but they are 0-1023.
1024 should not be used in calculations, otherwise you shouldn’t use zero either.

But I have less posts, less stars, and less Karma…
Leo…