logo

Openplatform.xyz

Placeholder for our stuff related to Telecom, IT, Internet of things (IOT), ESP8266, Raspberry Pi

Home IOT Telecom IT stuff About Us Contact Us Site Map

ATtiny13 Low Power Door Sensor

Let's build a Door Sensor

  • Ultra low power, No need to replace batteries for atleast a year.
  • Cheap, need to put on many doors and windows
  • Wireless (RF 433MHz), don't want to run wires from every door in house
  • Use few components
  • ATtiny sleeps most of the time to save battery. It wakes up only in following conditions
    • Door is opened. (State change from Close to Open)
    • Door is closed (State change from Open to Close)
    • Periodically wakes up every 8s and after configurable time elapsed (60 x 8s) transmits door state. This can be used as keep alive that battery is up and circuit is running. Also a reminder can be triggered in case door is open. I am using Alexa to play an reminder announcement.
  • Transmitor is powered from ATtiny pin. So it uses power only when there is something to transmit.

What we need:

  1. ATtiny13 - 1 No.
  2. RF Transmitor 433MHz - 1 No.
  3. RF Receiver 433MHz - 1No.
  4. Reed Switch - 1 No.
  5. Magnet - 1 No.
  6. Resistance 100K and 1K ohm - 1 No. each
  7. LED - 1 No.
  8. Jumper to isolate LED (save power, connect LED to debug only)
  9. Battery 3xAAA
  10. General Purpose PCB and some wires

Schematic

 

ATtiny Door Sensor

DoorSensorPCB1 RFTx1

Note: Too big resistance in series with Reed Switch can create issues. Earlier I put 1M ohm, this started dropping 2.2v in open condition. Seems the air inside Reed Switch produced resistance around 1M ohm, this can create issues of false detection.  Replacing it with 100k ohm resolved issue.

Code Door Sensor Transmitter

Download Arduino Sketch from https://github.com/shariramani/ATtiny-RF-433MHz-Door-Sensor

Learn how to program ATtiny at https://openplatform.xyz/attiny13_my_adventures.html

 

Function and Features:

I had normally open reed switch. When door is open, reed switch remains open so the detector pin pb0 reads high. When door closes, magnet comes near to reed switch and reed switch gets closed and detector pin pb0 reads low.

ATtiny is sleeping all the time except following conditions.

  1. It wakes up when there is a change in pb0 pin state. pb0 pin state is changed whenever door opens or closes. Code is using pin change interrupt (PCINT) feature of AVR to wakeup ATtiny. ATtiny reads pb0 pin to know door is open or closed and transmitts message on RF. After that it goes back to sleep.
  2. A Watchdog Timer wakes up ATtiny every 8 seconds. The Watchdog Timer (WDT) is a counter clocked by a separate On-Chip oscillator (different from the main clock of the AVR). ... When the WDT overflows, the AVR resets and starts the program from the reset vector, which is similar to externally pulling down the reset pin. ATtiny just increments a counter and goes back to sleep.
  3. Whenever counter hits 60 (programmable value) i.e. 8 x 60 = 480 sec, ATtiny reads pb0 pin and transmits the door state on RF. After that it resets counter and goes to sleep.

Code also has a very simple software debouncer. It reads pin state multiple times at brief intervals. 10 consecutive same readings declare the door state close or open. For our application this simple software debouncer is more than enough.

RF Transmitter is powered by ATtiny pin. This pin goes high only when we have something to transmit.

Remove the LED jumper after initial testing to save power.

Battery life

ATtiny is sleeping most of the time, 3xAAA cells will provide enough juice to run the ckt for year.

 

Antenna

To increase the reach, attach an Antenna to receiver and transmitter. Look at following links to build one for youerself

https://davidaugustat.com/arduino/wireless-rgb-controller-433mhz-rf-modules

https://arduinodiy.wordpress.com/2015/07/25/coil-loaded-433-mhz-antenna/

Interface with Openhab2

I am running openhabian on raspberry pi 3b.

Connect RF receiver to raspberry-pi gpio pins

How to receive RF signals

Convert RF to MQTT

Configure Door Sensor in Openhab2

 

 

Going Further :

Create rules in Alexa or Openhab2.

  1. If door opens and it's dark than turn on lights.
  2. Send an alert mail when door opens.
  3. When no door message received in last 20mins, send an alert mail and Alexa plays an announcement. (Note that our door sensor is sending a message approximately every 8m.

To use standalone door sensor, connect a buzzer instead of RF transmitter.




Coming Soon !!!

 



Suresh

Suresh Hariramani

I am an IOT enthusiast with more than 20 years of experience in the IT sector. Specializing in telecom service's; follow me for some very innovative and best in class IOT products as I unfold my knowledge and passion for the subject.


Vatsal

Vatsal Hariramani

Just me, myself and I, exploring the universe of uknownment. I have a heart of love and interests in technology, IOT and travel . And I want to share my world with you .