6
\$\begingroup\$

I'm using an ATTINY85 for a portable application that uses a Lithium-ion battery; therefor I need to monitor the battery voltage so I don't kill the battery. Is there a way to go about this without using another pin? or using the reset pin? **NOTE: assume that there will be no regulated voltage such as 3.3V or the like. (this is because the circuit only uses one battery and should never go above spec; and saves on cost)

\$\endgroup\$
  • \$\begingroup\$ The voltage regulation is not an issue since there is an internal voltage reference. You do have to have one of the ADC pins available (Reset is one of them). Using the reset pin as an ADC pin could cause some problems programming the firmware though. \$\endgroup\$ – Mike Feb 16 '15 at 17:59
  • \$\begingroup\$ I've read if I disable it I'll have to use a HVL programmer to program it. \$\endgroup\$ – Sam W Feb 16 '15 at 18:13
16
\$\begingroup\$

Setting REFS[2:0] to 0bX00 will use VCC as the voltage reference, and setting MUX[3:0] to 0b1100 will use the internal bandgap voltage as the voltage to measure (see §17.13 from the datasheet). From there, the full range of 1023 will tell you what VCC is in relation to the bandgap voltage. So take (1.1*10*1023=) 11253 (or an appropriately scaled equivalent) and divide it by the measured value in order to get the approximate value of VCC in tenths of volts.

\$\endgroup\$
4
\$\begingroup\$

Yes you can. I made a library https://github.com/cano64/ArduinoSystemStatus it also works with ATTiny85. In addition to measuring a voltage on VCC pin, with this library you can measure voltage on any analog pin (without need for regulated VCC), get free RAM, go to sleep and wake up after button press and more...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.