12V DC measuring with Arduino

Hi,
i have a problem with measuring 12V DC. I haven't found answer at any other forum, so I hope you will help me.

I have connected switched-mode power supply 15V/1A with parallel catalytic 22uF and foil capacitor 330n then 7812 in order to decrease voltage to stable 12V and stabilize signal with catalytic 10uF and foil 100n. The voltage measured by multimeter is 11.72V which is okay for me.

Anyway when I measure it with analog pin (a0-a5) of Arduino uno (and 2 other plates similar to it) of course via voltage divider (10k and 20k, 47k and 68k) readings are between 0 and 5V (varying without any reason).

The same situation occurs when applying 9V DC from a battery.

I think it's not because of the supply, but there might be some problems with arudino, however, should I apply anything to my loop? Or connect any different pin to Arduino, such as reference pin or sth?

Thank you in advance!
Regards,
Adam


About schematic: Resistor after diode is 100Ohms to measure voltage drop (current), voltage divider is made of resistor 47k and 68k that should give numbers between 0 and 4,9V (fine for Arduino), potentiometer is 5k, capacitors as written earlier.

Simplified code (just to measure voltage at output from potentiometer to check if it is working):

int voltageSensorPin = A0;
int voltageSensorValue = 0;

float resistor1 = 68000;
float resistor2 = 47000;
float voltageOUT = 0.0;
float voltageIN = 0.0;

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

void loop() {
  voltageSensorValue = analogRead(voltageSensorPin);
  voltageOUT = voltageSensorValue * 5.0 / 1024.0;
  voltageIN = voltageOUT * (resistor1 + resistor2) / resistor2;
  Serial.println(voltageIN);
  delay(1000);
}

Hello adamrobot3456

Welcome to the world's best Arduino forum ever.

Post your sketch, well formated, with well-tempered comments and in so called code tags and schematic to see how we can help.

Have a nice day and enjoy coding in C++.

3 Likes

What does that mean? If you've made a 30K & 115K voltage divider it should be OK.

You need a common ground between the Arduino and the voltage you're measuring. The Arduino measures relative to it's ground. I'd guess you're missing the connection so there's no reference and the input is "floating" relative to Arduino ground.

When troubleshooting, it's a good idea to simplify things and just check the raw ADC reading. There could be an error in your voltage calculation (although if the reading is stable the voltage calculation will also be stable).

1 Like

HAve you sen this?

1 Like

We need a schematic showing ALL the connections.

1 Like

Hello, thanks for reply, I've just added them :slight_smile: Have a nice day!

Well, if you would be so kind you can check, I've already added schematic and code; everything is fine when measuring voltages from Arduino or via potentiometer up to 5V, problems become when I plug in other power supply (with higher voltages).

When it comes to divider I just count it, when you use R1=to 68k and R2=47k the maximum voltage is 47/(47+68) *max Voltage, which for 12V would be around 4,9V
(same with 10k and 20k if max is 12V, max after divider will be 4,00V)

I don't have actually any connection between Arduino gnd and power supply. So shall I simply connect and pin with gnd on power supply (meaning after all "stabilizers")?

Other than sharing grounds, you should use the internal voltage reference for this kind of measurement. Use a voltage divider to bring down the voltage to <1.1V.
For accurate measurements, calibrate as there's quite a tolerance to this reference voltage, but it's very stable. The 5V Vcc against which you reference by default is not guaranteed stable, but can easily be 4.5V or so.

1 Like

Sure thing Mr. John, I've just added both code and schematic. I haven't noticed that tutorial beforehand, apologize for that.

Okay, but u mean that I should take this voltage out of my circuit (from power supply, not Arduino for instance 5V pin)?

All of the grounds should be connected together. I'm pretty sure that's the problem.

FYI - That's NOT a schematic. A schematic shows the electrical connections & "symbolic" components without regard to their physical arrangement or physical appearance.

For those of us with electronics experience, a schematic is a LOT easier to follow & understand. :wink:

It does create the possibility of the actual circuit not matching the schematic, but that can happen with your pictorial diagram too.

Which will require a different voltage divider and different calculation. ...And that's not the problem at the moment.

1 Like

Okay, i will check it out (your solution), thanks for reply
Sorry I'm beginner in it :wink: Is there any app to create schematics?

Okay, I checked it out and it seems to be working now!
Thanks a lot!!!

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