For quite some time, my wife asked me to "produce something useful" instead of the projects I have been busy spending time and money on.
We live in an apartment building on the 3rd floor (4 for Americans) and our mailbox is next to the entrance together with the other 39 inhabitants. It's a full metal construction with an aluminum lid.
The distance is far exceeding a WiFi connection, so a LoRa connection should solve the distance issue.
Proof of Concept
I experimented with two of the E32 433MHz boards and quickly got that up and running using Arduino Nano boards, with two simple sketches. One acting as the sender and one acting as the receiver with an acknowledgement going back to the sender to turn on an LED. Powering the sender one with a Powerbrick, I ventured a few times up and down the stairs to the mailbox to see if I could get a reliable connection from within the metal enclosure, which I did.
Extending the Proof of Concept
In order to make this more reliable and practical, I wanted to put the sender contraption into deep sleep to conserve power, and waking it up somehow when mail got delivered.
I first tried to use an LDR that would function as a wake-up for the system. Unfortunately, my first attempts failed. I think this is because the mailbox itself it dark, and opening the lid and shoving mail through the opening did not provide enough of a light differential to use it as the trigger. This is unreliable because the postman or woman stands in front of the mailbox, blocking light and that in the winter period is another obstacle.
Besides, the circuit to recognize the opening of the lid by means of an LDR would have to be powered 24x7 and that would drain the battery cell.
It would have been nice nonetheless, because all the parts could be in one enclosure.
Alas, I had to find a different method, preferably one that did not use any power but would be reliable. So, the next thing I wanted to try was to use a magnetic reed switch, typically used for signaling doors opening. I ordered one, but it turned out to be too bulky for this application. The magnet piece would have to be connected to the lid by either glue or double sided tape because I can't drill holes anywhere. This bulky magnet part would be exposed to the outside when the lid opens, and it's too easy to get nocked off with bulky packages.
The next step was to try a smaller motion activated switch by a mercury droplet, which I found after some searching on Aliexpress. I knew about the existence, but looked for a really tiny one.
The glass bulb is 11mm long and has a diameter of only 4mm.
Using a different lid opening sensor
Vibration sensor
This is how they look on the inside: (I borrowed the picture below from Adafruit: https://www.adafruit.com/product/2384
I got the vibration sensor with the normal sensitivity and it is not working in this application. It needs quite a violent jolt to make contact, making it unreliable for the detection of the lid opening and closing. Maybe the more sensitive one works better?
I got the sensitive version, and tried that out. It indeed works a lot better, but have a look:
It produces a large number of these very fast pulses when you tilt it or tap it. For this project, that would still work, but it's not any more reliable or different enough to change it for the tilt sensor. It's more appropriate for a door or window sensor, registering a break-in attempt as an example.
Optical light sensor
I also got delivery of another optical sensor, the OPT101. Using a sensor that does not have to be fixed to the lid is a major improvement, because everything can then be built in one box, and there are no wires going to the sensor mounted on the lid.
I built a little prototype with it, and initially, it seemed to work very well, just waving my hand above it would activate it. However, when I put it in the carton shoebox that would mimic the letterbox, I did not get enough light on the sensor to make it work. It's not sensitive enough for this application, even though I increased the gain.
Optical PIR sensor
I also ordered a small IR motion detector, I saw it was used in a mailbox alarm project where the designer sold his result. It uses one of these small sensors.
When I tried it, it worked very well, even within the concocted shoebox replacement, but as I already feared, it only reacts on Infra-Red generated from warm bodies. In other words, it will only work when the postman puts a bare hand for the opening, but it does not react on any light. This will be a very unreliable detector for my particular mailbox. It may be better suited for the US mailboxes that have a much larger opening. I had high hopes for this sensor, but alas...Tilt switch
The tilt switch I also found while searching for alternatives is so far the best replacement for the mercury switch I'm currently using. As you can see in the picture that I borrowed from Adafuit (https://learn.adafruit.com/tilt-sensor/overview), it uses two balls that roll around and make contact when the device is up-right. Same as the mercury switch.
The ones I ordered arrived and seem to work fine. I will replace the Mercury switch that is currently taped to the letterbox lid with this one soon.
Changing the processor
I had a few issues with putting the Nano to sleep, and waking it up. Also these boards are a tad too large to my liking as well, so I switched to the ESP8266 based WEMOS D1 boards. I use a number of them in my home, measuring many environmental "things" and I always have a number in spare to play with. They have enough available pins to interface to the LoRa board and they can be put into a deep sleep mode with one instruction, while they wake-up when the RST pin is momentarily pulled low.
I'm using a clone of the WEMOS D1 Mini, the GY-D1MINI. The major difference is that it uses a SCP2104 USB to UART bridge, instead of the CH340C, which calls for another USB driver on your PC.
Unfortunately, although there are many variations and models, I have not been able to find a schematic for this particular board.
The proof of concept prototype
To keep an eye on the Lipo cell voltage, I use the on-board ADC to measure the cell voltage. I used a 120K resistor that works together with the on-board attenuator to keep the voltage within the ADC range.
To get a more reliable communication, the sender sends a text message that it has detected mail. This message gets verified by the receiver after it than sends an acknowledgement. The sender waits for the acknowledgement, but if not received after a short period, it sends the "I got mail" message again, up to 5 times. After receiving the acknowledgement from the receiver, it would also measure and send the cell voltage to the receiver. On the receiver side, I use an LED to signal a low voltage, set at 3.4V. Reading the cell voltage just after activating the LoRa board, which uses about 100mA while transmitting, ensures that the cell is at the lowest level when I measure it, although the voltage will creep back up a bit when the circuit is put to sleep again.
This worked really well until I did not get any alarms anymore. It turned out that the so called 500mAh Lipo cell drained before mail arrived so I did not get the low battery warning. Bummer! At that time, I set the cell voltage warning at 3.4V, but later I figured out that this was way too low. Due to the voltage drop over the 3V3 regulator, an ME6211 with 260mV dropout, it very well could have resulted in a voltage for the ESP8266 and the LoRa board that was below 3V, at which level they stop working reliably or at all.
First of all, the 500mAh cell capacity was inadequate to begin with, but it is what I had. I had measured the two cells I have several years ago and they showed to have a capacity of only 274mAh and 260mAh.
Because I used the on-board 3V3 regulator on the WEMOS D1 mini, by the time the cell produced less than 4V, the 3V3 voltage regulator started to drop the voltage, so I did not get much of a useful capacity to start with. I knew that, so I ordered two new LiPo cells with 2000mAh capacity. When they arrived I put one into the letterbox.
This graph was generated by my DC Dynamic Load in the Battery Test mode. That recent design is described elsewhere on my Blog. It shows a couple of things. First of all the discharge curve was made with a constant 200mA (1/10th) of the rated 2000mAh for the cell. The measurement shows that it's not quite up to the specification at 1889mAh, but close enough. It took 9 1/2 hrs to discharge it from fully charged to the 3.0V cutoff setting. The sender circuit should draw about 20uA when in deep sleep, and about 100-150mA when the LoRa module is transmitting for a few seconds.
I installed the prototype board into a small enclosure and taped it to the inside of the letterbox with double sided foam tape and used two thin wires that went to the mercury switch that I taped to the lid. I also mounted a small connector to be used for the LiPo cell such that I can replace it without opening the enclosure. The cell is also taped to the side of the letterbox.
This prototype is working really well for a few weeks now. They major issue is that normally, I do not get a lot of mail. There may be days without any. The cell voltage only gets send to the receiver when there is mail, so there is too much of an opportunity that the cell gets depleted before I get mail and I'm unaware of this. I need to find a way to avoid that.
The receiver
The receiver basically has the same ESP8266 and LoRa module, but the circuit is enhanced to give audible and visual information. The receiver is located in the apartment where we can hear it beep, see the LED's and reset the alarm.
This circuit is powered by a 5V USB wall wart connected to the WEMOS D1 mini micro USB input connector. There is a beeper/buzzer that will activate when mail is received and it will beep 5 times. An LED is turned on so you also have a visual indication that mail is received.
You can reset the alarm by a push button.
Another LED will be turned on when the receiver is notified that the LiPo cell in the receiver module is below the cut-off voltage, I currently have that set at 4V or below.
I'm actually actually using the ADC input to measure the activity of the reset switch, because I can out of digital inputs. The D4 pin is connected to the on-board LED, so I don't want to use that.
At this moment, I'm programming the LoRa module with the standard configuration parameters at boot-up, because I have no other LoRa transmitters nearby.
The parameters that I currently use for both devices are:
Adrs=0, Ser=8N1, 9600bd, Air=2.4Kbps, chan=23 and pwr=20dbm.
Enhancing the sender prototype
I needed a low voltage alarm for the LiPo cell that would wake-up the system and send a distress signal apart from the mail alarms. That took a bit more time to design, because the RST wake-up signal must be a momentary low, not a permanent one. So although I started out with a very simple low voltage indicator, testing showed that I needed a bit more logic to create a more reliable and correct wake-up signal to kiss it out of the deep sleep.
Below is the updated but still evolving schematic.
Using a LiPo cell to supply power
Supplying the +5V input?
Supplying the 3V3 input?
Using the LiPo with a different supply option
Eliminating the USB 5V back feeding into to the circuit
The 5V comes in through the USB connector and is fed through a Schottky diode (D2) to prevent back-powering the PC when you apply 5V directly to the WEMOS board. (BTW, I have never seen the 500mA fuse used on all the different boards I have).
Using an external voltage regulator
Current consumption analysis
Protection fuse
Reverse Polarity Protection
Rail buffering
Obviously, this is with the prototype on proto-board, which is notorious for poor connections, but still...
The above schematic is what I used to the create a PCB. It has the optional MCP308 voltage supervisor chip that can be used instead of the TS881. Note that I'm now using the WEMOS D1 mini V4 with the flipped pinout because it has the lowest current consumption. Other WEMOS D1 boards can still be used when they are mounted upside down.
Conclusion
I will add more soon... Stay tuned...
As usual, I will create a GitHub project that will have all the details when I'm satisfied that the hardware works.
If you like what you see, please support me by buying me some Java: https://www.buymeacoffee.com/M9ouLVXBdw
For those that already did, thank you!
2 comments:
An alternative to the fragile dangerous mercury switch is a vibration sensor switch. It's basically a spring surrounding a pin inside a tube that resemble a capacitor. When it moves, the coil makes contact with the pin. Adafruit sells them.
Thank you, your are right, of course, but I was not aware of this device. I ordered a few to test.
Post a Comment