Power supply questions

I noticed that my analogRead was showing 1023 at 4.4v and I'd like to read 1023 at 5v. After some research it appears the ADC scale is a reference to the 5v pin (which is a direct correlation to the usb power voltage or the barrel jack power voltage. Is all of that correct?

If so, I took a measurement of the Arduino 5v pin voltage value and it's at 4.4v, which would correlate with my ADC scale being skewed. Am I able to power the Arduino through the barrel jack, while still plugged into my laptop and using the serial communication? If yes, what's a safe known good power supply to purchase and do this with, to achieve a true 5v out of the 5v pin and as a reference value?

I'm using a Mega 2560 if that matters.

Why are you feeding it 4.4v? Why do you need exactly 5.0v out of the %v pin? What are you trying o do?

You can power it with 5V at the 5V pin. Phone chargers are 5V and perfectly good, just make sure you get the polarity the right way round.

And there is no issue doing what you've suggested, while the Arduino is also plugged into the usb slot on my laptop?

Never had a problem. Check the schematic, I believe you will find a diode between the 5V from the USB connection and the 5V pin.

If you want your analogue measurements to be independent of the 5V supply, you can use an internal reference.

I didn't know this existed, great suggestion.

To confirm I've understood the manual correctly, I can add analogReference(EXTERNAL); to my code, give that a 5v input voltage from a phone charger without an inline resistor, connect the ground side of the phone charger cable to the Arduino GND pin and continue with my project?

I don't really understand what you mean. If you want to use an external ref voltage, you must connect this voltage to the Vref pin - and it should be independent from and more stable than your power source of the Arduino.
I would recommend to use the internal reference and adjust the measuring voltage by a voltage divider if needed.

I don't think Vref can (safely) be higher than Vcc.
If you don't measure anything > 4.4V, you could probably simply replace the 5.0 in

float voltage = sensorValue * (5.0 / 1023.0);

with 4.4 .

Ok, so if that's the case I'll stick with the barrel jack if I can use that while still connected to my laptop via usb. That's a good idea ZX80, however I have a bench test rig set up and would like to verify with the full voltage range.

According to this post it is not safe to power the Arduino externally while connected via a serial cable, unless you cut the power wire in the usb cable?

Then you could use a 10K/10K voltage divider with

analogReference(INTERNAL2V56); // and if I am not wrong
float voltage = sensorValue * 0.005;
1 Like

Using ANY supply as a reference voltage is a bad idea.
Because a load on the supply will change its value.

Here you will find a full and detailed explanation of good ways to measure all sorts of voltages.

as @ZX80 says,

As a start you can use the INTERNAL reference and a potential divider to scale your input to suit it.

1 Like

To clarify for my own understanding, do you mean to use the divider from the output of the sensor since the reference is 1/2 of 5v? This way it gets 1023 at 1/2 of 5v and my sensor now has a range of 0 to 2.5v with the divider? This assumes an external power source of 5v to the sensor correct?

For example you have 4 Volts from your sensor, divided by 2 by the voltage divider.
2/2.56 = 0.78125 //proportion of maximum analog reading
0.78125*1024 = 800 //ideally analogRead = 800
800*0.005 = 4 Volts

Ok, is the 0.005 actually 3 significant digits of this number 0.0048828125 . If not, where does that come from?

voltage = value * (2.56/1023) * ((R1 + R2)/R2)
voltage = value * (2.56/1023) * ((10k + 10K)/10K)
voltage = value * 0.002502444 * 2
voltage = value * 0.005
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.