The project is a tinderbox-sized PCB with a microprocessor and a piezo buzzer. When a trigger (a reed switch) is activated, a preprogrammed melody is played.
In the army, we have private Te, whose “theme song” is considered to be the theme from Mario, the video game. My evil plan is to install the device under his closet so that when he opens it, a magnet under the door moves away from the reed switch and the device activates.
The circuit itself is nothing complicated. The IC gets 3V from the battery and runs in standby mode. The trigger pin (2) is connected to a reed switch, the buzzer to the first PWM pin (5). There is a on-off switch (which actually works as a resistor (?!), passing 2.6V when OFF and 3.0V when ON). The loudness of the sound can be regulated with a trimpot. Three header pins pass out (or in) power, ground and the trigger.
Optimizing Power Usage
I read How to Run an Arduino for Years on a Battery and wanted to try it out. After all, what use is a project that dies after the first day of operation?
I coded the IC to check the trigger pin every second (
delay(1000);). This way, the circuit drew 4.5 mA of power (in average) and taking into account the capacity of the CR2032 battery - 225mAh - I calculated it to last about 35 hours. Not a whole lot.
Including the JeeLib library and doing
Sleepy::loseSomeTime(1000); instead of
delay(1000); reduced the power draw to 0.008 mA (!!!), giving me approximately 27 months of standby battery life.
The circuit draws 5mA of power while active (playing the melody).
I wonder whether I made a calculation mistake somewhere. 56 148% improvement with three lines of code? Unreal.
The project files are available @ GitHub.