Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
For accuracy there is no substitute for an ADC. If you have two spare digital pins you could consider adding an external I2C one.
If you want simplicity but not accuracy, you can do it by timing how long it takes to charge a capacitor from the battery voltage. It will be subject to the tolerance of the components, especially the capacitor and the exact logic threshold of the digital pin but it will give a rough idea of the voltage:
Connect the battery voltage through a resistor so it charges a capacitor, I would suggest aiming for a time constant of about 200mS up to 1 second and keeping the resistor > 10K. Connect the digital pin from the junction of the R and C and start the program with the pin driven low. This should keep the voltage across the capacitor close to zero volts. When you want to take the measurement, change the pin to an input and start a timer. When it goes to logic 1 state, stop the timer and immediately drive the pin low again to prevent it going over-voltage. The timer value will be proportional to the current that charged the capacitor and therefore the voltage providing the current. You will have to do the math to work out the voltage according to the values you used. For safety, add a low value resistor in series with the digital pin (~100 Ohms) to limit the discharge current when you drive the pin low after the measurement.
Brian.
A comparator is the default choice in these cases, but if you do not need more than one, you might want to consider doing that with a precision shunt regulator (e.g TL431), few components needed.
A comparator would provide only a single set-point which could be monitored. I assume OP wants to linearly measure
My intention is to monitor battery voltage at any given point of time. Voltage of battery falls in between [6v - 8.4v]. Accuracy is not a concern.
It's not clear how a regulator can help with this ? Could you explain the scheme ?
For accuracy there is no substitute for an ADC. If you have two spare digital pins you could consider adding an external I2C one.
If you want simplicity but not accuracy, you can do it by timing how long it takes to charge a capacitor from the battery voltage. It will be subject to the tolerance of the components, especially the capacitor and the exact logic threshold of the digital pin but it will give a rough idea of the voltage:
Connect the battery voltage through a resistor so it charges a capacitor, I would suggest aiming for a time constant of about 200mS up to 1 second and keeping the resistor > 10K. Connect the digital pin from the junction of the R and C and start the program with the pin driven low. This should keep the voltage across the capacitor close to zero volts. When you want to take the measurement, change the pin to an input and start a timer. When it goes to logic 1 state, stop the timer and immediately drive the pin low again to prevent it going over-voltage. The timer value will be proportional to the current that charged the capacitor and therefore the voltage providing the current. You will have to do the math to work out the voltage according to the values you used. For safety, add a low value resistor in series with the digital pin (~100 Ohms) to limit the discharge current when you drive the pin low after the measurement.
Brian.