The following circuit is what am using to make a volt meter using an arduino for my psu. It's a 30v psu hence I'll be measuring up to 30v. I don't know why I keep getting random values on the ADC. One minute it's 245 next it's 1024 then it's 0 for some time. Just jumps all over the place. I was told I would only need to supply 1mA to the analogue pin.

Avcc and vcc all decoupled to gnd using 0.1uf non polarised cap.

Here's the sketch code I am using to read the value of the adc

 ![void setup()
{
// begin the serial communication
Serial.begin(19200);
}

int analogValue = 0;

void loop()
{

// print as an ASCII-encoded decimal
Serial.print(analogValue);

// print a terminal newline character so the AVR Voltmeter
// will know that it has received the full string
Serial.print('\n');

// delay 1 second before the next reading:
delay(1000);
}][1]


• Could you post a schematic of your circuit please? – Oli Glaser Nov 26 '11 at 22:05
• Maybe try starting with a potentiometer across the arduino's 5v supply to make an adjustable voltage divider and see if you can get a stable reading from that, then go back to your higher voltage externals supply and its divider. – Chris Stratton Dec 28 '11 at 2:04

A few thoughts:

I'm assuming the PSU is DC within the range of 0V - 30V. (i.e no negative or AC voltages)

I don't know much about Arduinos, but do you have to set the pin to an analogue input? (e.g. like you would have to an a PIC) I'm thinking maybe the analogRead routine takes care of it. Also is the ADC reference voltage set correctly? (I notice there is a Aref pin floating on your schematic)

EDIT - Aref pin:

Atmel say:

The reference voltage for the ADC (VREF ) indicates the conversion range for the ADC. Single ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be selected as either AVCC , internal 2.56V reference, or external AREF pin. AVCC is connected to the ADC through a passive switch. The internal 2.56V reference is generated from the internal bandgap reference (VBG) through an internal amplifier. In either case, the external AREF pin is directly connected to the ADC, and the reference voltage can be made more immune to noise by connecting a capacitor between the AREF pin and ground. VREF can also be measured at the AREF pin with a high impedant voltmeter. Note that VREF is a high impedant source, and only a capacitive load should be connected in a system. If the user has a fixed voltage source connected to the AREF pin, the user may not use the other reference voltage options in the application, as they will be shorted to the external voltage. If no external voltage is applied to the AREF pin, the user may switch between AVCC and 2.56V as reference selection. The first ADC conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result.

So if the external reference is selected you need to apply a voltage to it. From your comment below it looks like this may be the case. Try connecting it to AVcc (or whatever you want the top of the ADC range to be)
You can optionally add a 100nF cap to ground to reduce noise if necessary also.

Is your 5V supply stable? Have you got bypass caps present? (mentioned but not acutally shown on schematic)

Is your PSU sharing ground with the Arduino? If not this could cause the issues you are seeing.

• well It was feed by the arduino. It's a self built arduino. Should it be wired to gnd then aref? I wasn't sure. From what I read thats to set the analogue reference as the internal reference is subject to temperature changes. That's what I've been told anyway. Yeah I do have bypass across vcc and avcc. Also bypass on the 7805 feeding my arduino. By the way am not wanting super accuracy. Just an idea of what the voltage is so i don't blow anything up – Ageis Nov 27 '11 at 11:06
• @Ageis - it might have been a good idea to mention it's a self built Arduino ;-) See edited answer, let me know how it goes. – Oli Glaser Nov 27 '11 at 13:18
• Grounds need to be shared. Maybe you should try running 4x the analogRead(0) function before taking a result. The ADC buffer in Atmel chips take some samples to stabilize. Also, you may want to execute the analogReference method in your setup function (explicit definitions are good when troubleshooting). You may want to try connecting the AREF pin to AVCC and putting your reference to EXTERNAL. If none of this helps, we'll see further. :-) – Hans Dec 28 '11 at 15:26

You do know don't you that the input pins on the Arduino are not rated for 30 volts? I hope you are not directly applying 30 volts. If you have, you may have destroyed the ADC and this would account for bad/random values.

Before attempting to measure your PSU, why not simply test the Arduino's ADC with a known, stable source like a 1.5V battery?

• yes I'm aware of that which is why I have a voltage divider in the circuit feeding off 24v. Sorry the picture didn't upload for some reason I did have a schematic. Ok I try a brand new virgin chip I have and see what happens – Ageis Nov 26 '11 at 23:32
• Try measuring a 1.5V battery first, that way you are sure that you don't zap the chip by accident. – JonnyBoats Nov 27 '11 at 0:47