precision of analogread

Hello,
I'm constructing an electric skateboard, and I need to detect when the input voltage is above 45V (it goes up to 45.9V)
the voltage is normally between 42 and 44V, so my question is :
if I use a voltage divider bridge to bring the voltage between 0 and 5V, is an arduino is going to be precise enough to be reliable?
Thank you

Define "precise enough" and "reliable".

Using a 10:1 divider, voltage resolution on a standard 10 bit Arduino ADC is about 50 mV.

Well By reliable I mean I need the arduino to make no error about the voltage.

But if the precision is at 50mV, that good enough for me

Thx

I just tested it and the arduino uno just output random numbers. I use a 10k and 90k resistor, is it too much?

Which Arudino are you using? What code or you using (post your code)?

If you are using an UNO. disconnect EVERYTHING. Then connect the UNO to the PC and the 3.3V output to the analog input. That's it nothing else. 1 cable and one wire. Output the analog read to the serial monitor. Tell us what it reads now.

int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read

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

void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
delay(100);
}

I'm reading 670. Strangely the output is constant. But on my test, the output can vary to up to 300

In my opinion, you can get close to 9 bits, that is 100mV precision when measuring 50V with a good reference voltage (overall absolute accuracy by guessing :slight_smile: ).
Without a good reference voltage, you need to tune things in software and when the temperature does not change too much, then 200mV or 300mV precision should be possible.

10k and 100k is perfect, even 22k and 220k is perfect.
I prefer 100k instead of 90k. If the battery is 52 Volts, then you know something is wrong.
Could you try with two real resistors ? That is safer than a potentiometer.

When you use the 3.3V voltage regulator output as reference voltage, then the range for the analog inputs is 0...3.3V.
When you use an external voltage reference, do not call analogRead() before analogReference(), read the warning.

With the 3.3V as reference, you could try a voltage divider with 10k and 180k for a voltage up to 60V.

I often use the internal reference voltage (1.0 to 1.2V for an Arduino Uno) when the Arduino is always at room temperature and when it has always 5.0V (not powered with just a USB cable).

Use the average of 5 to 100 samples. That helps a lot.

Koepel:
adwsystems tells to use the 3.3V voltage regulator output as reference voltage.
When you use an external voltage reference, do not call analogRead() before analogReference(), read the warning.

With the 3.3V as reference, you could try a voltage divider with 10k and 180k for a voltage up to 60V.

@Koepel, I'm sorry but please re-read and edit your post. I did not say that.

The use of the 3.3V output is to test the code and board. The test was successful, it should read 670 give-or-take. Now we can rule out those things out and look at @DryDemon circuit for the source of the problem.

With a voltage divider, the variation will be reduce by the divider ratio, so it should (theoretically) be quiter not noisier.

actually the output is from a transformer which is connected to my batteries. And I have a bms so no need to check for 52V.
The real problem is that the transformer block the power generated by my motors when I brake, which makes the breaking impossible.
But I bought 2 DTDP relays, so the goal is to check when I'm breaking to connect the motors dirrectly to the batteries, and then connect the motors back on the transformer

(When I'm breaking, the voltage goes up to 45.9V, so I just need to check the voltage to know if I'm breaking)

I need to use the aref pin?

adwsystems:
@Koepel, I'm sorry but please re-read and edit your post. I did not say that.

Oops, sorry :-[ I should go back to kindergarten to learn to read. I have changed it.

DryDemon:
I need to use the aref pin?

I don't know how reliable your 5V is. Is this with freezing temperatures in the winter and high temperatures in the summer ?

A common problem is when the 5V is used a default reference and the Arduino is powered via a USB cable. Then the voltage could change, for example, between 4.2V and 5.5V. Multiply that 10 times, and that will be accuracy for the 50V range.

Well the temperature is supposed to go from 0°C to 30.
And the arduino is supposed to be powered on batteries, and the voltage won't be constant but will be in the 5->12V range.
But Does that has something to do with my problem?

And is the divider is too noisy, is there any other component that could read the tension?

Koepel:
Oops, sorry :-[ I should go back to kindergarten to learn to read. I have changed it.

@Koepel, No problem. I just didn't want the OP getting the purpose and terms crossed up. If you think the 3.3V AREF would be better. We can pursue that route. Though the reading may be inaccurate with the 5V AREF, it would cause the noise described (would it?).

The 1.1V built-in reference is very stable, and is usually the best bet for a project like this. Use a 10k + 470k resistor combo for 1:47, keeps it comfortably within that range. Resolution doesn't suffer. The higher resistance means less heating in the resistors (which quickly becomes an issue at these high voltages).

I do wonder: would it be possible to have 40V as zero point, so you basically measure only the top 6V or so. Voltages <40V or so are not interesting here. That would seriously increase the resolution. E.g. by using a zener, or something a bit more stable, and connect that point to the Arduino ground instead of the battery's negative pole.

I forgot to connect the arduino ground to my measuring ground. So that corrected the problem

And yeah measuring the top 6V is a great idea. Thx