This project shows how to build an Alexa-enabled smart smoke alarm that can detect flame, dangerous gases (including smoke) and temperature. It also has a led light ring that is used both as an alarm indicator, emergency/convenience lighting, and status indicator. A user can ask Alexa to give the location and type of alarm ("Alexa, ask smart smokes which alarm is going off?"), silence a specific alarm ("Alexa, ask Smart Smokes to tell Alarm one that I'm just cooking!"), check the temperature at a particular alarm ("Alexa, ask smart smokes what's the temperature at alarm 1?", and turn on and off the emergency/convenience lighting ("Alexa, tell smart smokes to turn on the emergency lights) .
Once you get through this project you'll see that adding further features, sensors and tricks to the Smart Smokes platform is fairly simple and limited only by your imagination. You'll also find that the final product is significantly cheaper and more flexible than a store bought smart smoke alarm.
OVERVIEWThe Smart Smokes system is made up of a base station and up to six smoke alarms (hereinafter referred to as "smokes" or "nodes"). The base station is built around an Arduino Uno receiver, which can communicate simultaneously with up to six smokes using the venerable nRF2401 transceiver.
Integrating Alexa starts with creating an Alexa Skill on the Amazon Developer Website. The Alexa Sill then communicates with a Raspberry Pi 3 equipped with a little Python program that uses package called Flask-Ask. Flask-Ask is Python framework created by John Wheeler that you can install on Python "that makes building Alexa skills for the Amazon Echo easier and much more fun." Thanks John Wheeler! The Pi3 then talks with the Arduino base station through the serial port. Easy Peasy.
We'll start with building a smoke and a base station. Once we get them talking, we'll install the smart smokes Python program on a Raspberry Pi 3 and plug it into the base station. Lastly, we'll head over to Amazon and create custom Alexa Skill and test some voice commands. Let's start with the smoke.
STEP 1: WIRE UP THE SMOKEFirst get your 3d printer going on the Smoke Top and then the Smoke Body and Smoke Base of the smart smoke in that order because you'll need the Smoke Top first Now, fire up your soldering iron and mount your Arduino Nano into two parallel, fifteen-pin, female headers on a 40x60 prototype board. Then mount a twenty-pin male header on one side of the Nano and a two by four (2x4) female header on the other side. Here's what mine looked like:
Now we start connecting all the jumper wires. For your reference, here is the big picture idea on a breadboard schematic:
Let's start wiring in the jumpers for the nRF24L01. The two by four (2x4) header will be used to connect the nRF24L01 to the Nano. I wired it using jumper wires from the two by four (2x4) header to the Nano on the the bottom of the prototype board. Here's the pinout for soldering your jumper wires:
Next, we'll prepare the twenty-pin male header for all the sensors by connecting jumpers from the header to the Nano on the bottom of the prototype board. Here's the pinout for soldering your jumper wires from the twenty-pin header to the Nano:
Finally, wire your power source to the Nano Vin and Gnd. (Note: I did use a 9V battery, but this project chows them pretty quickly. I would recommend a 5v regulated supply instead.)
Here's how it all looks on the bottom of the prototyping board when I was done:
The closest header to you in the picture is the two by four (2x4) female header, then the Nano pins, then the twenty-pin header is farthest away. I know . . . its impossible to tell what is really going on, but I want you to see what I meant by using jumper wires on the bottom of the prototype board. Look at the other schematics to direct you as to what goes to where.
Now, let's use longer hookup wires to start connecting our components to the headers. Again, let's start with the nRF24L01 transceiver. You'll notice in the schematic (Figure 2) that I wired in a 3.3v power supply to the nRF24L01. Why not just hook this up to the 3.3v pin on the Nano? The reason is that the 3.3v pin on a Nano does not have sufficient current to power the nRF24L01 at anything over the minimum power setting. A convenient solution to this is to buy the nRF24L01 with some breakout boards that have a built in regulated 3.3v power supply with sufficient current. Then you just connect the power on the breakout board to the 5v pin on the Nano, which has plenty of current to handle various power settings on the nRF24L01. Here's a picture of the combination I used, with the breakout board on the top and the nRF24L01 on the bottom:
And here is the nRF24L01 plugged into the breakout board:
After you plug the nRF24L01 into the breakout board, just use some male to female hookup wire to hook it into the header. Then secure the header connections and protect the nRF24L01 with some shrink tubing as shown here:
And here is the nRF24L01 attached to the two by four (2x4) header:
Next, connect each of your components to the twenty-pin header as shown in Figure 2 and Table 2. When your done it should look something like this:
My cheap way of doing a header is to protect the connections with shrink wrap. You can see the 5v header is on the right, which I created by laying a solid piece of 22 gauge wire across 5 pins, soldering them together and then connected the pins to the 5v on the Nano with a jumper wire. I used the same process for the GND header on the left. The four open pins are not connected to anything, which corresponds to Table 2 above. Ok, tough part is done. Now let's go check on the 3d print.
STEP 2: MOUNT THE SENSORSWhen your 3d print of the Smoke Top is done you should have a print that looks something like this:
To prep the top for mounting, you'll want "tap" the existing9 holes in the mounting pillars for the gas sensor and the active buzzer shown in Figure above. Really, it is not necessary to use an actual tap because the 3d printed part is forgiving. I just used 5/64 inch drill bit (or roughly 2mm) and found that short M2.5 screws held pretty well.
Now you can start mounting your sensors on the Smoke Top. Mount the Neopixel 12 first by gently pressing it in the ring. It should clip in without too much pressure as shown here:
You'll notice I put a couple blobs of hot glue around the edges just to be sure the led ring stays put.
Mount the flame sensor on the vertical plate so that the actual IR Sensor protrudes through the provided hole in the Smoke Top. Then put a M3 screw through the holes in the flame sensor and the vertical plate. Put a nut a nut on the M3 screw to hold it in place. Like this:
Next you can mount the active buzzer with 2 M2.5 screws in the pillars so it is centered over the hole in the Smoke Top mount like this:
Mount the gas sensor over the grate with at least two M2.5 screws in the pillars, like so:
You can also see on the left of Figure 11 above that the temperature sensor (TMP36) should fit nicely through the 5mm hole in the Smoke Top. If you need to, you can bore it out with a 5mm drill bit. Then put the thermistor through the hole and put a little dab of hot glue over it to hold it in place. After everything is in place, flip the Smoke Top over and make sure everything is lined up, like this:
On the bottom you can see the active buzzer, on the top you can see the temperature sensor, on the right the gas sensor is barely visible through the grate, on left the IR sensor is poking through, and of course the Neopixel ring is in the middle.
STEP 3: ASSEMBLE THE BASE STATIONNow on to the base station, which is considerably simpler. All we are going to do is hook up an nRF24L01 radio to an Arduino Uno as shown in this pinout and schematic:
Now we will want to upload the appropriate sketches to our base and smokes, but first let's set up the Raspberry Pi 3 so we can use it to upload these sketches.
STEP 4: PREPARE THE RASPBERRY PI 3First thing you'll want to do is get your Raspberry Pi 3 fired up and install a fresh Rasbian image. I did this using NOOBS. Click here for instructions on installing NOOBS. Makes sure you select the Raspbian Operating system in the NOOBS setup. (Don't forget to change your keyboard to United States if that's where you are located)
(Note, that you could use any number of computers or operating systems to communicate with the base station. I used a Pi 3 because my mac was giving me fits with security settings. Also, note that this tutorial uses Python 3.)
First you'll want to make sure you have your Pi3 connected to the internet. Click here to see the documentation.
Now, open a terminal and enter the following commands.
sudo apt-get update
sudo apt get upgrade
sudo apt-get install arduino
Each of these commands is separate and the Upgrade command will take some time to complete. Be patient. The third line installs the Arduino IDE, which we will use to upload the sketches to our base station and smokes.
Now you need to download a couple of Libraries for the Arduino sketches to work. First let's get the libraries to operate the nRF24L02.
Download the nRF24L02 library here:
Scroll Down to here and click Download as indicated in figure 17:
After the download is complete, you will have a file named RF24-master.zip in your home/pi/downloads directory. Extract the file to the downloads folder. Then rename the extracted folder to "RF24". You're downloads folder should look like this:
The red arrow is pointing to the RF24 folder. Now you want to add the RF24 folder to your Arduino library by opening applications menu selecting the Arduino IDE, then clicking on Sketch ---> Import Library--->Add Library:
Once you click Add Library, navigate to your home/pi/Downloads folder, open the RF24 folder, and click OK as follows:
Now go back to your Arduino IDE and check that the library was properly added by selecting Sketch-->Import Library. You should see RF24 down at the bottom of the menu like so:
Now do this same process for the following two libraries:
- "Ellapsed millis" library: Download, and extract into a folder named "ellapsedMillis". Documentation here.
- Adafruit Neopixel Library: Download, and extract into a folder named "Adafruit_NeoPixel". Documentation here.
Please note, that without exception, when you extract the above .zip files, they will be placed automatically in a file that has the appropriate folder named followed by "_master". Just erase the "_master" and your folder will be named correctly.
STEP 5: UPLOAD THE ARDUINO SKETCHES
You should now be ready to compile and upload the sketches. There are two Arduino sketches included in the downloads section of this tutorial: SmartSmokesBase.ino, which gets loaded into the base, and SmartSmokesTx.ino, which gets loaded into each of the smart smokes alarms.
Let's start with the base. Download the SmartSmokesBase.ino and open it up in your Arduino IDE (Arduino may ask you to create a folder of the same name. Just say yes). You should have this on your screen:
Now plug in your Arduino Uno Base we created in Step 3 to one of the USB ports on the Pi 3. Check that your Tools-->Board is set to the "Uno" and that "Tools-->Serial Port is set to the Uno (mine is dev/tty/ACMO, but yours may be different). Here's the screen shots:
If everything looks good, then click "verify" then "upload". If everything goes smoothly, your Arduino IDE status bar should say "Done Uploading." Now click on the serial monitor. These three steps are shown here:
Once your serial monitor is open, entER "1" in the dialogue and press "send." You should get back a "999." This means the base station is monitoring the serial port for incoming messages. Here's what you should see:
Ok, if all that went well, its time to move on to uploading software to your smokes!
This is almost the exact same process as uploading to the base station, with one important difference. We need to slightly modify each upload of SmartSmokesTx.ino to correspond to each unique smoke or node. Download the SmartSmokesTx.ino and open it in the Arduino IDE. Look at the code and notice a line that says "#define WHICH_NODE 1:" (the one in figure 27 below says WHICH_NODE 3)
You must change this number to a number between 1 and 6 to correspond with each smoke alarm or node. So for example, if you only have two smokes, then for the first you would designate WHICH_NODE 1, save the sketch, and then upload the sketch to your smoke. Next, designate WHICH_NODE 2, save the sketch, and upload to your second smoke. That's It! Go ahead and upload your Arduino IDE to your smokes. For this project I only created two smokes, just as described in this paragraph. But you could do up to 6 smokes.
Once you have uploaded your software, go ahead and take any normal lighter and squirt a little butane right into the grate that covers the gas sensor as I did in the demonstration video. You should get a loud beep and red lights as shown in the demo video.
Keep in mind that your smoke will act funny when you first power it up. It may beep and indicate an alarm. This is because the the gas sensor has a element that must heat up before it can read correctly. When the gas sensor is cold it gives a false alarm If you look closely at the code you'll see I tried to account for this warmup period, but it was still a little buggy when the deadline was up for this project. Something to keep working on . . . in any event, after the gas sensor warms up the smoke will operate normally.
If your smokes work, then its time to go on to configuring Alexa to talk to your Smart Smokes system.
STEP 5: INSTALL FLASK-ASK
Installing flask ask is very simple, just open an terminal on the Raspberry Pi 3 and type the following command .
sudo pip3 install flask-ask
Answer yes when asked to install.
STEP 6: INSTALL NGROKFollow these instructions to install NGrok (thanks again to John Wheeler):
Click here to the ngrok client for your operating system. Make sure you choose the Linux (ARM) version if your using the Raspberry Pi 3:
- Unzip it to a location you can remember. (I just extracted mine in the /home/pi/downloads folder)
- Open up a new terminal, cd into the location, and enter:
./ngrok http 5000
The terminal should now look something like this:
Write down the bottom most "Forwarding" address. In Figure 29 above it is https://a1409a8.ngrok.io. Yours will almost certainly be different. Save that address for later and leave the terminal open. If you close the terminal, then you close the ngrok session and Smart Smokes and Alexa won't be able to communicate. Now let's move on to configuring Alexa.
STEP 7: CONFIGURE THE ALEXA SKILLFirst you will need to register for an Amazon Developer account. Click here to go to the registration page. Once you'v registered, sign in and the screen should look something like this
Now, click on the Alexa tab as indicated by the red arrow in Figure 30. The next screen should look something like this:
Now, click on the Get Started button under "Alexa Skills Kit" as represented by the red arrow in Figure 31. The next screen should look something like this:
You'll note in Figure 32 that I already have a skill named "smart smokes." That's because this is my account. You'll want to create this skill in your account. Do so by clicking "Add New Skill" as indicated by the red arrow in Figure 32 above. The next screen should look something like this:
Make sure your screen looks like this one, including, clicking the "Custom Interaction Model" radio button, entering English as the appropriate language, and using "smart smokes" as both the skill name and the invocation name. Now click Save, as indicated by the red arrow above. The next screen will look something like this:
Click Next, as indicated by the red arrow above. The next screen should look something like this:
Now you are into the meat of the skill: the interaction model. This is where you put together your intents, slots and utterances. There are many good tutorials on building a interaction model. I'm just going to cut to the chase and suggest you just copy my code so we can get this thing built. You can go back and play with the interaction model later. So click on the "Code Editor" button as indicated by the red arrow above. You should see this screen:
Now, you'll see the screen above. Go ahead and drag and drop the InteractionModel.txt file included in the code section. If it works, your screen should look something like this:
Keep in mind, that the stuff on the left side of the screen in these shots will probably not show up on yours. Again, this is my existing skill, and I am just backtracking through it for instruction purposes. But the code in the main editor should look the same or very similar to what you see above. If it does, then click "Apply Changes", then "Build Code" (this one will take awhile), then "Save Model".
Now the model is built, so we can configure it. Click "Configuration" (as shown above). You're screen should look as follows:
This is where we tell Alexa where to send the instructions to operate our skill. In this case we want to click the HTTPS button and then enter the NGROK address that you saved above in step 6. The Ngrok address you see in Figure 38 above is just an example. You must enter your own from Step 6. Scroll the screen down and you should see this:
Fill out the remainder of the screen as shown above. Most, if not all, should be default values. Then click next as shown above. Now you should see this:
Click on the radio button corresponding to "My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority." Save if necessary, then click "Next", all as indicated above.
Congrats! You're ready to test the skill.
STEP 8: TESTING THE SKILLDownload the SerialChooser.py program and run it in your Python 3 IDE. This video shows how to do it:
And here is a full demonstration of most of the capabilities of Smart Smokes:
Lastly, you can also get the current temperature from any particular node by asking "Alexa, tell me the temperature on Node ___." Enjoy!
Comments