Measuring voltage with an Arduino

I was wondering if I could measure battery voltage simply by hooking the battery's + to an analog Arduino pin so that my robot can know when it's low on power. From what i've understood, a battery of 1.5 volts is dead when it outputs 1.4 volts (gonna do some research about this). I guess I can apply this approximation to different voltages battery. The only problem is that, if I want to use a battery with voltage superior to 5v (Arduino analog pins set 5v as a maximum), how do I divide the voltage? Again, I guess I'll need op-amps to do that and voltage dividers, but what do I exactly do? And what reference should I use for the analog pins?

Thanks

Some suggestions:use Vcc as

Some suggestions:

  • use Vcc as reference
  • use a voltage divider with two resistors in series between power supply and ground, the center voltage is connected to Arduino ADC/analog pin
  • use large value resistors (maybe 100k) to prevent it from draining the battery fast
  • figure out your threshold where you can safely determine the battery is weak- look at the battery datasheet and find a plot of the drain curves to find the point where it starts to rapidly deplete
  • calculate resistor values that get you close to reference / 2, or half of Vcc if that is your reference