Analog Voltage Reader

I'm sure this is a really simple answer but I'm completely forgetting it as I haven't worked on my Arduino in a month. What would the code be if I wanted one of my analog inputs read a voltage coming in. Not from a sensor or anything, just a voltage. It's going to be the voltage from my power supply so my robot will alert me when it's running out of battery. Any help would be great!
Thanks! :slight_smile:

Here is the key lines of code that you will need:

temp = analogRead(in_pin);
val =(float)temp * .0049 ;// val needs to be a float

There is 1023 steps when you analog read, every step is .0049 volts.
If your power supply will give more then 5 volts, you should divide the voltage with resistors(Voltage divider - Wikipedia).
If you divide your voltage in 3 or 2, you should multiply val by 3 or 2.

Hope I helped.