Place this gadget on a windowsill and you will be alarmed if you leave the window open longer than five minutes. It senses the falling temperature and thus works best in winter. It requires only 0.026 milliampere. This means one battery will last the whole winter.
Available as "OpenWindowAlarm" example of Arduino library "ATtinySerialOut"
Der Sourcecode kann von hier kopiert werden.
Das Programm ist auch als Beispiel der Arduino "ATtinySerialOut" Bibliothek - unter Datei -> Beispiele -> Beispiele aus eigenen Bibliotheken - ATtinySerialOut -> OpenWindowAlarm verf�gbar. Die Bibliothek kann mit Werkzeuge -> Bibliotheken verwalten... oder Strg+Umschalt+I geladen werden. Dabei "SerialOut" als Suchstring benutzen.
The sourcecode can be copied from here.
The application is also available as an example of the Arduino ATtinySerialOut library - use File -> Examples -> Examples from Custom Libraries - ATtinySerialOut -> OpenWindowAlarm.
You can load the library with Tools -> Manage Libraries... or Ctrl+Shift+I. Use "SerialOut" as filter string.
YouTube video | Instructable |
---|---|
OpenWindowAlarm on a windowsill |
Every 24 seconds a reading is taken of the ATtiny internal temperature sensor which has a resolution of 1 degree.
If temperature is lower than the "old" temperature value, an alarm is issued five minutes later if by then the condition still holds true.
Detection of an open window is indicated by a longer 20 ms blink and a short click every 24 seconds.
Low battery is indicated by beeping and flashing the LED every 24 seconds. The beep and the flash are longer than for an open window detection.
AAA battery case | CR2032 case | LiPo battery |
---|---|---|
Install the Digispark board for the Arduino IDE as described in http://digistump.com/wiki/digispark/tutorials/connecting. Instead of http://digistump.com/package_digistump_index.json you must use http://drazzy.com/package_drazzy.com_index.json as Digispark board URL in Arduino File/Preferences. In the Boards Manager install the latest ATTinyCore version.
Since we want to save power, the board clock is 1 MHz so you must choose ATTinyCore->ATtiny85 (Micronucleus / DigiSpark)
as board in the Tools menu and set the clock to 1MHz (no USB).
For Windows you must install the Digispark driver before you can program the board.
if you have the Digistump AVR Boards already installed, then the driver is located in %UserProfile%\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b
. Just execute the Install_Digistump_Drivers.bat
file.
Or download it here, open it and run InstallDrivers.exe
.
Leider muss der Treiber f�r das Digispark Board manuell installiert werden. Der Digispark Treiber kann von hier heruntergeladen werden. Dann die Datei �ffnen und InstallDrivers.exe
ausf�hren.
Wenn die Digispark Boards in der Arduino IDE schon installiert sind, ist der Treiber bereits auf der Platte unter %UserProfile%\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b
. Am einfachsten installiert man ihn, wenn man das Board einsteckt und wenn das unbekannte Ger�t im Ger�te-Manager auftaucht, Treiber aktualisieren ausw�hlt. Dann Auf dem Computer nach Treibersoftware suchen w�hlen, C:\Users\<username>
w�hlen und Weiter klicken.
Bei der Nachfrage M�chten sie diese Ger�tesoftware installieren auf installieren klicken.
Wenn das Board nicht erkannt wird (kein Ger�usch beim Einstecken) kann es daran liegen, dass die Buchse zu tief ist, dann eine ander Buchse oder ein USB Verl�ngerungskabel benutzen.
Install the Arduino library ATtinySerialOut and select the OpenWindowsAlarm example with File -> Examples -> Examples from Custom Libraries -ATtinySerialOut -> OpenWindowAlarm
OR
create a new sketch with File -> New and name it OpenWindowAlarm
in the Arduino IDE and copy the code from OpenWindowAlarm.ino.
Compile and upload it. Keep in mind, that upload will not work if the speaker is connected.
If everything works well, the built-in LED of the Board will blink 5 times (for the 5 minutes alarm delay) and then start flashing after 8 seconds with an interval of 24 seconds to signal each temperature reading.
Before power reduction changes
We now have a Digispark board that consumes 6 mA at 1MHz and 3,7 volt. With a battery of 2000 mAh it will run for 14 days. But it is possible to reduce power consumption to 27 �A in 3 Steps.
- 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.
- Removing the VIN voltage regulator saves 1.5/3.0 mA.
The board now needs 3/4.3 mA at 3.7/5 volt and the 2000mAh battery will last for 28 days. - Disconnecting the USB D- Pullup resistor (marked 152) from 5 volt (VCC). Disconnect it by breaking the copper wire on the side of the resistor that points to the ATtiny.
This disables the USB interface and in turn the possibility to program the Digispark board via USB. To enable it again, but still save power, connect the resistor (marked 152) directly to the USB V+ that is easily available at the outer 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) and Digispark 5V. The other side is connected to the USB V+.
Now the USB pullup resistor is only activated if the Digispark board is connected to USB e.g. during programming.
The board now consumes 27 �A during sleep.
The software loop needs 2.1 ms (plus 3 times 64 ms startup time) => active time is around 1/125 of total time.
During the loop the power consumption is 100 times the sleep current => Loop adds 80% to total power consumption.
We now have an average current consumption of 75 �A and the 2000mAh battery will last for 3 years.
The BOD current of 20 �A can only be disabled by setting fuses via ISP programmer](https://www.google.de/search?q=arduino+as+isp) and a connecting adapter. We can also reduce the start-up time from sleep from 64 to to 5 ms.
For reprogramming the fuses, you can use this script.
Without BOD and with fast startup we have an average current consumption of 9 �A and are still able to program the ATtiny by USB.
If you do not want to remove power 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.
If you want to get rid of the 5 seconds wait for USB connection after reset, you can change the micronucleus kernel on the ATtiny85.
Both patches on front | Reset connection on back |
---|---|
Part 1 | Part 2 |
---|---|
Powered by 2 AAA batteries |
Powered by CR2032 coin cell |
Powered by LiPo battery |
Back viev with CR2032 coin cell |
With 16 Ω buzzer from an old Pc |
Compact version |
Different reset buttons and connectors
Place the board on a windowsill and connect it to the supply. If the temperature on the sill is lower than the temperature where the board was originally located, it will take additional 5 minutes to adopt to the new start value to avoid false alarm.
-
An open window is detected after
TEMPERATURE_COMPARE_AMOUNT * TEMPERATURE_SAMPLE_SECONDS
(48) seconds of reading a temperature with a value ofTEMPERATURE_DELTA_THRESHOLD_DEGREE
(2) lower than the temperatureTEMPERATURE_COMPARE_DISTANCE * TEMPERATURE_SAMPLE_SECONDS
(192 seconds-> 3 minutes and 12 seconds) before. -
The delay is implemented by sleeping 3 times at
SLEEP_MODE_PWR_DOWN
for a period of 8 seconds -the maximum hardware sleep time- to reduce power consumption. -
If an open window is detected, this is indicated by a longer 20 ms 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.
-
OPEN_WINDOW_ALARM_DELAY_MINUTES
(5) minutes after open window detection the alarm is activated.
The alarm will not start or an activated alarm will stop if the current temperature is greater than the minimum measured temperature (+ 1) i.e. the window has been closed already. -
The initial alarm lasts for 10 minutes. After this, it is activated for a period of 10 seconds with a increasing break time from 24 seconds up to 5 minutes.
-
At power-on the VCC voltage is measured used to determine the type of battery using
VCC_VOLTAGE_LIPO_DETECTION
(3.6 volt). -
Every
VCC_MONITORING_DELAY_MIN
(60) minutes the battery voltage is measured. Depending on the detected battery type, low battery voltage 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.
Low battery voltage is defined byVCC_VOLTAGE_LOWER_LIMIT_MILLIVOLT_LIPO
(3550 Millivolt) orVCC_VOLTAGE_LOWER_LIMIT_MILLIVOLT_STANDARD
(2350 Millivolt). -
After power-on, the inactive settling time is 5 minutes. If the board is getting colder during the settling time, 4:15 (or 8:30) minutes are added to avoid false alarms after power-on.
-
If you enable
DEBUG
by activating line 62, you can monitor the serial output with 115200 baud at P2 to see what is happening.
-
- party libs.
- Adapted MCUSR handling.
- Check for closed window happens only the first 10 minutes of alarm.
- Changed voltage low detection.
- Improved DEBUG output.
- Converted to Serial.print.
- New PWMTone() without tone().
- Fixed bug in check for temperature rising after each alarm.
- Improved sleep, detecting closed window also after start of alarm, reset behavior.
- Changed LIPO detection threshold.
- Fixed analog reference bug.
Changed OSCCAL from 0x52 to 0x4e
START ../src/OpenWindowAlarm.cpp
Version 1.2.1 from Nov 5 2019
Alarm delay = 5 minutes
MCUSR=0x2 LFuse=0x225 WDTCR=0x0 OSCCAL=0x78
Booting from reset
VCC=4022mV - LIPO detected
Temp=300 Old=0 New=300
Temp=298 Old=0 New=598
Temp=298 Old=0 New=596
Temp=297 Old=0 New=595
Temp=296 Old=0 New=593
Temp=296 Old=0 New=592
Temp=296 Old=0 New=592
Temp=296 Old=0 New=592
Temp=296 Old=0 New=592
Temp=296 Old=0 New=592
Temp=296 Old=300 New=592
Detected porting to a colder place -> reset
Temp=296 Old=0 New=296
Temp=296 Old=0 New=592
...
Temp=296 Old=0 New=592
Temp=296 Old=296 New=592
Temp=296 Old=592 New=592
Temp=296 Old=592 New=592