# Understanding external voltage reference for a LVC with attiny

Hi, I have been looking for a way to monitor a battery's voltage while it's being used in a project with arduino. Ideally, I'd shut my projects down when they hit a desired low voltage (LVC).

I would like to use attiny85. If I understand correctly, using analogReference() changes how all my analog input pins read 0 to 1023, 1023 being the reference voltage rather than VCC? (ex: my chip is powered at 4.5v and my refence is 1.1v, if I feed 2v an analog pin and read it, it will return 1023?)

If this is true, this is great for measuring remaining voltage in a battery with a voltage divider, but it messes with how I can use all my other analog pins in my projects! In that case, I'd prefer using an external circuit that can make sure I'm not referencing VCC to my analog pin so I can have a real idea of voltage left in my battery. Is there such a circuit or a link to how to build one? I have been searching online without success.

so to make it clear, my 2 questions are: Do I understand correctly how aref works (paragraph 1) and Is there a way to build an external circuit to feed to an analog pin that can return different values depending on voltage left in the battery powering the same arduino/attiny85. (since using a voltage divider between battery + and ground into the analog pin would be useless and always return the same voltage division)

Thanks people!! (note that I do not have any code or schematic because I am not sure yet how this would be feasible. I have found a lot of sketches using aref but I believe an external circuit would be cooler, if such a thing exists)

I think that you understood ADC operation and AREF.

If you use the 1.1V reference and a voltage divider, you can measure the battery voltage.

Eventually you also have use for the brownout detector (BOD)?

DrDiettrich:
I think that you understood ADC operation and AREF.

If you use the 1.1V reference and a voltage divider, you can measure the battery voltage.

Eventually you also have use for the brownout detector (BOD)?

Yes, but I would leave it at 2.7 v. And if I build that voltage divider and use aref, will it mess with all my analogreadings in my projects? Should I keep switching from default and 1.1v ref like described in this post? http://forum.arduino.cc/index.php?topic=22922.0

Switching between the internal reference and Vcc as reference is an appropriate solution.

Be sure to discard the first analogRead() result after changing the reference - as noted in the datasheet, this first reading may be inaccurate.

DrAzzy:
Switching between the internal reference and Vcc as reference is an appropriate solution.

Be sure to discard the first analogRead() result after changing the reference - as noted in the datasheet, this first reading may be inaccurate.

Thanks, yes I will make sure I do! And afterwards, I want to shut the microcontroller off (not sleep) automatically whrn it hits the lvc. I am looking for an good shut down circuit

Can a p channel mosfet connected between vcc and load remain ON jntil I send a HiGH signal to its gate, turning it off and cutting current to the microcontroller?