Community project

Cookie Jar Opening Alarm

Photo of Cookie Jar Opening Alarm
Generated with AI

Dhruv Panchal

Published November 19, 2026

This project builds a simple alarm that sounds whenever a cookie jar is opened. The system uses a reed switch mounted on the jar's lid and a neodymium magnet on the base to detect when they separate, triggering a piezo buzzer to emit an alert. An Arduino Uno microcontroller manages the logic, making it easy to customize the alarm tone and duration.

This guide provides a complete parts list, wiring diagram showing connections between the reed switch, buzzer, and Arduino, step-by-step assembly instructions for mounting the magnetic sensor, and the firmware needed to get the alarm working. The project is ideal for learning about magnetic switches and Arduino tone generation while creating a fun kitchen gadget.

Wiring diagram

Wiring diagram for Cookie Jar Opening Alarm
Loading diagram…

Gather all the parts

QtyComponent
1

Reed Switch

Glass-encapsulated magnetic reed switch -- contacts close in the presence of a magnetic field. Standard door/window sensor for alarms. Wire as a digital input with internal pull-up; debounce in firmware.

1

Piezo Buzzer

Small passive piezo buzzer (TDK PS1240) for beeps, tones and alerts. It has no built-in oscillator, so drive one lead with a 3-30 V square wave from a microcontroller pin using tone() or PWM and connect the other lead to ground. It is loudest around 4 kHz and works from about 2 to 10 kHz; driving both leads in antiphase roughly doubles the volume.

1

Neodymium Disc Magnet 10 x 3 mm

Small cylindrical neodymium magnet used as a magnetic target for Hall-effect homing or position sensing. It has no electrical pins and should be mounted mechanically on the moving split-flap wheel or index point, close enough for the chosen Hall sensor to detect repeatably without striking the sensor.

Assemble it in 4 steps

1. Connect the reed switch

With USB disconnected, connect either reed-switch lead to Uno D2 (lid detection) and the other to GND (ground). Do not connect the switch to 5V. The firmware enables the Uno's internal pull-up resistor, so no separate resistor is needed.

  • Disconnect USB before changing wires. The glass switch is fragile; protect it from impacts.

2. Connect the buzzer

Keep the passive piezo buzzer SIG lead connected to D9 (sound) and its other lead to GND. Use the specified passive piezo, not a magnetic speaker or high-current siren.

3. Mount the switch and magnet

Secure the reed switch outside the jar near the rim. Secure the magnet outside the lid next to the switch when closed. Position the magnet close to the switch when the lid is closed; the current buzzer-test program ignores the switch. Keep all electronics outside the food area.

  • Fully enclose and firmly secure the magnet so it cannot fall into the jar. Swallowed magnets can cause severe internal injury; keep them away from children and pets.

4. Test the alarm

Plug in USB and press Deploy. The current buzzer-test program beeps for one second, then pauses for one second, regardless of the magnet or reed switch. Listen for repeating beeps. Restore the lid-detection program after testing to use this as a jar alarm.

Review all connections

1. Connections between "lid_sensor" and "Arduino"

Functionlid_sensorArduino
dataPIN1GPIO 2
groundPIN2GND

2. Connections between "buzzer" and "Arduino"

FunctionbuzzerArduino
pwmSIGGPIO 9
groundGNDGND

Deploy the firmware

#include <Arduino.h>

// Buzzer test mode: deliberately ignores the reed switch.
constexpr uint8_t BUZZER_PIN = 9;

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  tone(BUZZER_PIN, 4000);
  delay(1000);
  noTone(BUZZER_PIN);
  digitalWrite(BUZZER_PIN, LOW);
  delay(1000);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik