A back door sensor with a coin Cell and a reed contact to detect the state of the back door

Principles

  • Limit power consumption:

https://forum.mysensors.org/topic/1287/door-window-sensor-consuming-more-power-when-closed/5

  • For the reed contact pin D3, a 3.3 MOhm pull up resistor is used and the internal pull-up is disabled.
  • Use an Arduino Pro Mini 3V3 to keep the cost down (compared to the sensebender).
  • Use no debouncing, and not the software debouncing library, since that one is guaranteed to give trouble combined with sleep mode.
  • The Arduino 3.3V 8mhz can handle down to roughly 2.8V and the Nrf24l01+ down to 1.9V. Hence the batteries can not be NiMH rechargeables - Alkaline or Lithium required. We use a CR2450 coin cell which gives 3V.

Future extensions

  • Add a Si7021 module to measure temperature and humidity.

The result

The SMD solder work

The SMD solder work

The connection of the reed contact

The connection of the reed contact

Wiring: supply, resistor, capacitor

Wiring: supply, resistor, capacitor

Used Components

Wiring

NRF24L01+ Function Arduino Mini Pro pin
+3.3V connected with wire
GND connected with wire
CE D9
CSN D10
SCK D13
MOSI D11
MISO D12
IRQ Not Connected
Component Pin Wire/Component Pin Component
Arduino Pro Mini VCC orange plus Battery CR2450
Arduino Pro Mini GND black min Battery CR2450
Arduino Pro Mini GND Reed Contact D3 Arduino Pro Mini
Arduino Pro Mini VCC Resistor 3M3 Ohm D3 Arduino Pro Mini

Programming

This project uses Platformio, see platformio.ini

Use the following commands:

$ pio run
$ pio run -t upload
$ pio run -t monitor

Code at: BackDoorSensor.ino

Setting the BOD to 1.8V

Programmer Type: USBtiny. The USBtiny is a simple USB programmer, see http://www.ladyada.net/make/usbtinyisp/.

Give these 3 commands. The first one sets the fuse, but also clears the bootloader (thanks to the "-e" - see https://docs.platformio.org/en/latest//platforms/atmelavr.html?highlight=custom_fuses#erase-chip-before-programming). The second one restores the bootloader, and the 3rd one programs the sketch:

michiel@Delphinus:~/..../domotica/Nodes/BackDoorSensor> pio run -t fuses -e custom_fuses

michiel@Delphinus:~/..../domotica/Nodes/BackDoorSensor> avrdude -C/home/michiel/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cusbtiny -Uflash:w:/home/michiel/.arduino15/packages/arduino/hardware/avr/1.8.5/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex:i -Ulock:w:0x0F:m

michiel@Delphinus:~/..../domotica/Nodes/BackDoorSensor> pio run -t upload -t monitor

The first command with Platformio gives:

michiel@Delphinus:~/..../domotica/Nodes/BackDoorSensor> pio run -t fuses -e custom_fuses
Processing custom_fuses (platform: atmelavr; framework: arduino; board: pro8MHzatmega328)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/pro8MHzatmega328.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Pro or Pro Mini ATmega328 (3.3V, 8 MHz)
HARDWARE: ATMEGA328P 8MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- framework-arduino-avr 5.1.0
- tool-avrdude 1.60300.200527 (6.3.0)
- toolchain-atmelavr 1.70300.191015 (7.3.0)
Converting BackDoorSensor.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPI> 1.0
Building in release mode

Selected fuses: [lfuse = 0xFF, hfuse = 0xDA, efuse = 0xFE]
Setting fuses

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: reading input file "0x0f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0f:
avrdude: load data lock data from input file 0x0f:
avrdude: input file 0x0f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xDA"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDA:
avrdude: load data hfuse data from input file 0xDA:
avrdude: input file 0xDA contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xFE"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFE:
avrdude: load data efuse data from input file 0xFE:
avrdude: input file 0xFE contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK (E:FE, H:DA, L:FF)

avrdude done.  Thank you.

================================================================================ [SUCCESS] Took 0.90 seconds ================================================================================

Environment    Status    Duration
-------------  --------  ------------
custom_fuses   SUCCESS   00:00:00.897
================================================================================ 1 succeeded in 00:00:00.897 ================================================================================
michiel@Delphinus:~/..../domotica/Nodes/BackDoorSensor>

First sign of life

__  __       ____
|  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
| |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
| |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
|_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
        |___/                      2.3.2

104 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=8,REL=255,VER=2.3.2
167 TSM:INIT
174 TSF:WUR:MS=8000
190 TSM:INIT:TSP OK
200 TSF:SID:OK,ID=14
212 TSM:FPAR
223 ?TSF:MSG:SEND,14-14-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
260 TSF:MSG:READ,0-0-14,s=255,c=3,t=8,pt=1,l=1,sg=0:0
288 TSF:MSG:FPAR OK,ID=0,D=1
595 TSF:MSG:READ,13-13-14,s=255,c=3,t=8,pt=1,l=1,sg=0:1
825 TSF:MSG:READ,10-10-14,s=255,c=3,t=8,pt=1,l=1,sg=0:1
1071 TSF:MSG:READ,7-7-14,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2263 TSM:FPAR:OK
2271 TSM:ID
2277 TSM:ID:OK
2285 TSM:UPL
2304 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2340 TSF:MSG:READ,0-0-14,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2369 TSF:MSG:PONG RECV,HP=1
2385 TSM:UPL:OK
2394 TSM:READY:ID=14,PAR=0,DIS=1
2422 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2461 TSF:MSG:READ,0-0-14,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2500 TSF:MSG:SEND,14-14-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
2547 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2584 TSF:MSG:READ,0-0-14,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2650 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=11,pt=0,l=16,sg=0,ft=0,st=OK:Back Door Sensor
2697 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
2750 TSF:MSG:SEND,14-14-0-0,s=1,c=0,t=0,pt=0,l=18,sg=0,ft=0,st=OK:BDS - Reed contact
2793 MCO:REG:REQ
2838 !TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=NACK:2
2877 TSF:MSG:READ,0-0-14,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2906 MCO:PIM:NODE REG=1
2920 MCO:BGN:STP
Back Door Sensor 1.0 - Online!
2938 MCO:BGN:INIT OK,TSP=1
Wake up - now minute -1
2975 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=1,st=OK:1
Reed contact changed without interrupt - now open
3037 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3063 TSF:TDI:TSL
3074 MCO:SLP:WUP=1
3084 TSF:TRI:TSB
3104 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
Reed contact changed - now closed
3158 MCO:SLP:MS=100,SMS=0,I1=255,M1=255,I2=255,M2=255
3186 TSF:TDI:TSL
3196 MCO:SLP:WUP=-1
3207 TSF:TRI:TSB
Wake up - now minute 0
3239 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
Reed contact repeat last message - now closed
3299 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3328 TSF:TDI:TSL
3336 MCO:SLP:WUP=1
3346 TSF:TRI:TSB
3362 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact changed - now open
3416 MCO:SLP:MS=100,SMS=0,I1=255,M1=255,I2=255,M2=255
3442 TSF:TDI:TSL
3452 MCO:SLP:WUP=-1
3463 TSF:TRI:TSB
Wake up - now minute 1
3495 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact repeat last message - now open
3555 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3584 TSF:TDI:TSL
3592 MCO:SLP:WUP=1
3602 TSF:TRI:TSB
3618 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
Reed contact changed - now closed
3672 MCO:SLP:MS=100,SMS=0,I1=255,M1=255,I2=255,M2=255
3700 TSF:TDI:TSL
3710 MCO:SLP:WUP=-1
3721 TSF:TRI:TSB
Wake up - now minute 2
3753 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact changed without interrupt - now open
3815 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3844 TSF:TDI:TSL
3852 MCO:SLP:WUP=-1
3864 TSF:TRI:TSB
Wake up - now minute 3
3901 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact repeat last message - now open
3960 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3987 TSF:TDI:TSL
3997 MCO:SLP:WUP=-1
4007 TSF:TRI:TSB
Wake up - now minute 4
4040 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact repeat last message - now open
4100 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
4126 TSF:TDI:TSL
4136 MCO:SLP:WUP=-1
4147 TSF:TRI:TSB
Wake up - now minute 5
4179 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact repeat last message - now open
4239 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
4265 TSF:TDI:TSL
4276 MCO:SLP:WUP=-1
4286 TSF:TRI:TSB
Wake up - now minute 6
4319 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
4366 TSF:MSG:SEND,14-14-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:104
Wake up - a long period has passed - update all data.
4431 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
4460 TSF:TDI:TSL
4468 MCO:SLP:WUP=1
4478 TSF:TRI:TSB
4495 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
Reed contact changed - now closed
4548 MCO:SLP:MS=100,SMS=0,I1=255,M1=255,I2=255,M2=255
4577 TSF:TDI:TSL
4587 MCO:SLP:WUP=-1
4597 TSF:TRI:TSB
Wake up - now minute 0
4626 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
Reed contact repeat last message - now closed
4685 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
4712 TSF:TDI:TSL
4722 MCO:SLP:WUP=1
4732 TSF:TRI:TSB
4749 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact changed - now open
4800 MCO:SLP:MS=100,SMS=0,I1=255,M1=255,I2=255,M2=255
4829 TSF:TDI:TSL
4839 MCO:SLP:WUP=-1
4849 TSF:TRI:TSB
Wake up - now minute 1
4882 TSF:MSG:SEND,14-14-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact repeat last message - now open
4941 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
4968 TSF:TDI:TSL
__  __       ____
|  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
| |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
| |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
|_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
        |___/                      2.3.2

104 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=8,REL=255,VER=2.3.2
167 TSM:INIT
174 TSF:WUR:MS=8000
190 TSM:INIT:TSP OK
200 TSF:SID:OK,ID=26
212 TSM:FPAR
223 ?TSF:MSG:SEND,26-26-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
335 TSF:MSG:READ,21-21-26,s=255,c=3,t=8,pt=1,l=1,sg=0:1
364 TSF:MSG:FPAR OK,ID=21,D=2
882 TSF:MSG:READ,7-7-26,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2263 TSM:FPAR:OK
2271 TSM:ID
2277 TSM:ID:OK
2285 TSM:UPL
2295 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2463 TSF:MSG:READ,0-21-26,s=255,c=3,t=25,pt=1,l=1,sg=0:2
2494 TSF:MSG:PONG RECV,HP=2
2508 TSM:UPL:OK
2519 TSM:READY:ID=26,PAR=21,DIS=2
2537 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2678 TSF:MSG:READ,0-21-26,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2711 TSF:MSG:SEND,26-26-21-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
2754 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:21
2947 TSF:MSG:READ,0-21-26,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2979 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=11,pt=0,l=16,sg=0,ft=0,st=OK:Back Door Sensor
3026 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
3067 TSF:MSG:SEND,26-26-21-0,s=1,c=0,t=0,pt=0,l=18,sg=0,ft=0,st=OK:BDS - Reed contact
3112 MCO:REG:REQ
3123 TSF:MSG:SEND,26-26-21-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
3424 TSF:MSG:READ,0-21-26,s=255,c=3,t=27,pt=1,l=1,sg=0:1
3452 MCO:PIM:NODE REG=1
3467 MCO:BGN:STP
Back Door Sensor 1.0 - Online!
3485 MCO:BGN:INIT OK,TSP=1
Wake up - now minute -1
3522 TSF:MSG:SEND,26-26-21-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact changed without interrupt - now open
3584 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3612 TSF:TDI:TSL
Tags: domotica nodes
Comments: