Principles

  • Limit power consumption:

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

try a 1 MOhm pull up and disable the internal. Hardware debounce is the way to go. Add 100nF to ground and 10k in series with the contact.

  • Use an Arduino Pro Mini 3V3 to keep the cost down (compared to the sensebender).
  • Use hardware debouncing (or none), but 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 required. But due to the low current, we can use batteries that are considered "empty" for driving motors.

Future extensions

  • Add a Si7021 module to measure temperature and humidity.

The result

PC240022h.png PC240013vs.png

See also the gallery.

Used Components

P9170009c.jpg

Wiring

MISO = M1, MOSI = M0

Component Pin Wire/Component Pin Component
NRF24L01+ SMD +3.3V red plus Batteries 2x AAA
NRF24L01+ SMD GND black min Batteries 2x AAA
NRF24L01+ SMD CE blue D9 ArduinoProMini3V
NRF24L01+ SMD CSN orange D10 ArduinoProMini3V
NRF24L01+ SMD SCK brown D13 ArduinoProMini3V
NRF24L01+ SMD M0 (MOSI) yellow D11 ArduinoProMini3V
NRF24L01+ SMD M1 (MISO) purple D12 ArduinoProMini3V
NRF24L01+ SMD IRQ green D2 ArduinoProMini3V
GND GND Reed Contact D3 ArduinoProMini3V
ArduinoProMini3V VCC Resistor > 3M Ohm D3 ArduinoProMini3V
ArduinoProMini3V VCC red plus Batteries 2x AAA
ArduinoProMini3V GND black min Batteries 2x AAA

Programming

  • Board: Arduino Pro or Pro Mini
  • Processor: ATmega328P (3.3V, 8MHz)
  • Serial monitor: 19200 Baud

Code at: DoorWindowButton.ino

Brown-Out Detection

The problem

A standard Arduino Pro Mini 3.3V 8MHz has a e-fuse value of 0xFD, which means that the device refuses to work if the VCC goes below 2.7 Volt. That means that it will not work with 2 AAA rechargeable MiNH batteries, which give at most 1.3 Volt each. So, we would like to change this value.

The solution

The default value of the e-fuse for an Arduino Pro Mini is 0xFD, which means 2.7V brown-out detection. Changing the value into 0xFE means 1.8V, acceptable for our case with 2 batteries. Alternatively, brown-out detection can be disabled completely with the value 0xFF.

The fuses of an ATmega328P can be set with an ISP, not with the normally used Arduino serial connection.

We make use of the "Arduino as ISP" programmer. Since the target is a 3.3V device, it would be best to use a 3.3V programmer, too.

Use Arduino as ISP

We use a standard Arduino Pro Mini for 3.3V 8MHz as programmer.

See https://www.arduino.cc/en/tutorial/arduinoISP

P1020011.jpg P1020020.jpg

Reading fuse value

michiel@arion:~> avrdude -p m328p -P /dev/ttyUSB0 -c avrisp -b 19200 -U efuse:r:-:h

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading efuse memory:

Reading | ################################################## | 100% 0.02s

avrdude: writing output file "<stdout>"
0xfd

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

avrdude done.  Thank you.

michiel@arion:~>

Writing fuse

michiel@arion:~> avrdude -p m328p -P /dev/ttyUSB0 -c avrisp -b 19200 -U efuse:w:0xfe:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "0xfe"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.05s

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.02s

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

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

avrdude done.  Thank you.

michiel@arion:~>

Verification

michiel@arion:~> avrdude -p m328p -P /dev/ttyUSB0 -c avrisp -b 19200 -U efuse:r:-:h

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading efuse memory:

Reading | ################################################## | 100% 0.02s

avrdude: writing output file "<stdout>"
0xfe

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

avrdude done.  Thank you.

michiel@arion:~>

First sign of life

18419 MCO:SLP:WUP=-1
18429 TSF:TRI:TSB
Wake up - now minute 1

18456 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
18485 !MCO:SLP:TNR
20301 TSM:FAIL:RE-INIT
20314 TSM:INIT
20326 !TSM:INIT:TSP FAIL
20340 TSM:FAIL:CNT=3
20350 TSM:FAIL:DIS
20361 TSF:TDI:TSL
28495 MCO:SLP:MS=50000
28508 TSF:TDI:TSL
28518 MCO:SLP:WUP=-1
28528 TSF:TRI:TSB
Wake up - now minute 2

28555 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
28583 !MCO:SLP:TNR
30373 TSM:FAIL:RE-INIT
30386 TSM:INIT
30398 !TSM:INIT:TSP FAIL
30412 TSM:FAIL:CNT=4
30423 TSM:FAIL:DIS
30433 TSF:TDI:TSL
38594 MCO:SLP:MS=50000
38606 TSF:TDI:TSL
38617 MCO:SLP:WUP=-1
38627 TSF:TRI:TSB
Wake up - now minute 3

38653 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
38682 !MCO:SLP:TNR
40445 TSM:FAIL:RE-INIT
40458 TSM:INIT
40470 !TSM:INIT:TSP FAIL
40484 TSM:FAIL:CNT=5
40495 TSM:FAIL:DIS
40505 TSF:TDI:TSL
48693 MCO:SLP:MS=49999
48705 TSF:TDI:TSL
48715 MCO:SLP:WUP=-1
48726 TSF:TRI:TSB
Wake up - now minute 4

48752 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
48781 !MCO:SLP:TNR
50518 TSM:FAIL:RE-INIT
50530 TSM:INIT
50542 TSM:INIT:TSP OK
50554 TSM:FPAR
50565 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
50944 TSF:MSG:READ,0-0-255,s=255,c=3,t=8,pt=1,l=1,sg=0:0
50974 TSF:MSG:FPAR OK,ID=0,D=1
51691 TSF:MSG:READ,7-7-255,s=255,c=3,t=8,pt=1,l=1,sg=0:1
52606 TSM:FPAR:OK
52615 TSM:ID
52623 TSM:ID:REQ
52633 TSF:MSG:SEND,255-255-0-0,s=143,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
53245 TSF:MSG:READ,0-0-255,s=143,c=3,t=4,pt=0,l=2,sg=0:13
53276 TSF:SID:OK,ID=13
53288 TSF:MSG:READ,0-7-255,s=143,c=3,t=4,pt=0,l=2,sg=0:13
53319 TSF:MSG:BC
53329 TSF:MSG:READ,0-0-255,s=143,c=3,t=4,pt=0,l=2,sg=0:13
53360 TSF:MSG:BC
53370 TSF:MSG:READ,0-7-255,s=143,c=3,t=4,pt=0,l=2,sg=0:13
53401 TSF:MSG:BC
53409 TSM:ID:OK
53417 TSM:UPL
53428 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
53465 TSF:MSG:READ,0-0-13,s=255,c=3,t=25,pt=1,l=1,sg=0:1
53495 TSF:MSG:PONG RECV,HP=1
53512 TSM:UPL:OK
53520 TSM:READY:ID=13,PAR=0,DIS=1
53542 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
53581 TSF:MSG:READ,0-0-13,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
53614 TSF:MSG:SEND,13-13-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
53659 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
54272 TSF:MSG:READ,0-0-13,s=255,c=3,t=6,pt=0,l=1,sg=0:M
54306 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Door Window Button
54358 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:3.0
54403 TSF:MSG:SEND,13-13-0-0,s=1,c=0,t=0,pt=0,l=18,sg=0,ft=0,st=OK:DWB - Reed contact
54448 MCO:REG:REQ
54460 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
54499 TSF:MSG:READ,0-0-13,s=255,c=3,t=27,pt=1,l=1,sg=0:1
54528 MCO:PIM:NODE REG=1
54542 MCO:SLP:MS=54249
54554 TSF:TDI:TSL
54564 MCO:SLP:WUP=-1
54577 TSF:TRI:TSB
Wake up - now minute 5

54603 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
54630 TSF:TDI:TSL
54640 MCO:SLP:WUP=-1
54652 TSF:TRI:TSB
Wake up - now minute 6

54679 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
54708 TSF:TDI:TSL
54718 MCO:SLP:WUP=-1
54728 TSF:TRI:TSB
Wake up - a long period has passed.

54769 TSF:MSG:SEND,13-13-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:105
54810 TSF:MSG:SEND,13-13-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
54847 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
54876 TSF:TDI:TSL
54886 MCO:SLP:WUP=-1
54896 TSF:TRI:TSB
Wake up - now minute 1

54925 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
54951 TSF:TDI:TSL
54962 MCO:SLP:WUP=-1
54974 TSF:TRI:TSB
Wake up - now minute 2

55001 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
55029 TSF:TDI:TSL

First sign of life 2

104 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
165 TSM:INIT
172 TSF:WUR:MS=8000
188 TSM:INIT:TSP OK
198 TSF:SID:OK,ID=1
208 TSM:FPAR
251 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
456 TSF:MSG:READ,10-10-1,s=255,c=3,t=8,pt=1,l=1,sg=0:1
485 TSF:MSG:FPAR OK,ID=10,D=2
534 TSF:MSG:READ,0-0-1,s=255,c=3,t=8,pt=1,l=1,sg=0:0
563 TSF:MSG:FPAR OK,ID=0,D=1
1157 TSF:MSG:READ,7-7-1,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2287 TSM:FPAR:OK
2295 TSM:ID
2301 TSM:ID:OK
2310 TSM:UPL
2322 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2357 TSF:MSG:READ,0-0-1,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2385 TSF:MSG:PONG RECV,HP=1
2402 TSM:UPL:OK
2410 TSM:READY:ID=1,PAR=0,DIS=1
2430 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2467 TSF:MSG:READ,0-0-1,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2502 TSF:MSG:SEND,1-1-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
2545 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2580 TSF:MSG:READ,0-0-1,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2611 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Door Window Button
2658 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:3.0
2701 TSF:MSG:SEND,1-1-0-0,s=1,c=0,t=0,pt=0,l=18,sg=0,ft=0,st=OK:DWB - Reed contact
2744 MCO:REG:REQ
2756 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2793 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2822 MCO:PIM:NODE REG=1
2834 MCO:BGN:STP
Door Window Button 3.0 - Online!

2859 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
2902 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
2938 MCO:BGN:INIT OK,TSP=1
2955 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
Reed contact changed - now 1

3004 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
3033 TSF:TDI:TSL
3041 MCO:SLP:WUP=-1
3053 TSF:TRI:TSB
Wake up - Short cycle after REED contact change.

3096 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
3131 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
3158 TSF:TDI:TSL
Tags: domotica nodes
Comments: