Arduino Open Window Detector - for Winter

It is getting cold outside, but sometimes I need some fresh air in my rooms. So, I open the window, leave the room, close the door and want to come back in 5 to 10 minutes. And after a few hours I remember that the window is open... Maybe you know this or have children, which give you this experience...

My solution is the Open Window Detector. The battery will last for over a jear, so just place it in autumn and remove it in spring.

Step 1: Parts List

  1. Digispark board from eBay.

  2. Old headphones.

  3. Tiny button for reset.

  4. Connectors for speaker - otherwise it is not possible to reprogram the board.

  5. Wire.

For power supply you need:

  • AAA battery case with on/off switch. You can even use worn out batteries, since the module will operate down to 2.4Volt.


  • Old lipo battery (even 30% capacity is sufficient for this purpose).

  • 1A diode 1N4001 or equivalent or whatever you have in this size.

  • Charger for lipo batteries from eBay.

Step 2: Programming the Digispark Board

  1. Install the Digispark board for the Arduino IDE as described in

    Since we want to save power, the board clock is switched to 1MHz in our setup() so please choose Digispark (1mhz - No USB) as board in the Tools menu in order to set the right timing.

  2. Download the files from Github , compile and upload the program to the board.
    In the Arduino IDE Create a new sketch with File/New and name it e.g. "OpenWindowAlarm".
    Copy the code
    Download and extract the repository. Open the sketch with File -> Open... and select the "OpenWindowAlarm" folder. Compile and upload it. Keep in mind, that upload will not work if the speaker is connected. If everything worked, the build in LED of the Digispark will blink 5 times and then start flashing after 8 seconds with an interval of 24 seconds.

Step 3: Power Reduction

We now have a module that uses 6/9.5 mA at 3,7/5 Volt. With 2 AAA batteries (1000mAh) it will run for 7/4 days. But it is possible to reduce power consumption to 6-9 µA in 3 Steps.

  1. Disabling the power LED by breaking the copper wire that connects the power LED to the diode with a knife or removing / disabling the 102 resistor saves 2/2.2 mA.
  2. Removing the VIN voltage regulator saves 1.5/3.8 mA.
    We now use 2.5/3.5 mA at 3.7/5 Volt, and the module thus lasts for 23 days with 2 AAA batteries.
  3. Disconnecting the USB Pullup resistor (marked 152) from 5 Volt (VCC) saves the 2.5/3.5 mA. Disconnect it by breaking the copper wire on the side of the resistor that points to the ATTiny. BUT this also disables the USB interface and in turn the bootloader.
    There is a solution:
    If you use a battery then just connect the resistor directly to the USB 5 Volt that is easily available at one side of the diode. The correct side of the diode can be found by using a continuity tester. One side of this diode is connected to pin 8 of the ATtiny (VCC). The other side is connected to USB 5V.

Step 4: Reset Button

If you do not want to switch the power off and on or remove it temporarily to reset the alarm, connect a reset button between PB5 and ground.
I did this by connecting the unconnected VIN copper surface to PB5 and soldering the reset button directly to the VIN pin hole and the big ground surface of the removed VIN voltage regulator.

Step 5: Speaker

I disassembled an old headset and connected the male connector to the cable.

Step 6: Operating

To use the board place it on a windowsill and connect it to a battery or USB power bank.
If the temperature on the sill is lower than the temperature where the board was originally located it will take an additional 5 Minutes to intelligently adopt to the new start value.

You will then be alarmed if you leave the window open longer than five minutes.

Internal Operation

  • An open window is detected after TEMPERATURE_COMPARE_AMOUNT * TEMPERATURE_SAMPLE_SECONDS (48) seconds of reading a temperature with a value of TEMPERATURE_DELTA_THRESHOLD_DEGREE (2) lower than the temperature TEMPERATURE_COMPARE_DISTANCE * TEMPERATURE_SAMPLE_SECONDS (192 -> 3 minutes and 12 seconds) seconds before.

  • The delay is implemented by sleeping 3 times at `SLEEP_MODE_PWR_DOWN` for a period of 8 seconds to reduce power consumption.
  • A detection of an open window is indicated by a longer 20ms blink and a short click every 24 seconds. Therefore, the internal sensor has a time of 3 minutes to adjust to the outer temperature in order to capture even small changes in temperature. The greater the temperature change the earlier the sensor value will change and detect an open window.
  • After open window detection Alarm is activated after `OPEN_WINDOW_ALARM_DELAY_MINUTES` (5).
    The alarm will not sound if `OPEN_WINDOW_ALARM_DELAY_MINUTES` (5) after detecting an open window the current temperature is greater than the minimum measured temperature (+ 1) i.e. the window has been closed already.

  • At startup, the battery voltage is measured and recognized if the module is operating on one LIPO battery or two standard AA / AAA batteries.
    Every VCC_MONITORING_DELAY_MIN (60) minutes the battery voltage is measured. A battery voltage below VCC_VOLTAGE_LOWER_LIMIT_MILLIVOLT (3550) Millivolt or below `VCC_VOLTAGE_LOWER_LIMIT_MILLIVOLT_STANDARD` (2350) mV is indicated by beeping and flashing the LED every 24 seconds. Only the beep (not the flash) is significantly longer than the beep for an open window detection.

  • The initial alarm lasts for 10 minutes. After this it is activated for a period 10 seconds with an increasing break from 24 seconds up to 5 minutes.



    • Paper Contest

      Paper Contest
    • Sweet Treats Challenge

      Sweet Treats Challenge
    • Build a Tool Contest

      Build a Tool Contest



    I could see this being useful. My kids forget windows all the time.