The trigger to start this project was remarking, for the umpteenth time in the morning, that the door had been unlocked again all night.
Replacing the mechanical locks on the 4 doors by electric locks was out of the question, too expensive and the need for electric cables that were not present.
So, how to detect if a mechanical lock is closed?
The internet is an incredible source of ideas:
With this idea, let the bolt close a contact, I could use the standard window/door sensor node!
So I made my version by using springs I found in my junk bin mounted on a piece of wood, namely the wooden stick of an ice cream
My first prototype was working, but not really a piece of art
Remember to always drill holes because the wood of the stick splits very easily.
I did use battery springs for my other nodes, they are stronger and easier to use.
The battery-based windows/door sensor node : hardware
I had never built a battery based node before, so as a first step, I did read the site article on the MySensors site: https://www.mysensors.org/build/battery
Luckily, I already had Pro Mini's and enough RFM69HW radios in stock.
Today I know that I did probably the wrong choice by using the Pro Mini’s. They are good in low consumption, but a bare bone 328P used like in this topic https://forum.mysensors.org/topic/2067/my-slim-2aa-battery-node is still better...
But we will see how far these Pro Mini’s will take us on 2x AA batteries!
My first node was based on the idea to use the same enclosure as in the above topic. In Belgium these cable ducts are known under the name Legrand and I had a still a piece of more then 1 meter lying around, a surplus from the renovations.
Because I used a Pro Mini and not a bare bone 328P, I was obliged to use 2 covers of the cable duct instead of a cover and base. The base of the cable duct was not broad enough for the Pro Mini.
With the hardware tricks of the MySensor battery node site article on the Pro Mini, I could obtain a current consumption of 133µA in deep sleep (Modified Pro Mini, RFM69HW and the open contact).
To minimize the current with a closed contact, I did not use the internal pull-up resistor of the 329P (internal pullup resistor value around 30KOhm), but an external 1M ohm resistor. With closed contact and deep sleep, I have now around 136µA.
The battery-based windows/door sensor node : software
Besides the hardware modifications done at the Pro Mini, you can also do software modifications to save power consumption.
In the same topic https://forum.mysensors.org/topic/2067/my-slim-2aa-battery-node, the author @m26872 mentioned the use of a new bootloader with a 1MHz internal clock and a BOD (cpu brown out) disabled.
Today (2020-12-28) we can use the github project MiniCore https://github.com/MCUdude/MiniCore to program our Arduino Pro Mini with the new bootloader. See the readme of the project MiniCore on Github. It explains everything: the theory, the installation and the Getting Started.
After installing MiniCore, I used following configuration:
- board : ATmega328
- clock : internal 1 MHz
- BOD : BOD 1.8V
- EEPROM : EEPROM retained
- Variant : 328P / 328PA
- Bootloader : Yes (UART0)
I did not disable completely the BOD. Why? I did read on forums that the processor could write garbage into the memory when below 1.8V, so for safety’s sake, I did set it to 1.8V.
There are reports that using the Arduino Pro Mini at internal 1Mhz gives sometimes problems with the MySensors library. It was not clear to me if it was with the 1.x version of MySensors or the 2.x version, so I did take my chance and used 1MHz with the 2.3 version of MySensors. Till now, no problems!
You must program the bootloader with an ISP. I used my ‘Arduino as ISP’. See https://forum.mysensors.org/topic/11444/using-an-arduino-uno-as-isp-for-programming-5v-and-3-3v-boards-without-soldering-the-needed-connections
If your pro mini is already connected to the RFM69HW radio, D11, D12 and D13 are used as MISO, MOSI and SCK for the radio.
These pins are also used to program the bootloader.
This will affect each other. The ISP programmer will not be able to detect the device ID and will fail. You must disconnect these 3 lines from the radio module, the time to (re)program the bootloader.
You can find the used sketch at https://github.com/ericvb/MySensorsArduinoSketches/tree/master/sketches/ArduinoProMiniLockDoorBatterySensorWithEncryptionGithub
So in a nutshell:
- first program the bootloader via minicore (Arduino IDE : burn bootloader)
- download the sketch via your normal USB to TTL programmer using the rx, tx, dtr, gnd pins (Arduino IDE : Upload)
The battery-based windows/door sensor node : 3D printing enclosure
Because I had to use the cover of the cable duct as base for the Pro Mini, I decided to design a case with approximately the same dimensions.
The dimensions were dictated by the available space in the PVC door frame, the dimensions of the Pro Mini, the RFM69HW, the 2 AA batteries and the minimum possible printed thickness still solid by my 3D printer:
- Length : 200mm
- Width: 20mm
- Height: 17mm
You can find the design (open source FreeCAD) and STL files at: https://www.thingiverse.com/thing:4659402
The last months the thingiverse website has many problems, designs are not visible, 404 messages, etc.
Post a note if you don't find the 'thing'
The sensor is fastened with Velcro strips to prevent damage to the door caused by using fixing screws.
Via following links, you can find more information about minimal power consumption, bootloaders, etc.
Low power Pro Mini
Specific commercial hardware
https://www.canique.com (power efficient board with RFM69HW)
Use of bootloaders