A door that opens for five seconds should not trigger the same reminder as one left open for a minute. This small project makes the difference visible: move a magnet away from a reed switch and the indicator lights only after about 30 seconds. Returning the magnet resets the countdown.
Why these parts work together
A reed switch contains magnetic metal contacts in a sealed capsule. Choose a normally open contact that closes near its magnet; verify this with the continuity range of a multimeter before assembly. The 10 kΩ pull-up resistor gives the input a defined high level when the contact opens. An LED, or light-emitting diode, turns electrical current into visible light. Its series resistor limits that current: with a red LED near 2 V, the estimate is (3.3 − 2)/680 = 1.9 mA.
DIP means dual in-line package: two parallel rows of pins. The drawing names physical DIP-8 pins as well as PB port names. Do not use Arduino pin numbers here. The 100 nF capacitor supplies brief local current pulses and helps keep the supply at the chip steady.
Parts to gather
- ATtiny85 in DIP-8 package, a regulated 3.3 V supply and a compatible 3.3 V ISP programmer
- Normally open reed switch and magnet; red LED
- Two 10 kΩ resistors, one 680 Ω resistor, one 100 nF ceramic capacitor
- Breadboard, short wires and a multimeter

Complete connections
| Connection | Purpose |
|---|---|
| Pin 8 VCC → 3.3 V; pin 4 GND → ground | Place 100 nF directly between pins 8 and 4. |
| Pin 1 RESET → 10 kΩ → 3.3 V | Keep RESET available to the programmer. |
| Pin 2 PB3 → reed → ground; PB3 → 10 kΩ → 3.3 V | The magnet closes the contact: closed door reads low. |
| Pin 5 PB0 → 680 Ω → LED anode; LED cathode → ground | The LED indicates a door left open, not the instantaneous contact state. |
Clock assumptions and loading the firmware
This program targets an ATtiny85 whose internal 8 MHz oscillator is divided by eight, giving a 1 MHz processor clock. That is the factory clock arrangement described in the datasheet; a previously programmed chip may differ. F_CPU tells the compiler what you expect but does not change the chip’s clock. Confirm the existing clock configuration with your programmer before use. This lesson does not write fuse bits.
ISP means in-system programming. Connect your compatible programmer’s MOSI to PB0/pin 5, MISO to PB1/pin 6, SCK to PB2/pin 7, RESET to pin 1 and ground to pin 4. Use one agreed source of target power, not two competing supplies. Disconnect the LED branch while programming if it loads the programmer. With an AVR-GCC toolchain installed, compile using avr-gcc -mmcu=attiny85 -Os -DF_CPU=1000000UL door_reminder.c -o door_reminder.elf, then avr-objcopy -O ihex -R .eeprom door_reminder.elf door_reminder.hex. Upload that HEX through the selected programmer’s documented flash operation.
Complete firmware
/* ATtiny85, factory 1 MHz internal clock. No fuse writes in this example.
* PB3/pin 2: reed to GND; PB0/pin 5: 680 ohm + red LED to GND.
* PB3 has an external 10k pull-up. Timer: 1 MHz / 64 / 125 = 125 Hz.
* Define TC_HOST_TEST only for the supplied host-side logic tests.
*/
#include <stdint.h>
typedef struct { uint8_t stable, candidate, count; uint16_t open_ticks; } Door;
/* 4 consecutive equal samples debounce the contact. Saturate the timer. */
static uint8_t door_tick(Door *d, uint8_t raw_open) {
if (raw_open != d->candidate) { d->candidate = raw_open; d->count = 1; }
else if (d->count < 4) { ++d->count; }
if (d->count >= 4) d->stable = d->candidate;
if (!d->stable) d->open_ticks = 0;
else if (d->open_ticks < 3750) ++d->open_ticks;
return d->open_ticks >= 3750; /* about 30 seconds after debounced open */
}
#ifndef TC_HOST_TEST
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#if F_CPU != 1000000UL
#error This timer configuration requires a 1 MHz CPU clock
#endif
#include <avr/io.h>
int main(void) {
Door door = {0, 0, 0, 0};
DDRB = (1 << PB0); PORTB = 0;
TCCR0A = (1 << WGM01); /* clear timer on compare match */
TCCR0B = (1 << CS01) | (1 << CS00);
OCR0A = 124;
for (;;) {
while (!(TIFR & (1 << OCF0A))) { }
TIFR = (1 << OCF0A); /* clear by writing one */
uint8_t alarm = door_tick(&door, (PINB & (1 << PB3)) != 0);
if (alarm) PORTB |= (1 << PB0); else PORTB &= ~(1 << PB0);
}
}
#endif
What the timer counts
The timer divides 1,000,000 clock ticks by 64 and counts 125 of those slower ticks: one sample arrives every 8 ms. Four consecutive equal samples qualify a contact change, so bouncing contacts cannot immediately reset or start the reminder. This is debounce: accepting a change only after it persists. Once the open state is accepted, 3,750 ticks represent approximately 30 seconds. The internal oscillator is not a precision clock, so compare behavior with a stopwatch rather than claiming exactly 30.000 seconds.
The counter stops increasing at its maximum. That matters because a small integer that keeps increasing eventually wraps to zero; a saturated counter keeps the indicator on until the door closes. Power loss clears the reminder. An already open door at startup starts a new countdown.
Bench test and troubleshooting
- Start with the magnet present. Confirm the LED remains off for at least 35 seconds.
- Remove the magnet for five seconds and replace it. No reminder should appear.
- Remove it again for more than 30 seconds. The LED should stay on until you replace it.
- Leave it open for several minutes: the indicator should not periodically clear.
- Disconnect the reed wire. It reads open and eventually lights the LED, which is useful but cannot distinguish an actual open door from a broken wire.
If the delay is roughly eight times wrong, investigate the clock before changing timer constants. If the LED never lights, check its polarity and pin 5, then measure PB3 with and without the magnet. Keep the fragile glass switch supported; bend leads away from its body.
Challenge: how many timer ticks give roughly 10 seconds?
10/0.008 = 1,250 ticks. Change both uses of 3750 together. Keep the debounce length unchanged: the contact’s bounce does not depend on the chosen reminder delay.
Sources and related learning
Explore the Tricky Circuit interactive lessons. This article presents a design and software checks; no physical build results are claimed.



