I’ve been delighted with the results of my We’ve Got Mail project. Now we know when mail is put into our mailbox. Our mailbox is down the road from our house. There are days when my husband goes down and checks for mail delivery several times. A little exercise is a great thing. But some days it is cold, rainy, and dark.
NOT ANY MORE – when mail comes, the super-dah-dee-duper We’ve Got Mail home device starts to sparkle…a DEFINITE YIPPEE moment…It knows when to sparkle because the Mail Box Puck – which sits inside the mailbox – sends a message to the controller when the mailbox door is opened.
This can’t be seen in the image, but the top of the device’s enclosure is printed with translucent filament. When mail comes, the neopixel FeatherWing starts lighting up in a sparkle panel. There is a button on the left side of the enclosure that turns off the sparkling.
Thanks To Those That Went Before
I am very grateful for the knowledge, excellence, and practical use of:
- the RadioHead RF arduino libraries. These libraries have been the backbone of my radio projects. Well done. My only challenge is in power management with the m0 – getting to deep sleep requires waiting for an interrupt. My current challenge is the RF library takes over the interrupt I define for RF traffic. When I put the m0 in idle mode 2, I get the interrupt. When I put the m0 into deep sleep and wait for an interrupt, I don’t receive one. I should do more investigation. However, at this time I want to make progress on other project.
- Adafruit products and services. THANK YOU for the spirit of “We all do better when we all do better.” (see Al Franken’s book). For the RF95 feather, neopixels, their exceptional service, exceptional support, exceptional videos. From all I can tell employees are treated well. They care about each other and us. It would be SO AMAZING if more companies shared the “We all do better when we all do better” spirit.
- John Ericksen’s really nice neopixel sparkle sketch. It would take me a long, long time to figure out the graphics/math and put this together. John made this easy and shared it with us. THANK YOU.
- Tweaking4All’s also really nice Fire neopixel sketch. Same comments as with John’s work. THANK YOU.
- Jeremy Bloom’s tutorial on using hardware to debounce button input.
The two Arduino sketches I used:
The goal is to build a Mail Box puck and Controller that lets us know when mail has arrived. The Mail Box puck sits in the mail box. When the door is opened, it sends a notification to the Controller. The Controller is responsible for:
- receiving the message from the Mail Box puck.
- sparkling when it receives the message.
- turning off sparking when a button is pushed.
- Two Feather m0 with RFM95 LoRa Radio from Adafruit.
- PIR Sensor. I had one from back when I started learning about electronics + Arduino. Whoa – using it gave me a moment of reflection on how much I have learned since I started. I am incredibly grateful. I feel a sense of joy.
- One Neopixel Featherwing. I got one awhile back to play with. Imagine my excitement when this project came around!
- Button + hardware debouncing circuit (see below) + Featherwing proto + small piece of prototyping board (I ordered some of these to use with projects) to mount the button.
- White and Translucent PLA filament for 3D printed enclosure.
The Mail Box Puck
Thankfully, the RFM95 LoRa sends a strong enough signal to easily reach inside our house from the mailbox. The mail box puck is extremely simple (see GotMail_MB_V1.ino):
- The PIR sensor is hooked up to a GPIO pin.
- The first thing the loop() does is goToSleep() – i.e.: set the M0 into deep sleep mode, put the RF95 to sleep, and set the motionDetected interrupt to be called back when the GPIO pin assigned to the PIR sensor goes off. The GPIO pin will change from LOW/HIGH when the mailbox is opened. When this happens, the __WFI() happens, which plops the code into motionDetected().
- The bMotionDetected is set to true.
- When bMotionDetected is true and now the code is running below the interrupt in the loop(), a mail message is sent to the WeGotMail home device.
- The message includes the battery level.
The Controller uses the GotMail_Home_V2.ino code.
There are three Feather boards inside the Controller – a Feather M0 RFM95 LoRa, a proto FeatherWing, and a neopixel FeatherWing. This image shows the neopixel Featherwing connected to the proto Featherwing.
The RF95 code was easy because I was familiar with how RadioHead’s library worked after using it for my outdoor gardening project. I LOVE evolving what I have learned.
I grabbed the sparkle() routine from John Ericksen’s Multicolored Plasma for the Arduino Micro-Controller and NeoPixel Shield sketch. When a message is received from the Mail Box Puck with a battery reading <= 3.7, the sparkle pattern changes to flickers of red in the Fire() routine. I grabbed this code from Tweaking4All’s work and slightly modified it.
There is a button on the side of the enclosure that when pressed turns off the neopixels.
I hooked up a button I found lying around. Because I easily forget the basics, I decided to document how a simple button switch works.
Here is an image from an Adafruit tutorial that shows how a button switch should be wired:
// initialize the pushbutton pin as an input. Use INPUT_PULLUP // so that when the button is open, the digitalRead will be HIGH. pinMode(buttonPin, INPUT_PULLUP);
These two tidbits of information made it easy for me to wire up the button.
The two challenges I had were:
- realizing the best way to trigger an interrupt when the button was pushed was on the RISING or FALLING edge. Triggering on the HIGH or LOW reading returns many (many) readings. Yah. Obvious to you. I get it. (BTW: I thought Jeremy Bloom’s discussion on how interrupts work on the Arduino was excellent…)
- just getting one interrupt when the button was pressed and the interrupt was set to fire on RISING (or FALLING). AKA debouncing. The debouncing links shows how to do this when the code does not use a hardware interrupt. I’m glad it did because I didn’t know how to hardware debounce. Lucky for us, Jeremy Bloom has a tutorial discussing hardware debouncing.
I am using the NTE74HC14 Schmitt Trigger Inverter. I chose this one because our local hardware shop had it, making it easy for me to pick up.
The pins I used include 7, 14, 2, and 1. Pin 1 is input from the button push and pin 2 is output that goes into a GPIO pin of the Feather M0.
The Controller’s job is to hear a message from the mail box puck. When it does, it starts sparkling the neopixels. There is a button on the side of the box to turn off sparkling. When the battery level of the Mail Box Puck is <= 3.7V, the sparkling looks like red fire to symbolize the Mail Box puck’s battery needs to be recharged.
- Sparkle when a “We’ve got mail” message is received from the mail box puck.
- Stop sparkling when the button is pushed.
- Have a robust and attractive enclosure.
- Be available wherever we are within the house. In order to do this, the Controller will use a battery. The enclosure must make it easy to recharge the Controller through the USB port. The Controller should use minimum battery power.