Help with voltmeter.

Hello all,

I have made a power supply with inbuilt ammeter voltmeter on an lcd, everything works fine it reads the volts perfectly according to my multimeter. The only problem is when i attach a load to it, I do not get much of a voltage drop and in some cases the voltage goes up, which is not true to my multimeter.
If it reads the volts perfectly it cannot be the code, so what is it that might be causing this? The arduino is also running off computer usb power.

Post your schematic and code. My gut says you are sensing the voltage output in the wrong spot or wrong manner.

I can’t put up a schematic cause the web site isn’t working properly right now, ill try later.

But its pretty simple, a potentiometer as a voltage divider out of the power supply which feeds into pin 3 on arduino. after the potentiometer a .5 ohm shunt resistor on the negative rail which goes into pin 4. I wish I could draw it but it won’t let me insert image, as i said will try again later. Anyhow here is the code. Im sure some of it needs cleaning up but im still working on it.

cheers

#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);

// These constants won’t change:
const int analogPin = A4; // pin that the sensor is attached to
const int ledPin = 6; // pin that the LED is attached to
int analoginput0 = 3; //analoge pin 3 voltage
int analoginput1 = 4; //analoge pin 4 Amps
float vout1 = 0.0;
float vout2 = 0.0;
int value1 = 0;
int value2 = 0;
//float R1 = 5100.0; // !! resistance of R1 !!
//float R2 = 2193.0; // !! resistance of R2 !!
float vin1 = 0;
float vin2 = 0;

void setup(){
lcd.begin (16,2);
lcd.setCursor (5,0);
lcd.print (“G’day”);
delay (1000);
lcd.setCursor (6,1);
lcd.print (“Mate”);
delay (2000);

// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);

// declaration of pin modes
pinMode(analoginput0, INPUT);
pinMode(analoginput1, INPUT);
lcd.begin(16, 2);

}

void loop(){
// read the value on analog input
value1 = analogRead(analoginput0); //voltage value
vout1 = (value1 * 4.62)/1023;
vin1 = vout1 * 3.597402597; //(R2/(R1+R2));

value2 = analogRead(analoginput1); //Amp output
vout2 = (value2 * 4.555)/1024.0; //4.555=voltage threshold (1023=4.555V);
vin2 = vout2*2; //vin2 = value2;

lcd.setCursor(12,0);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(vin1);
lcd.setCursor(8,1);
lcd.print(vin2);

lcd.setCursor(0,0);
lcd.print(“Volts”);

lcd.setCursor(0,1);
lcd.print(“Amps”);

// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, sound alarm:
// if (analogValue > threshold)

if (vin2 > 3.2) // Set amp alarm value
{
digitalWrite; //(ledPin, HIGH); //ledpin for led
tone(7, 3);
delay(100);
}
else{
digitalWrite(ledPin,LOW);
noTone(7);
}

delay(100);
}

please use the # button when posting code, it provide tags to put around the code making it look better.

Do the math in less steps, less rounding errors (and faster !)

Note: value 2 should be divided by 1023 not 1024 !!! Note: 1023 is the max value and 1024 is the number of steps.

value1 = analogRead(analoginput0);   //voltage value
  vout1 = (value1 * 4.62)/1023;
  vin1 =  vout1 * 3.597402597; //(R2/(R1+R2));
 
  value2 = analogRead(analoginput1);    //Amp output
  vout2 = (value2 * 4.555)/1024.0;    //4.555=voltage threshold (1023=4.555V);
  vin2 = vout2*2;  //vin2 = value2;

==>

vin1 = 0.016246334 * analogRead(analoginput0);      //voltage value
vin2 = 0.008905181 * analogRead(analoginput1);     //Amp output

I Solved the problem.

When connecting a load to the power supply, I was measuring the voltage across the load with a multimeter. The problem with doing this is the shunt resistor (in series with the circuit) for measuring amps. So effectively when you put a load on and take a measurement across the load, you are essentially taking a measurement across a voltage divider, because the load forms the second resistor in the circuit, hence the reason the voltage on the arduino lcd was reading higher. So when I connected the multimeter to the ground before the shunt, It was reading the same value as the lcd. So basicly the output negative rail has a .5 ohm resistor as opposed to the real ground which has no series resistance.

So essentially this was my stupidity but just in case someone else makes a similar project and the same mistake the knowledge is here.

cheers

If you know exactly the voltage drop across the .5 Ohm resistor, and know exactly the resistance of that resistor, you should be able to calculate the voltage drop and compensate for that when displaying the output value.