Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.
Supplier photo
Temu affiliate offer · Project idea

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

ATtiny85 Battery Check: The Divider Can Use More Current Than Sleep

A sleeping microcontroller can be quiet while the resistor divider beside it consumes current all day. Build a press-to-measure battery checker around an ATtiny85-20PU, then compare two dividers with the same voltage ratio and tenfold different resistance. The useful result is a current budget and a qualified measurement, not a percentage of battery life guessed from one voltage.

This is a bare eight-pin microcontroller experiment, not a development board with hidden power LEDs and regulators. We use the eight-lead plastic dual in-line package (PDIP8), verified internal1MHz central processing unit (CPU) clock, and a controllable2.7–5.0V bench supply. An optional three-AA pack comes later. AVR names this microcontroller architecture family; C is the programming language. An analog-to-digital converter (ADC) turns its input voltage into a numerical code. The complete AVR C program sleeps between button presses, uses the internal nominal1.1V reference, reports the raw converter code through a light-emitting diode (LED), and refuses voltage classes until you enter a real per-unit calibration.

Verification: actual portable C helpers were built and run on the host; separate nominal divider/resistor-capacitor (RC) calculations were checked. The AVR target compiler is not installed here, so no physical assembly, ATtiny execution or target firmware binary is claimed. The blank worksheet contains no invented current, accuracy or battery results.

Freeze the part, resistors and permitted supply

The specified Microchip/Atmel ATtiny85-20PU is the2.7–5.5V industrial grade in8P3 PDIP. An ATtiny85V-10PU is a different ordering option. The product family’s general1.8V headline does not change the minimum of our exact part. Our narrower experiment range is2.7–5.0V, at1MHz. Software cannot keep this part within its operating range after the supply has already fallen too low; the checker is not a battery-protection cutoff.

  • ATtiny85-20PU PDIP8, socket or breadboard; an ISP programmer that supports the chosen target voltage and a verified ground connection. ISP means in-system programming.
  • Vishay BCcomponents MRS25,1%,±50ppm/K axial resistors: MRS25000C4703FCT00470kΩ and MRS25000C1003FCT00100kΩ. Comparison pair: MRS25000C4702FCT0047kΩ and MRS25000C1002FCT0010kΩ.
  • One10kΩ RESET pullup, one1kΩ LED resistor, a red LED, a normally open button,100nF ceramic supply bypass and100nF ceramic divider capacitor, rated at least10V. MRS25 equivalents for the small resistors are1002 and1001 resistance fields.
  • A regulated, current-limited bench supply, direct-current (DC) voltmeter and a current instrument with known burden voltage. A three-cell holder with three Energizer E91 primary AA alkalines is optional after the controlled tests; no charging circuit is included.

The MRS25 ordering field encodes three significant digits and a decimal multiplier:4703 is470×10³Ω. CT is a packaging code for5000 taped pieces fan-folded in a box, not a different resistance. These codes freeze a documented1% family; do not assume colour bands, a marketplace title or a similar suffix prove a loose part’s tolerance. Measure and record the actual pair used. Datasheet dissipation is0.6W at70°C with derating; our microampere divider does not need that power rating to establish accuracy.

Both the chip and divider share one switched supply

VCC labels the chip’s positive supply and GND its ground return. PB0–PB5 are port-B general-purpose input/output (GPIO) pins; their alternate functions depend on the selected peripheral.

ATtiny85-20PU PDIP8: one switched 2.7–5.0 V rail powers pin8 and the 470 kΩ/100 kΩ divider; ADC2/PB4 pin3 has a 100 nF filter. RESET pin1 has a 10 kΩ pull-up; PB3 pin2 has a button to ground and an internal pull-up; PB0 pin5 drives an LED through 1 kΩ. Pin4 and the 100 nF supply bypass return to common ground.
Original pin-level functional schematic. The chip and divider share one switched rail; button, LED, reset pull-up and supply bypass are shown. Disconnect the programmer before operation. Open full-size schematic
Physical pin Connection and purpose
8 VCC;4 GND Switched positive supply and common0V. Fit100nF directly across the chip supply pins.
3 PB4/ADC2 470k top resistor from switched positive;100k bottom resistor and100nF to ground. No digital pullup.
1 PB5/RESET 10k pullup to switched positive. Keep RESET enabled for ISP.
2 PB3/PCINT3 Button to ground; firmware enables its internal pullup. A pin-change interrupt wakes the CPU.
5 PB0/MOSI/AREF 1k → LED anode; LED cathode to ground. Internal1.1V selection leaves this pin free for digital output.
6 PB1/MISO;7 PB2/SCK Unused during this experiment and driven low by the application. They are programmer signals while RESET is asserted.

VCC is the chip’s positive supply; an ADC is an analog-to-digital converter. The capacitor across the lower resistor holds the sensing node between converter acquisitions and filters changes. It also creates a settling delay. Both divider and chip turn off together: never leave a powered divider feeding the input of an unpowered microcontroller.

Disconnect the LED branch during ISP if it loads MOSI, and disconnect the experimental supply before allowing a programmer to supply target power. Select exactly one supply source. Verify programmer voltage and clock rate; at1MHz target clock, keep the serial-programming clock within the datasheet limit, for example125kHz or slower. No fuse-writing command is supplied: read and record oscillator selection, CKDIV8, RESET/debugWIRE and brownout settings first. The operating preconditions are the internal8MHz source with CKDIV8, CKOUT (clock output) disabled so PB4 remains an analog input, WDTON unprogrammed so the watchdog timer can be disabled, RESET enabled and debugWIRE off. Brownout detection (BOD) must be compatible with the chosen supply sweep; if its threshold holds the chip in reset near the low endpoint, raise and record that endpoint rather than silently changing protection fuses.

The reference trap: a changing battery can produce constant codes

The divider ratio is k=100/(470+100)=0.1754386, so its ideal node voltage is k×Vpack. For an ideal ten-bit ADC, the usual scale model is code≈1024×Vnode/Vref, bounded by codes0–1023. If Vref is the same battery powering that divider, Vpack cancels: code≈1024×k≈179.65 at2.7,3.3 or4.5V. A nearly steady code can therefore be the expected result of the wrong reference choice.

We select the internal nominal1.1V reference instead. Now the ideal code changes with battery voltage. At5.0V the node is approximately0.8772V, below even the document’s1.0V reference guideline. An approximate inverse is Vpack≈code×Vref/1024/k; this displayed equation is a scale model, not an assertion that every real ADC transition lies at that lower-bin value. Offset, quantization, reference tolerance and divider error remain.

The internal reference is not a calibrated1.100000V source. The complete datasheet lists1.0/1.1/1.2V guideline values, and we deliberately do not convert its general ten-bit headline into a guaranteed accuracy claim at this high source impedance and different test conditions. A real reference/gain calibration is needed before the LED’s voltage classes are meaningful.

Tenfold less divider current has a cost

Calculated divider currents at 4.5 V are 7.895 µA for 470 kΩ/100 kΩ and 78.947 µA for 47 kΩ/10 kΩ. Normalized ideal external RC step responses have time constants 8.246 ms and 0.8246 ms; they do not establish ADC accuracy or whole-unit current.
Original nominal current bars and external RC curves. No sleep current or physical settling accuracy has been measured. Open full-size comparison

At4.5V the high pair draws 4.5/570k≈7.895µA continuously, about0.1895mAh each day if that voltage remained fixed. The low pair draws78.95µA, about1.895mAh/day under that same idealized condition. Neither number includes the chip, button pullup, brownout detector, LED, leakage or battery self-discharge. Dividing a nominal cell-capacity number by these currents would conceal discharge-rate and cutoff assumptions.

The divider’s Thevenin resistance, its effective small-signal source resistance, is Rth=Rtop×Rbottom/(Rtop+Rbottom):82.46kΩ for the high pair and8.246kΩ for the low pair. The datasheet recommends approximately10kΩ or lower source impedance for ADC use. The high pair deliberately exceeds that guidance; the capacitor helps supply acquisition charge but does not remove leakage, switch dynamics or every accuracy limitation.

With100nF, the nominal external RC time constant is8.246ms for the high pair and0.8246ms for the low pair. The100ms software allowance is more than twelve high-pair time constants in a simple unloaded first-order model. It is not a proof of ten-bit settling after the ADC’s switches/reference are included. Sweep the allowance and compare the lower-impedance pair at each supply point before qualifying this design.

Leakage matters even after waiting forever. A hypothetical1µA disturbance at the high-pair node causes about82.46mV of node error, corresponding to470mV at the inferred battery. The DC pin table lists up to1µA under its stated rail-level tests; this calculation is a sensitivity example, not a guaranteed worst-case error bound at every analog voltage. Board contamination and a connected meter can add another load. A10MΩ meter across the bottom resistor changes the high divider ratio by roughly0.82%; measuring the battery for calibration avoids that particular node-loading error.

Complete firmware, explicit unknown state

The code assumes a verified internal8MHz oscillator divided by eight, giving1MHz CPU clock. F_CPU describes that clock to the compiler; it does not program a fuse or change hardware by itself. Reference selection is REFS2:REFS1:REFS0=010; MUX=0010 selects single-ended ADC2. A divide-by-eight ADC clock gives125kHz. The routine allows100ms, discards the first conversion, averages eight subsequent useful codes, then disables the ADC and its peripheral clock before sleeping.

Raw zero, any clipped/full-scale sample, and a conversion timeout reject the whole average. That cannot diagnose every open wire or floating input; a plausible bad voltage can still pass. A finite polling limit keeps a stuck conversion from waiting forever, but only a real target run can establish register behavior and timing.

The LED first sends a one-second start pulse and one-second gap, then ten bits most significant first: short250ms pulse means0; long750ms means1; each is followed by500ms off. Record the frame on video if necessary. After1.5seconds off, a separate group of short pulses reports the class:1 uncalibrated,2 invalid,3 outside the declared supply range,4 below3.4V,5 from3.4 to below4.2V,6 at least4.2V. An ADC timeout has no raw frame and reports2. These thresholds are laboratory labels, not chemistry-specific state of charge.

Download complete AVR C (ZIP; file: batch-005/code/attiny-battery-divider-budget.c) · Blank calibration/current worksheet (ZIP; file: batch-005/code/attiny-battery-divider-budget-observations-blank.csv)

/* ATtiny85-20PU PDIP8; bare AVR C; internal1MHz clock must be verified.
 * Build target example: avr-gcc -mmcu=attiny85 -DF_CPU=1000000UL -Os
 *   -ffunction-sections -fdata-sections -Wl,--gc-sections file.c -o battery.elf
 * This publication has NOT compiled that AVR target or run the hardware.
 */
#include <stdint.h>
#define ADC_FAULT 65535u
/* Set only from a real per-unit calibration. Zero refuses voltage classes. */
#ifndef CAL_UV_PER_COUNT
#define CAL_UV_PER_COUNT 0UL
#endif

enum Kind { UNCALIBRATED=1, INVALID_SAMPLE=2, OUTSIDE_SCOPE=3,
            BELOW_3400=4, FROM_3400_TO_4199=5, AT_LEAST_4200=6 };
typedef struct { uint8_t kind; uint16_t millivolts; } Result;

/* Portable helpers below are the same ones called by the AVR application. */
uint16_t mean8(uint16_t (*next)(void)) {
    uint16_t sum=0;
    for (uint8_t i=0;i<8;i++) {
        uint16_t n=next();
        if (n==0 || n>=1023) return ADC_FAULT;
        sum+=n;
    }
    return (uint16_t)((sum+4u)/8u);
}
Result interpret(uint16_t raw, uint32_t uv_per_count) {
    Result r={INVALID_SAMPLE,0};
    if (raw==0 || raw>=1023) return r;
    r.kind=UNCALIBRATED;
    if (uv_per_count<4000UL || uv_per_count>8000UL) return r;
    r.millivolts=(uint16_t)(((uint32_t)raw*uv_per_count+500UL)/1000UL);
    r.kind=OUTSIDE_SCOPE;
    if (r.millivolts<2700 || r.millivolts>5000) return r;
    r.kind=r.millivolts<3400 ? BELOW_3400 :
           (r.millivolts<4200 ? FROM_3400_TO_4199 : AT_LEAST_4200);
    return r;
}
uint8_t raw_bit(uint16_t raw,uint8_t index) {
    return index<10 ? (uint8_t)((raw>>(9-index))&1u) : 0;
}

#ifndef HOST_TEST
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#if F_CPU != 1000000UL
#error "This timing/ADC setup requires verified1MHz CPU clock"
#endif
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <util/delay.h>
#define LED PB0
#define BUTTON PB3
ISR(PCINT0_vect) { /* Pin change wakes CPU; main rechecks the pin. */ }

static void on(void) { PORTB|=_BV(LED); }
static void off(void) { PORTB&=(uint8_t)~_BV(LED); }
static uint16_t conversion(void) {
    ADCSRA|=_BV(ADSC);
    uint16_t remaining=10000;
    while (ADCSRA&_BV(ADSC)) if (--remaining==0) return ADC_FAULT;
    return ADC; /* avr/io's ordered ADCL then ADCH access. */
}
static uint16_t sample(void) {
    PRR&=(uint8_t)~_BV(PRADC);
    ADMUX=_BV(REFS1)|2u; /* REFS2:1:0=010,1.1V; MUX=0010,ADC2. */
    ADCSRB=0;
    ADCSRA=_BV(ADEN)|_BV(ADPS1)|_BV(ADPS0); /*1MHz/8=125kHz.*/
    _delay_ms(100); /* Nominal RC/reference allowance, not accuracy proof. */
    uint16_t first=conversion(); /* Discard first result after enabling. */
    uint16_t result=first==ADC_FAULT ? ADC_FAULT : mean8(conversion);
    ADCSRA=0;
    PRR|=_BV(PRADC);
    return result;
}
static void raw_frame(uint16_t raw) {
    on();_delay_ms(1000);off();_delay_ms(1000); /* Start marker. */
    for (uint8_t i=0;i<10;i++) {
        on();
        if (raw_bit(raw,i)) _delay_ms(750); else _delay_ms(250);
        off();_delay_ms(500);
    }
    _delay_ms(1500);
}
static void show_kind(uint8_t kind) {
    for (uint8_t i=0;i<kind;i++) {
        on();_delay_ms(100);off();_delay_ms(400);
    }
    _delay_ms(1500);
}
static void wait_press(void) {
    while (PINB&_BV(BUTTON)) {
        cli();
        /* Clear old pending flag BEFORE the final pin check, avoiding a
           press arriving between the check and flag clear being lost. */
        GIFR=_BV(PCIF);
        if (PINB&_BV(BUTTON)) {
            sleep_enable();
            sei();
            sleep_cpu(); /* Immediately follows sei; avr-libc atomic pattern. */
            sleep_disable();
        } else sei();
    }
}
int main(void) {
    MCUSR&=(uint8_t)~_BV(WDRF);wdt_disable();
    DDRB=_BV(LED)|_BV(PB1)|_BV(PB2); /* Unused PB1/PB2 driven low. */
    PORTB=_BV(BUTTON); /* PB3 input pullup; ADC2/PB4 no pullup. */
    DIDR0=_BV(ADC2D);ACSR=_BV(ACD);ADCSRA=0;
    PRR=_BV(PRADC)|_BV(PRTIM0)|_BV(PRTIM1)|_BV(PRUSI);
    PCMSK=_BV(PCINT3);GIFR=_BV(PCIF);GIMSK=_BV(PCIE);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);sei();
    for (;;) {
        wait_press();_delay_ms(30);
        if (PINB&_BV(BUTTON)) continue; /* Bounce with no stable press. */
        uint16_t raw=sample();Result r=interpret(raw,CAL_UV_PER_COUNT);
        if (raw<=1023) raw_frame(raw); /* Timeout has no invented raw code. */
        show_kind(r.kind);
        while (!(PINB&_BV(BUTTON))) _delay_ms(10); /* Held button costs power. */
        _delay_ms(30);
    }
}
#endif

The build-command comment is an instruction for a future AVR toolchain, not evidence of a successful build here. Use avr-objcopy -O ihex battery.elf battery.hex after a successful target compile, inspect its size and program only the identified part through your verified ISP setup. No bootloader, Arduino core or electrically erasable programmable read-only memory (EEPROM) calibration storage is required by this source.

Calibrate one real unit, then test the range

  1. Start with the47k/10k pair at a measured4.5V. Keep the chip marking, fuses, supply current limit and programmer arrangement in the worksheet. Build first with CAL_UV_PER_COUNT=0. The one-pulse class must remain uncalibrated.
  2. Press and release the button. Decode the ten-bit raw frame and repeat several times. Keep the meter on the supply terminals, not on ADC2. If, as a hypothetical example, a real reading were735 at4500mV, a one-point gain would be4500×1000/735≈6122µV/count.
  3. Enter only your actual measured coefficient, rebuild and reprogram. The program’s4000–8000µV/count plausibility band does not itself perform calibration. A slope coefficient corrects gain at that point; it does not remove offset or prove accuracy elsewhere.
  4. Sweep controlled supply points within2.7–5.0V. Compare decoded counts and computed/classified values against the meter. Repeat with the470k/100k pair using a separately determined coefficient and the same fixture. Power off before changing parts.
  5. Try longer settling allowances in a separately labelled build, and compare repeatability. Record changes that persist even after more delay; those suggest more than an external RC transient.
  6. For invalid-input software trials, run the provided host cases. On the bench, disconnect power before removing a divider lead; do not create arbitrary overvoltage or run this exact grade below2.7V to seek a warning.

For current tests, measure the whole circuit at idle, then with the divider detached while power is off for rewiring, and then with each complete pair. Record the instrument range and burden voltage; a meter inserted in series can reduce the actual supply. Also measure the active LED-report interval. The long human-readable frame intentionally consumes far more energy than a brief ADC acquisition. A held button draws pullup current and leaves the CPU waiting for release; it is not the advertised sleep condition.

A useful budget is Iaverage≈Iidle+(Iactive−Iidle)×tactive/T when measurements repeat every T seconds, with the always-connected divider included once in Iidle. Brownout configuration, leakage and real supply conditions must come from your unit. No fixed nanoampere sleep claim is made. If later using three E91 cells, measure their actual series voltage, keep it within the allowed span and stop before the exact chip’s lower operating limit; do not charge these primary cells or infer remaining capacity from the class.

Source review, tests and challenge

The manufacturer-hosted complete document is2586Q–AVR–08/2013. Its ATtiny85 errata section states no known issues for revisionsB–C and identifies a revisionA EEPROM-read limitation at low voltage/clock. This firmware uses no EEPROM; that does not mean an unknown silicon lot has been physically identified or every future notice is excluded. Errata for ATtiny25,ATtiny45 or a newer tiny family must not be silently transferred to this exact85 experiment.

The host build executes the actual supplied mean, calibration gate, class boundaries and LED-bit helpers, including every ten-bit frame and every legal numeric conversion candidate. Fault cases cover zero, saturation, a failed conversion inside an average, absent/out-of-band calibration and out-of-scope voltage. Separate ideal equations check current ratio, source resistance, RC estimates, meter loading and the VCC-reference cancellation. The AVR register/sleep branch remains uncompiled and unexecuted here.

Challenge: a larger resistor pair uses less current. Why not multiply both resistances by another100?

The voltage ratio would remain the same ideally, but source resistance, leakage sensitivity and external RC time would grow100fold. At some point the sensing circuit becomes dominated by input/board/meter leakage and acquisition behavior. Choose a current/uncertainty/settling budget from measurements; preserving the ideal ratio preserves none of those practical limits.

Primary references and related learning

Review why dividers move under load and the interactive circuit lessons. This project adds the self-supply reference trap and a measurement-current budget; it does not replace a general multimeter or a battery-management system.

📡Broadcast the signal — amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu

Supplier photo of an assembled two-wheeled line-following car with a blue circuit board, two motors and an empty battery holder.

Supplier product photo

Build a line-following car

Soldering and assembly required. Check battery and track requirements before buying.

View kit on Temu