Introduction: IoT Beacon - Notification Receiver and Trigger
In this instructable we'll walk through making a battery powered Pi Zero W based notification receiver and trigger, connected to IFTTT through Adafruit.io. This walkthrough covers the hardware, the software for this project is an ongoing project on github at https://github.com/jeffdepascale/IoTBeacon.
- Raspberry Pi Zero W
- 4.4x2.4x1 inch (or larger) project box Amazon link
- USB audio adapter This one from Sabrent works well
- Adafruit PowerBoost 1000C
- 1000-2500mAh battery - 2500 is the biggest that will fit this box
- An RGB led, either common annode or cathode Here is the one i used
- Mono amplifier
- USB OTG adapter
- 16x2mm 10K Ohm pot
- momentary button I used this one
- power adapter Like this one
- power slide switch, something like this one
- 4gb or larger microSD card
- Optional: I had a spare powerstrip PCB that I used, helpful for wire management but not required.
- Optional: ferrite beads
- Soldering iron
- hot glue gun
- Xacto knife
- Kapton tape
Step 1: Prepare the Pi
Head over to github and check out the project. I'll cover configuration and setup over there, as it will change over time. Prepare the SD card, put it into the pi and fire it up. double check that your pi, and the image, are working. Note that the service will not be running, as you haven't wired anything in yet, so it will fail out because there is no usb audio and no gpio connections. We'll get there in the next few steps.
Step 2: Wire Up the Audio
You can go either the GPIO PWM audio route or the USB audio route. I went with USB here, its cleaner audio and generally easier as well, bypassing the necessary filter build for PWM audio, so that is what we will cover here. With USB, there are a few gotchas to look for in the steps below. The reference photo above shows the POC version breadboarded, which includes the usb audio bare board (connected temporarily by a USB OTG cable), amplifier, and a temporary speaker.
Connecting to the Pi
It has been my experience thus far with the Pi Zero W that the wifi radio causes interference with the USB data test pads, rendering them unusable. I've confirmed this on two separate zero w boards myself, and see this link for some more detail. I may be wrong, or they may improve this with a rev, but as of right now, I highly recommend using that USB OTG cable I recommended for the parts list, but you'll need to gut it to fit it in the case. carefully disect it with the Xacto knife, being careful not to cut the interior wiring, removing all of the sheath so you are left with a bare usb plug and the wires hanging off of it. Hot glue the remaining nub where the wires connect to the usb plug to give them a little rigidity.
Prepping the usb audio adapter
If you went with the Sabrent adapter, there is a good amount of detail on this at the Sudomod link above, which covers it in regard to the gameboy zero project i discovered it in. To open it, carefully either slice in, or squeeze it with wire cutters to crack the outer casing, then separate it. The sabrent adapter has lots of room above the pcb on the inside, the PCB sits flush with the bottom of the casing. pop the plastic and remove the hot glue globs holding it in. Use your soldering iron and flat cutters to remove the USB plug from the board so you have 4 exposed solder pads. Fully remove the microphone (pink) analog jack.
VERY IMPORTANT! - When soldering the usb audio adapter, remember this PCB is not meant for DIY. These solder pads are very sensitive. It is recommended typically to desolder the audio jack and then solder to the pads, but it is very easy to rip the pads off the board, so given we have the room in this case, I recommend leaving the jack on and using it as your solder point.
Solder the cut up USB OTG cable to the adapter. Remember that the wiring order for USB is, from left to right on the PCB with the audio jack facing up, black, green, white, red.
Solder the audio wires to the pads on the audio jack. I connected the L/R into one signal with a piece of jumper wire first. Refer to the diagram on sudomod for wiring, but basically if you still have the pcb oriented audio jack up, you will solder the right side of the jack, the three pads going up the side are R, L, and ground respectively.
Connecting the amplifier and volume pot
Connect the audio wires to the amp inputs, prep solder power and ground, and connect the speaker to the amp with the pot wired in the middle. On the pot, 1 is ground and 2 and 5 are in.out. If you have ferrite beads, add them to the speaker wire before soldering.
Step 3: Power!
Prep the PowerBoost by connecting 5V and ground wires to the output (where the usb jack would go). Solder two additional wires for EN and GND connections for the switch, and wire in the switch. For the switch itself, solder either wire to a common (middle of the switch) post, then solder the other wire to the post on the side you want to be the off position.
If you are using a powerstrip PCB, connect the 5v/GND wires to it. If not, you can also use some spare perf board and solder the 5V wires and grounds together. Either way, we are making a distribution block. There are only three wires for each of 5V and GND, so not a huge deal if you dont have a powerstrip. I had it lying around and make changes easier when finalizing a build, so i used it.
Connect wires from here to the pi power test pads (these are on the reverse side of the board behind the power usb port, the one closest to the edge of the board is ground, the one next to it is 5V. If you are using a pi zero non W (in which case, have fun with the usb hub and wifi adapter and squeezing that in!), these will be labeled PP6 and PP1, respectively. They removed the labels on the Zero W for some reason. Connect the power wires from the amplifier to the block. Add one more ground wire for the push button ground and leave it loose for now.
Test it out - plug the USB OTG cable for the audio into the usb port, and plug in the battery and wall jack (if your battery isnt charged) and make sure the pi powers up. Follow the instructions on github for setting usb audio as your output device. If it shows up, you know you've at least got the usb part working. We'll cover testing audio playback after we wire up the GPIO pins. After you are done, pull the power and battery before proceeding.
Step 4: GPIO Wiring
The config details on github talk about defining GPIO pins in the software, so you can choose whatever valid GPIO pins you want here. For common anode RGB LED, wire in three wires for R, G, B respectively, plus one more wire for the push button. Wire the common anode from the LED to the 3.3v pin. connect the three color grounds to their respective leads on the LED. Connect the button wire to one side of your switch, and connect your spare ground from the last step the other.
Test - power it back up, and this time, if all goes well, you should see the LED light up briefly when the service starts. If configured correctly, the hardware should now be wired up enough to not cause software faults. Following the how to on github, you can now test pushing to the device, and triggering from it. This is a good place to test that your audio is working as well.
Step 5: Box It Up
You can technically do this much earlier in the process if you choose to do so, and glue parts in as you go, your choice. If you are using the same box as me, you'll need to notch out the bottom tray for the usb power. the edge of the PCB should sit flush with the trim ring, you can see it in the photo above. Also add notches for the volume pot and power switch. The upper half of the case will need to be notched out correspondingly to leave room for the usb plug, volume, and switch. On the top, cut a hole for the button (if you are using a round button, this step drill bit will give you a nice clean hole. Cut slots for the speaker grille and notch out a spot for the LED to pass through.
Inside the box, glue in the parts. In the image above, from left to right I have wired in the usb audio PCB, the amp, the powerstrip, and the PowerBoost. Opposite side on the base is the location of the volume pot and the power switch. Apply kapton tape across all of the devices on the bottom layer to avoid shorts. Kapton tape the bottom of the pi now too, we will be placing the battery beneath it, so better to take precautions here to avoid any possible shorts. Also, make sure you have trimmed the leads on the back side of the pi from those GPIO connections. a sharp wire point could poke your battery, which could be very dangerous. Triple check for sharp points.
In the top of the box, glue in the LED, and the speaker (against the grille slots, be careful to not glue the speaker cone, just the edges).
For the button, I found creating a stack of perf board built up with hot glue, placed on top of the PowerBoost, allowed me to put this where it needed to be. Do your best to line up the button to the top hole, test, test, test the fitting, and glue it down.
Step 6: Close It Up and Put It to Work!
That's it - slot the battery beneath the pi, carefully close the box together, screw it tight, plug it in and turn it on. Follow instructions on github for configuring alerts and triggers, and enjoy!
We have a be nice policy.
Please be positive and constructive.