You'll want to use a voltage reference along with an ADC or analog comparator. Voltage references work kind of like an LDO voltage regulator; the difference is that they put out a very stable and accurate voltage (but very little current). The following circuit will do the job:

The two resistors will supply half the battery voltage to the comparator. The chosen voltage reference is 1.6 V (half of a LiPo's very low battery level of 3.2 V ). The comparator will output true if Vbat
1 drops below 3.2 V. Alternatively, one could use an ADC that allows a reference voltage as an input:

In this case the voltage reference is chosen to be over half the maximum battery voltage (2.5 V × 2 = 5.0 V). The output of the voltage divider is measured by the ADC using 2.5 V as the top of the measurement range. To get the actual voltage plug the ADC output value \$N\$ into the following:
$$
V_{bat} = { { 2 \times N \times V_{ref} } \over { 2^{resolution} - 1 } }
$$
The result is the measured battery voltage \$V_{bat}\$ in volts. \$V_{ref}\$ is the value of the voltage reference (in volts) and \$resolution\$ is the resolution of your ADC (in bits). Many popular microcontrollers and development boards have built-in ADCs with support for external voltage references (the Teensy 3.x and Feather M0 boards come to mind).
For either of the above you should choose a voltage reference that's appropriate for your power source. LiPo batteries, for example, typically max out at 4.2 V, spend most of their useful life at 3.7 V, and cut out completely at 3.0 V. Alkaline batteries, on the other hand, start out at 1.5 V then end their useful life around 1.15 V (IIRC). Your typical NiMH will start out at 1.3 V and dip to a tad under 1 V before they're unusable (again, IIRC).
I used LiPo batteries for the examples above; regardless of the battery technology you use you'll want to feed it to a 5 V regulator2 that can then power the rest of your circuit.
1 \$V_{bat}\$ is the raw battery voltage, not the output of your voltage regulator.
2 For LiPo batteries you'd use a boost regulator.