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 Mailbox Flag: Remember an Opening, Then Sleep

This project remembers that a mailbox lid was opened, even after the lid closes again. Press VIEW to inspect the remembered event; press ACK with the lid closed to clear it. The indicator stays off the rest of the time. That interaction makes a useful distinction between detecting an event, storing it and consuming energy to display it.

ATtiny85-20PU at 3.3 V: PB2 pin 7 reads lid contact, PB3 pin 2 acknowledges, PB4 pin 3 requests display, each with 100 kΩ pullup. PB0 pin 5 drives a red LED through 4.7 kΩ.
Original Tricky Circuit connection diagram. Labels identify physical pins and supply rails; this is a locally reviewed design, not a measured prototype. Open full-size schematic

A small controller and a precise promise

Use Microchip ATtiny85-20PU, a through-hole eight-pin microcontroller, with regulated 3.3 V. The code assumes the internal 8 MHz oscillator divided by eight, giving a nominal 1 MHz processor clock. F_CPU tells the compiler the clock rate; defining it does not program the hardware clock fuses. Verify the fuse configuration with your programmer before interpreting the 25 ms contact filter.

Power-down sleep stops most clocked activity until an enabled source wakes the chip. A pin-change interrupt responds to changes on selected inputs, so lid and button transitions can wake it without periodic polling. The interrupt handler does no work beyond returning; the main loop handles the contacts after waking. This project has no radio or notification service.

Parts and equipment

  • Microchip ATtiny85-20PU in PDIP-8; regulated, current-limited 3.3 V source; breadboard and a 3.3 V compatible AVR in-system programmer.
  • One lid contact closed when the lid is closed (a model switch is sufficient); two normally open buttons marked ACK and VIEW.
  • Three 100 kΩ pullups, one 10 kΩ RESET pullup, one 4.7 kΩ LED resistor, red LED, 100 nF ceramic bypass. A meter suitable for measuring supply current.

Every connection

Pin or partConnection and purpose
Supply and resetPin 8 VCC → 3.3 V; pin 4 GND → ground. 100 nF across 8/4. Pin 1 RESET → 3.3 V through 10 kΩ; keep available to the programmer.
LidPB2 pin 7 → contact to ground, closed with lid closed. Separate 100 kΩ pullup from pin 7 to 3.3 V.
AcknowledgePB3 pin 2 → ACK button to ground; 100 kΩ pullup to 3.3 V.
ViewPB4 pin 3 → VIEW button to ground; 100 kΩ pullup to 3.3 V.
IndicatorPB0 pin 5 → 4.7 kΩ → LED anode; LED cathode to ground. PB1 pin 6 unused, internally pulled up.
ProgrammingProgrammer RESET/MOSI/MISO/SCK reach pins 1/5/6/7, plus common ground. Disconnect lid contact during programming because PB2 is also SCK. Use one supply source; disconnect programmer for current measurements.

Give every input a defined state

Each 100 kΩ resistor pulls its input high when the contact is open. Closing the contact gives a low input and consumes about 3.3/100000 = 33 µA through that resistor. The lid contact is deliberately closed while the lid is closed: ordinary standby therefore includes that 33 µA. A high-value resistor reduces standing current but also makes long, exposed wiring more susceptible to leakage and interference. Keep the prototype leads short and dry.

The LED current is approximately (3.3 − 1.8)/4700 = 0.32 mA for an assumed 1.8 V red LED drop. Its real forward voltage and brightness vary. VIEW held down adds both that current when an event is latched and its own 33 µA pullup current. Sleep does not switch off an output that was left high, so holding VIEW can keep the LED on while the processor sleeps.

The event policy

The remembered flag is stored in volatile working memory: it survives sleep but is lost when power or reset clears the program. At startup an open lid sets the flag after contact filtering; a closed lid starts clear. This is not a record that survives battery replacement, and it is not proof of mail delivery. Opening the lid for any reason counts.

The decision rule gives an open lid priority over acknowledgement. ACK cannot clear the flag while the lid remains open. Once the lid closes, a pressed ACK clears it. If ACK is held during closing, clearing occurs then; there is no additional press-edge requirement. State that policy before testing, because a different interaction would need different code.

Two contact samples separated by approximately 25 ms must agree. This rejects some bounce but cannot guarantee rejection of every possible chatter waveform. Very short open-and-close events can be missed intentionally. After updating the flag and indicator, the code disables interrupts briefly, checks that the inputs have not changed, enables sleep and uses the documented enable-interrupts-then-sleep sequence. This closes the usual race in which an event arrives just before sleep and the main loop misses its wakeup.

Complete program

/* ATtiny85-20PU, 3.3 V. Internal 8 MHz oscillator / CKDIV8 => 1 MHz.
   Compile with avr-gcc -mmcu=attiny85 -DF_CPU=1000000UL -Os -o mailbox.elf attiny-mailbox.c
   TC_HOST_TEST exposes only the portable decision logic for host tests. */
#include <stdint.h>
uint8_t mailbox_next(uint8_t latched, uint8_t open, uint8_t ack) {
    if (open) return 1; /* Opening has priority; cannot acknowledge an open lid. */
    if (ack) return 0;
    return latched;
}
#ifndef TC_HOST_TEST
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <util/delay.h>
ISR(PCINT0_vect) { } /* Wake only; no work or delay inside interrupt. */
int main(void) {
    MCUSR = 0; wdt_disable();
    ADCSRA &= ~_BV(ADEN); ACSR |= _BV(ACD);
    DDRB = _BV(PB0); /* LED output; external 100k pullups on PB2/3/4 */
    PORTB = _BV(PB1); /* unused PB1 input uses internal pullup */
    PCMSK = _BV(PCINT2) | _BV(PCINT3) | _BV(PCINT4);
    GIFR = _BV(PCIF); GIMSK |= _BV(PCIE);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    uint8_t latched = 0;
    sei();
    for (;;) {
        uint8_t first = PINB & 0x1c;
        _delay_ms(25);
        uint8_t raw = PINB & 0x1c;
        if (raw != first) continue;
        latched = mailbox_next(latched, !!(raw & _BV(PB2)), !(raw & _BV(PB3)));
        if (latched && !(raw & _BV(PB4))) PORTB |= _BV(PB0);
        else PORTB &= ~_BV(PB0);
        cli();
        if ((PINB & 0x1c) != raw) { sei(); continue; }
        sleep_enable();
        sei(); /* AVR guarantees next instruction executes before ISR */
        sleep_cpu();
        sleep_disable();
    }
}
#endif

Build and flash deliberately

The listing is bare AVR C, not an Arduino sketch. With an installed AVR compiler and avr-libc, build using avr-gcc -mmcu=attiny85 -DF_CPU=1000000UL -Os -o mailbox.elf attiny-mailbox.c, then convert with avr-objcopy -O ihex -R .eeprom mailbox.elf mailbox.hex. Flash using your programmer’s documented ATtiny85 procedure. Keep RESET enabled; do not copy fuse bytes intended for an unrelated board or oscillator.

AVR in-system programming shares PB0, PB1 and PB2 with our circuit. Open or disconnect the lid contact before programming so it cannot hold the programming clock low. Use 3.3 V compatible programmer signals and one supply source. Confirm the device signature before writing. No AVR target compiler was available in the local authoring environment: only the shared decision function was compiled and executed on a host, so a target firmware build remains an explicit bench prerequisite.

Test behavior before measuring current

  1. Power up with the lid closed. Hold VIEW: LED off. Open the lid for one second, close it and press VIEW: LED on.
  2. Release VIEW and confirm the LED goes off. Press ACK with the lid closed, then VIEW: LED off.
  3. Open the lid and hold ACK. VIEW must still show the event. Close the lid while holding ACK and verify the documented clearing policy.
  4. Reset or remove power with a closed lid and a remembered event. On restart the flag is clear, demonstrating volatile storage rather than a failed memory guarantee.
  5. Disconnect the programmer. Measure supply current with lid closed, lid open, and VIEW held with a latched event. Record supply voltage, meter range, fuse configuration and LED current separately.

Turn current into a budget, not a slogan

An idealized 1000 mAh source supplying a constant 33 µA would last about 30303 hours by division alone. That ignores the processor, regulator, battery self-discharge, temperature, active intervals and display time, so it is not a battery-life claim. Measure the complete assembly, including the source regulator. A meter’s voltage drop in current mode can also change the circuit under test.

The code disables the analogue-to-digital converter and analogue comparator, which are unused. It does not silently change brownout fuse settings. Brownout detection resets a processor when supply becomes unsuitable; its current contribution depends on configuration. The exact datasheet includes revision-specific errata; the listed early ATtiny85 EEPROM issue is avoided here because no EEPROM access is used.

This circuit has not been physically tested. Local checks validate the flag priorities for every input combination, not wake latency, sleep current or compiled AVR behavior. This is a low-voltage tabletop prototype; enclosure, contact protection and outdoor reliability require later work.

Challenge: would an always-on event LED simplify the code?

Yes, but its roughly 0.32 mA could dominate the standby budget. Press-to-view moves that cost to brief observations. A mechanical indicator is another option with a different energy and construction tradeoff.

Sources and related lessons

Continue with why a voltage divider drops under load, measuring current through a resistor with a voltmeter, and the interactive circuit lessons.

📡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