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);
}
// variable to hold the analog input value
int analogValue = 0;
void loop()
{
// read the analog input on pin 0
analogValue = analogRead(0);
// 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]
Best Answer
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:
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.