Charter 25 · count · reserve project

The Door Mouse

Door-State and Opening Counter

Watch one door open and close without watching anyone who uses it.

Difficulty
★☆☆
Prefix
dm
Zone
greenhouse-2
Type
door-node
Device
dm-01
Build time
6 hours

Mission

Build this

Build a magnetic door-state sensor that publishes open or closed and increments one count for each confirmed opening.

One kit, one team repository.

Borrowed parts are labelled below and have a fallback. The registered device ID is fixed; sensing and behaviour decisions remain yours.

Bill of materials

Parts

SourcePartFallback
○ fablabReed switch and magnetUse a kit push button to bench-test the complete state machine
● kitRGB LED and 220 Ω resistors ×3—
● kitSG90 servo—

Disconnect USB before rewiring. Motors, the relay, and the servo need appropriate power and a shared ground. Never drive an actuator from the ESP32 3V3 pin.

Backup assignment · your invitation

Notice the door, not the person

A tiny magnetic switch can tell a complete mechanical story: closed, beginning to open, open, and safely closed again. The Door Mouse watches that story while remaining unable to know who crossed the threshold.

Your creature will peek out when the greenhouse door opens, return home after a confirmed close, and add exactly one to its count for every completed opening. The challenge is not seeing an open door once. It is refusing to turn rattles, hesitation, and switch bounce into imaginary visits.

The narrow claim

This device reports the door’s state and confirmed openings. It does not report people, entries, exits, or occupancy.

Meet the idea

A reed switch is a magnet-controlled button

Inside the glass capsule are thin metal reeds. A nearby magnet pulls them together. With the ESP32 input pull-up enabled, closed contacts usually read LOW and separated contacts read HIGH.

That electrical answer describes magnet distance, not door angle. Placement creates the meaning. Mark where the door becomes mechanically open enough to release the switch, then protect both pieces from shifting.

Real contacts can chatter between open and closed for a few milliseconds. Doors can also pause near the boundary. Your state machine decides which changes become events.

State

What the door appears to be now: confirmed closed, confirmed open, or still uncertain.

Transition

A change between confirmed states. One closed-to-open transition earns one count.

Debounce

A short demand for stable evidence that prevents one physical movement becoming several events.

Signal chainHow a moving door becomes one opening
  1. in the worldDoor movesThe magnet approaches or leaves the fixed switch.
  2. the partReed contactsThe magnetic field closes or releases the tiny metal reeds.
  3. electricalHIGH / LOW inputSeveral fast edges may occur around one physical transition.
  4. in the codeConfirmed state + countCode remembers the previous state and accepts one transition.
  5. on the spinestatus + countThe garden learns the door state and aggregate openings.

The count belongs after confirmation, not directly after a noisy electrical edge.

The lovely trick

A count is a story with memory

If code adds one whenever the input says open, an open door becomes hundreds of openings. If it adds one on every electrical edge, contact bounce becomes several. The device must remember what was already accepted.

A candidate state begins when the input changes. Only if that evidence remains stable for your chosen confirmation time does the official state change. Count only the confirmed closed-to-open transition.

Decision flowOne complete opening, one count
  1. 01Confirmed closedMouse is home; input is stable near the magnet.
    then, input changes,
  2. 02Opening candidateThe switch released, but the timer is still checking.
    then, stable for ___ ms,
  3. 03Confirmed openIncrement once and let the mouse peek.
    then, input returns,
  4. 04Closing candidateThe magnet returned; wait before declaring closed.

Back to the start: Confirm the close, return the mouse home, and arm the next opening.

A hesitant door may move between candidates without creating an event until one state is confirmed.

Partial is a useful answer.

If the door stops where the magnet chatters at the boundary, keep the last confirmed state or expose an uncertain status. Do not invent a clean transition just to make the display look decisive.

Wiring

Find the magnet’s useful distance before fixing anything

Bench-test the reed switch like a button. Watch the raw input while moving the magnet slowly from several angles. Only after you understand the sensing region should you design a mount and add light or movement.

The power rule: The reed switch is a dry contact and uses the ESP32 internal pull-up. Each RGB channel needs its 220 Ω resistor. Power the servo from a separate 5 V supply and join grounds.

Bench referenceOpen the exact wiring map
WiringMagnetic door input, state light, and peeking mouse
ESP32GPIO 25Reed switchone leadGNDReed switchother leadGPIO 26RGB LEDR via 220 ΩGPIO 27RGB LEDG via 220 ΩGPIO 14RGB LEDB via 220 ΩGNDRGB LEDcommon cathodeGPIO 18SG90 servosignal (orange)external 5 VSG90 servopower (red)GNDSG90 servoground (brown)
ESP32 pinPartPart markingCarries
GPIO 25Reed switchone leadDigital in/out — configure INPUT_PULLUP
GNDReed switchother leadGround — the nearby magnet closes the switch
GPIO 26RGB LEDR via 220 ΩDigital in/out — common-cathode reference
GPIO 27RGB LEDG via 220 ΩDigital in/out
GPIO 14RGB LEDB via 220 ΩDigital in/out
GNDRGB LEDcommon cathodeGround
GPIO 18SG90 servosignal (orange)PWM to actuator — mouse peeking position
external 5 VSG90 servopower (red)5V power — separate supply
GNDSG90 servoground (brown)Ground — join servo and ESP32 grounds

Glass reed capsules are fragile. Cover the leads with strain relief, keep fingers away from door pinch points, and unplug USB before changing the mounted wiring.

  • Digital in/out
  • Ground
  • PWM to actuator
  • 5V power

This map assumes a normally open reed switch and common-cathode RGB LED. If the supplied parts differ, document the inverted logic; the state names must still describe the real door.

Give it character

Give a careful watcher a readable personality

The mouse may peek quickly, creep out in stages, or remain cautious during an uncertain transition. Its colour and posture should agree with the same stored door state.

Your team decides:

  • At what physical opening should the switch release?
  • How long must open or closed evidence persist before confirmation?
  • What does the creature do when the door stops at the boundary?
  • Does one count mean confirmed opening, complete open-close cycle, or another clearly documented event?

Write these decisions in plain language before turning them into code. A clear rule is easier to test, explain, and change.

Your field adventure

Can one frozen rule survive an awkward door rehearsal?

Write the movements before tuning the software. Include ordinary use and the irritating cases a friendly demonstration tends to avoid.

  1. Map the magnetic boundary.

    Mark the switch and magnet positions, then measure where release and reconnection occur during slow movement.

  2. Write a labelled script.

    Prepare at least thirty slow, fast, held, hesitant, partial, and lightly rattled movements with expected state and count.

  3. Tune once, then freeze.

    Choose confirmation times from the first run. Do not change them during the final run.

  4. Repeat with the mounted device.

    Report missed, extra, delayed, and uncertain events plus any shift caused by the real door hardware.

MovementExpected stateExpected +countObserved stateObserved +countDelay / note
ordinary open-closeclosed1_________ ms
pause near boundaryteam defines____________
light door rattleclosed0_________

When it gets dramatic

The mouse’s confusion points to mechanics or memory

One opening adds many counts

The code is counting a level or raw edges. Count only when the confirmed state changes from closed to open.

The state is backwards

Your switch or pull-up logic is inverted. Print raw input beside the real door state, then name the Boolean for meaning rather than voltage.

The door is closed but sometimes reads open

The magnet sits too near the release boundary or the mount flexes. Increase mechanical margin before increasing debounce time.

The mouse jitters at the threshold

The servo is following raw input. Let it follow only the confirmed stored state and give uncertain evidence time to resolve.

The count returns to zero after restart

Decide whether the project needs local persistence or a documented session count. Never disguise a reset as continuity.

Choose your direction

What kind of door investigator will you become?

The state-machine authors

Make hesitant and incomplete movements the centre of the project and draw every accepted transition.

The magnetic cartographers

Map distance, angle, and mounting tolerance to build the most forgiving physical installation.

The interval keepers

Add aggregate open-minutes and study how uncertain beginnings and endings affect duration.

Each direction is real engineering. Pick the question that keeps your team curious.

A calm way through the build

Collect four small wins

  1. dm-01 says hello with the switch on the bench.

    Print raw state before mounting the magnet.

  2. One clean open and close produces two confirmed states.

    Add timers without the servo.

  3. Exactly one count follows the confirmed opening.

    Challenge it with a held-open and a bounce script.

  4. The mounted mouse peeks and returns once.

    Add protected wiring, colour, and movement after the rule is frozen.

When a new step fails, return to the last small win. The fault is now somewhere in the few wires or lines you just added.

The garden handshake

Share what you found

These names are the rigid part of the project. They let another team find your work without knowing what you called the variables in your code.

When state changes

Confirmed door state

garden/greenhouse-2/door-node/dm-01/status

Unit: enum

On each opening

Confirmed opening count

garden/greenhouse-2/door-node/dm-01/count

Unit: events

Listen beyond your own device.

garden/greenhouse-2/climate-node/ro-01/temperature

Romeo supplies greenhouse temperature. You may let warmth influence the mouse’s style or display, but it must not change what counts as a physical door transition.

Finish line

Ready to introduce to the garden

  • dm-01 stays online and publishes confirmed status plus one count per accepted opening.

  • The reject feed stays clear after the final code starts.

  • The device reads Romeo temperature without confusing climate with door state.

  • The light and mouse follow the confirmed state without blocking garden messages.

  • The build log contains the magnetic boundary, labelled movement script, frozen timing rule, misses, extras, uncertainty, and delay.

  • The fragile switch and wires are protected from strain and pinch points, and the device label can be scanned.

The Door Mouse is a good observer because it knows exactly what it witnessed: one door changing state, and nothing about the people beyond it.

Backbone now

Live status

Updates from the same public event stream

Checking dm-01…