Just a simple voltage reader

Hi everybody!

I'm stuck on a really simple thing but you have maybe a response...
I want to read voltage from external power supply greater than 5V (it's a 12V DC transformer). I use a voltage divider to get voltage between 0-5v (with 4 1K resistors). With my multimeter the value is stable in entry (2.80V approximatively after 3 first resistors for 11.80V in DC input).

But the value from A0 analog input fluctuate from 0 to 900 without interruption (via intermediate values). I don't know why? Wrong signal from DC transfomer ? My arduino uno is powered by USB.

PS: I added the schema as an attachment

Thanks in advance for your help.

There is either something wrong with your "DC transformer" or with one or both of your connections to the Arduino or with the code that you did not show us.

By the way, your "DC transformer" is actually a "DC power supply". DC and transformers do not go well together.

You may have a rectified but unfiltered, pulsating DC, what is your ADC sampling rate?

Hi!

Thanks for your responses.
My DC power supply is battery charger for motorcycle (see linked picture). The final power supply of my project will be realized by a car battery. Will these disruptions also occur? Do I have a way to filter that?

And the code to test is really simple :

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

void loop() {
  int numericInput = analogRead(A0);
  Serial.println(numericInput);
  delay(100);
}

Thanks!

Will these disruptions also occur?

Yes. No, wait, no.

What disruptions are you talking about?

Are you measuring the voltage WITH batteries attached or WITHOUT?

Chargers for batteries can have something called a "trickle charger" (Don't know the real english word for it though, could be wrong). What this basicaly means is that the output voltage will sometimes drop to reactivate the battery for a short time, then charging it again. Cheap chargers can throw some issues in the mix when badly designed.

Also, if you really want to charge a 12V battery you need more than 12V, usually with 14.2V or 14.4V depending on the battery.

Hi,
Your battery charger is just that, a rectified AC supply.

No smoothing to give you pure DC, your DMM is averaging the pulsed DC from the charger.

You have 2.80V measured by the DMM.

This results in peak of 2.8 x 1.141 = 3.95V peak.

(3.95/5.0) * 1023 = 808 analog count.

So 0 to 900 count is sampling the pulsed DC.

What do you want to use the charger for?

Tom... :slight_smile:

C-F-K:
Chargers for batteries can have something called a "trickle charger" (Don't know the real english word for it though, could be wrong). What this basicaly means is that the output voltage will sometimes drop to reactivate the battery for a short time, then charging it again.

In other words: your sketch is quite possibly working perfectly fine. The issue is that you are mistaken about what to expect. Try attaching your thingumajig to an oscilloscope rather than a multimeter.

Try removing the charger and replacing it with a car battery. Do things settle down then?

Indeed!

I changed to another power supply (9v) and I no longer have any fluctuation ...
I used this charger as a power source but this is not something clean.

Thank you for your answers.

Chargers for batteries can have something called a "trickle charger" (Don't know the real english word for it though, could be wrong).

Sure you do, since you used it.