Measuring voltage

Hello,

I want to use my Arduino to measure the voltage of a (regulated) power supply to test the Arduino's accuracy (and my program). Can I simply connect the minus pin to an analog pin on the board and the plus to Arduino's GND? If so, would that impact the display and button I connected to the same GND pin? If it is of any relevance, the Arduino is powered via USB. Would that be safe? I'd love to try it myself, but as an electronics beginner I don't want to fry the chip or power supply.

Thanks a lot!

If you don't want to fry the chip (or anything generally speaking) don't connect a positive line to a GND (as you suggest below) as it will be a direct short.

This should be possible though but how you wire it will depend on the maximum output of your supply. What is it?

Also what are you planning on using to display the voltage? LCD / 7 segment / etc

The maximum output can be regulated and I wanted to test with voltages between 0V and 5V. I'm using a 16x2 LCD display with backlight, so it needs two connections to GND.

Can I simply connect the minus pin to an analog pin on the board and the plus to Arduino's GND?

The analog pins must never see a negative voltage.

So how would one connect that? I know now what not to do, but I can't find a simple way to bring all these things together. Where would I connect the positive/negative lines to? Would I need a resistor even if I only supply 0V-5V? Thanks!

The best information is in the micro-controler datasheet not in arduino website.. Have a look on it and you will see the you can not apply on a pin a voltage under -0.5V

If you are only going to be inputting a maximum of 5v then it should be safe to connect the output directly to the arduino’s analog pins (although a resistor between them wouldn’t hurt)

The pin (analog 0 in this example) can be read simply using this line of code …

int pinReading = analogRead(A0);

You then need to convert that to a voltage as the reading will be a number between 0 and 1023 depending on where the voltage is sat on the range of 0-5v. For accuracy it is best to use a float …

float voltage = pinReading * (5.0 / 1023.0)

You will then have a (hopefully) accurate reading of the voltage stored in the float “voltage” which you can then output to anything you want.

Have a look at either http://arduino.cc/en/Tutorial/ReadAnalogVoltage or Tutorial 04 for Arduino: Analog Inputs - YouTube for a more detailed explanation of analog inputs

thermalhound, that helped, thanks. My missing piece is now just how to connect the two power supply wires to the rest. It needs to have a closed circuit, so where would I connect the minus and plus poles? As you said, connecting the positive line to GND would short it, where would I connect it to instead? Linking it to the Arduino pin and the negative line to GND seems wrong too.

thermalhound: float voltage = pinReading * (5.0 / 1023.0)

The correct value is 1024.0.

Connect the minus output of the power supply to ground on the Arduino and the plus output to the analog input. To be safe, put a resistor (say 10 K ohms) between the plus power supply terminal and the analog input. In case of a mistake, the resistor will limit the current to a safe value.

The power supply that you are measuring should not be the power supply used for the Arduino, as the analog converter normally uses the Arduino power supply as the reference.