Fluctuations in Volt meter using Arduino UNO

Hey,

I am currently trying to measure the voltage over a set of resistors using an Arduino Uno board. The external power supply is an old laptop charger of 20V and 2.31A. This is hooked up to a SICK laser sensor which needs power between 12-30VDC. It outputs a signal between 4-20 mA, from which I can calculate the distance measured. Since Arduino can not measure mA, I have configured it this way so that I can measure the voltage over the resistors (100 Ohm and 150 Ohm in series) and use that as an input for my calculations. The multimeter shows values between 0-5V which is what is needed for the A0 input pin on the Arduino board.

In my measurements, I see fluctuations of +/- 0.6V on my serial monitor. How is this possible and how can I reduce these fluctuations?

I use this code to measure my voltages:

int analogPin = A0; //
float val = 0;  // variable to store the value read
float volt = 0;

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

void loop() {
  val = analogRead(A0); // read the analog input pin A0
  volt = (val*5)/1023;
  delay(2000);          // debug value
}

Thanks in advance!

Moved to Project Guidance.

The UNO GND needs to be connected to the power supply ground (negative).

2 Likes

Bring up an ascilloscope and check the 5 volt pin for variations. That 5 volt is the reference for the ADC converter.

1 Like

Thanks! This reduced a lot of the fluctuations. However, still, fluctuations of +/- 0.2V are present. I will try to hook up a multimeter to check the fluctuations of the reference voltage.

I will try. Thanks.

A battery charger does not make a good clean power source.
You need a good clean benchtop type supply.

The voltage difference between the 5V-pin and the Ground fluctuates from 5.070-5.073V hence it is pretty constant. Have you got any idea where the large fluctuations in my Arduino readings could possibly come from?

if you need precise measurement, you need external 5V reference for the ADC. Btw, you could also connect 100nF from ADC in to gnd and do oversampling, for example:

    // oversampling (average of 20 samples)
    val= 0;
    for (int i = 0; i < 20; i++)
    {
      val+= analogRead(A0);
      delay(1);
    }
    val= val/ 20;
1 Like

Bad wiring = show the picture.
Add capacitor 100nF or 1uF on Arduino board, GND - A0.

Serial monitor is showing exactly what is on A0, fluctuations (regular changes ) suggest that they are come from 50/60 Hz power supply , not necessary by wire, 10 cm wire on A0 act as antenna and can pick up 50/50 Hz interferences.

The laptop battery set become the filter capacitor for the charger. The charger output is pulsed DC.

1 Like

Try powering it via the Vin with an appropriate voltage, that will help filter out some of the power supply noise you are experiencing.

I got hands on an professional 5VDC 3A source. Will try to hook this up tomorrow and see what this will change. Thanks all

The wires I use are 30cm. Maybe indeed this has something to do with that. I will try to get shorter wires.

But your LASER needs 12-30VDC

Sorry forgot to mention but I received next to the 5VDc a 24 VDC as well. With the 5VDC I will try to power the reference voltage as @noobmastha suggests.

show picture and serial plotter

on board reference voltage is not fluctuating, unless Arduino power supply is bad quality

Currently, I used this, which already gave reasonable values since it will take the average of 9600 measured values. However, I would like that each single measurement will be more precise.

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

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

void loop() {
  float volt = 0;
  for(int i = 0; i < 9600; i++) 
  {
    val = analogRead(A0);
    volt = volt + ((val*5.06)/1023)/9600; // read the 9600 times analog input pin A0 and take the average
  }
  Serial.print("V:");
  Serial.println(volt,4);
}

You should of course use the more stable internal 1.1volt reference of the Uno, not the default 5volt supply as reference.

Calculate your voltage divider for ~1volt, say 10k:27k.
Make sure that ground is not shared (Kelvin connections).
Add this to setup().
analogReference(INTERNAL);
Take up to 64 measurements, with a small delay in between (9600 is silly, and won't improve things).
+= them in an unsigned long (the A/D doesn't return a float).
Divide by a calculated factor into a float voltage.
Leo..

1 Like

I'm guessing you mean the arduino readings show fluctuations of +_0.2V but the "meter" does not.

Ideally you should look at the voltage with an oscilloscope to see what is REALLY happening.

This measures the analog input by comparison with the "5v" supply. So you could have noise on either or both.

As Leo says, use the "INTERNAL" reference of ABOUT 1.1V which while not accurate IS stable.
That will eliminate the effect of noise from the 5V supply. You will need to change the resistor value to say 51 ohms.

Most likely your noise is coming from the laser supply and is related to mains frequency so you should oversample at a rate that reduces that. So eg 16 samples with a 7ms delay.

That is explained here; also take notice of what it says about star points.

When you have the noise and sampling fixed you will need to calibrate the measured value by reference to your voltmeter.