We’re giving away 1,500 DJI Tello drones. Enter to win ›
By J Steven Perry | Published February 28, 2018 - Updated February 28, 2018
Home automation is everywhere!
But just what is home automation? One thing I learned while I was doing this project is that there are numerous definitions of the term “Home Automation.” To me, it means using IoT technology to remotely control tasks in my home that I would normally perform manually.
For example, instead of walking up to my living room lamp, reaching out with my hand, and turning it on, I can turn the light on and off from anywhere I have access control, whether that is using a panel somewhere in my home or on my computer, or from half-way around the globe using my smartphone.
That definition sounds neat, but, in practice, a home automation system is a complicated symphony of components from different manufacturers that must be choreographed to perform the functions of the system. The components must understand a common set of protocols — for this project, just one, OOK/ASK encoding that uses the 433.92 MHz frequency band — in order to be controlled, report status, and in general be a part of the home automation system as a whole.
One major complaint about the current home automation landscape is that the various devices are “fragmented.” Typically, devices are from different manufacturers and often speak different protocols. These differences cause headaches for home automation system integrators who must deal with the question of how to stitch these fragmented components together to provide a good homeowner experience.
While I won’t really go into this issue per se, you need to be aware that when you purchase IoT devices that they might not play well together. So, I carefully chose the devices for this tutorial because I tested them myself and I know that they all work together. Be sure to follow the instructions carefully, and unless you know what you’re doing, don’t deviate from my Parts List in this tutorial.
In this tutorial, most major sections start with a short video (< 7 minutes), in which I demonstrate the concepts of IoT devices. The text of the section contains the detailed explanations and figures that explain the concepts I’m trying to convey in that section. Where it makes sense — and so the text in the section flows better — the video will be at the end of the section. The point is that this tutorial contains text, figures, and video, which are all woven together to try to immerse you in the technology so that you have the best possible learning experience. I hope I have succeeded.
You will build the skeleton of a remote control system, not a complete home automation system. But, when you’re done with the project, you will be equipped with the knowledge (and hopefully the drive) to take it further if you choose.
The project that you build will control a set of IoT devices, including:
You will control both of these IoT devices from an Android smartphone that is running the Android operating system (or through the Android emulator if you do not have an Android smartphone).
The hardware components of the system are:
You’ll set up the hardware in this part of the tutorial series.
The software components of the system are:
You’ll set up all of the software in Part 2 of the tutorial series (except for Raspbian Stretch, which you will set up later in this part of the series).
Last (but definitely not least) is the IBM Cloud service (Watson IoT Platform) that you’ll use to securely connect your home automation platform and the various devices connected to it (the “things”) to the internet.
By using the Watson IoT platform, you can securely connect your Raspberry Pi to the internet and control it all with the magic of Message Queue Telemetry Transport, or MQTT (okay, it’s not magic, but it is very cool, and an ISO standard).
I’ll show you how to define the API key that the Android application needs and the device ID for the Raspberry Pi. I’ll also show you how to connect the Raspberry Pi that is running your home automation system to the Watson IoT platform. Then, I’ll show you how to control the home automation system through the Android app both from your Android device and from the Android emulator.
You’ll see how to connect the home automation system through the IBM Cloud to the Android app in Part 3 of the tutorial series.
I love DIY projects, but there’s nothing more irritating to me than working on a really cool project, only to find half-way through that the author didn’t use the parts depicted in the illustrations, or worse, is using parts that are no longer available!
All of the parts in this list are readily available from Amazon.com, and I used them myself in this project. You can substitute parts if you have issues getting them from Amazon, but try to stick as closely as possible to the parts list below, or you might run into trouble.
Below you will find a table where you will find the same parts that I use in the project. And, like I said, all of the parts are available from Amazon, so you should be able to order them from pretty much anywhere in the world.
Project cost (estimated): 125 USD.
Consider these notes about the parts in this parts list:
One final note: I’m assuming that you have a USB keyboard and mouse, and an external display that uses an HDMI connector. You will need these components in order to work with the Raspberry Pi. If not, check out this video that shows you how to do a “headless” setup of your Raspberry Pi, which means “you control it from over the network.” However, you will need an Ethernet cable to do the initial installation.
Now that you have the parts that you need, it’s time to set up your Raspberry Pi 3, which will control all of the devices in your home.
Grab the 16 GB micro SD drive (part #6), and get ready to install (or flash) the Raspbian OS image on to it. After that, you’ll insert the card into the micro SD slot on the Pi, connect an external monitor, keyboard, and mouse, and boot the Pi up for the first time.
Don’t like boring text and screen captures? I get it. How about a video instead? Or, why not use them both?
If you’re familiar with flashing OS images onto micro SD media, you can skip this section.
To create the bootable OS image on the micro SD card, you’ll use Etcher. It’s super easy and intuitive to use. If you want to use a different tool, that’s up to you, but the instructions below (and in the video that follows) I’ll use Etcher.
Before you can create the Raspbian image on the micro SD card, you have to download the image to your computer. Go to the Raspbian downloads page and choose RASPBIAN STRETCH WITH DESKTOP, which will give you a nice GUI to work with after your Raspberry Pi is up and running.
The image is a bit larger than the “Lite” image, but the GUI is totally worth the extra time it takes to download.
It will take several minutes to download the image, even with a fast connection, so be patient. After the download finishes, be sure to verify the SHA checksum. Figure 1 shows the SHA-256 checksum for the Raspbian Stretch with Desktop image.
To verify the checksum on MacOS open a Terminal window, go to the directory where you downloaded the image, and run the command: shasum -a 256 2017-11-29-raspbian-stretch.zip
shasum -a 256 2017-11-29-raspbian-stretch.zip
You’ll see output similar to the following output:
$ shasum -a 256 ~/Downloads/2017-11-29-raspbian-stretch.zip
The name of the .zip file that contains the image might vary from what you see (as new releases come out). This output is what it looks like at the time of this writing.
Copy the checksum (the long hexadecimal number) to a text editor. Now copy and paste the checksum from the Raspbian downloads page and compare the two. If they do not match, do not open the file! Instead, first try to download the image again (it might have somehow gotten corrupted during the download process, which would cause the checksums not to match).
If that doesn’t work, go to the Raspberry Pi forum and search for issues related to Stretch (and post a message if you can’t find anything to help you, but always search first). The issue is not always a problem with the file as you can see from this post.
After you download the image to your computer, you’re ready to flash it to the micro SD card that you’ll use to boot the Pi. You might wonder why you can’t just copy the OS image to the SD card like you would any other file. Well, you could certainly do that, but the Pi won’t know what to do with it, and you’ll be staring at a blank screen (hey, and if that’s your thing, I’m not here to judge).
But, if your goal is to get your Pi to boot and run Raspbian, you’ll need to flash the image to the card in a way that the Pi can boot properly. You need a program that can make the micro SD card bootable, and (you guessed it) Etcher can do that.
First, go to the main Etcher page and choose the download that matches your platform. I use MacOS so I’ll choose Download for MacOS.
After you download Etcher, run the installation for your platform. For MacOS, Etcher is downloaded in a DMG file. For Windows, run the setup program (exe). On Linux, extract the .zip file.
Now that Etcher is installed, it’s time to fire it up. Flashing a bootable disk image is a three-step process. First, click Select image, go to the folder where you downloaded the image, select the image, and click Open. The Etcher UI opens.
Next, insert the micro SD card into your computer’s SD drive (using the adapter if necessary), and make a note of how your computer’s OS mounted the drive. Then, click Select drive to select the SD drive as the destination for the bootable image.
Finally, click Flash, and several minutes later you’ll have a bootable image with Raspbian Stretch loaded and ready to go.
Now that you’ve flashed the Raspbian Strech OS image onto the micro SD card, insert it into the Pi’s micro SD slot, which is located on the underside of the board, see Figure 3 (labeled “Micro SD Card”).
The micro SD card will fit in only one orientation, so if you’re having trouble getting it to seat, make sure that the contacts of the micro SD card are facing towards the board, as shown in Figure 4.
Another in the long list of things I love about the Pi is that everything is labeled. So if you’re not sure where to connect something, chances are, the Pi’s circuit board has a label next to the connector.
The Micro SD card usually easily slides into place if you have it oriented properly. Don’t force the card to fit or you could damage the card, your Raspberry Pi, or both.
The Raspberry Pi 3, Model B has 4 USB ports, an HDMI port, and a USB mini-B port to supply the Pi with power. Connect the USB mouse, keyboard, and monitor to the Pi’s USB and HDMI ports. Then, connect the Pi’s power adapter USB mini-B connector to the PWR IN port on the Pi. See Figure 4. Plug the power adapter into an electrical outlet that is suited to the power supply that came with your CanaKit (Part 1), and the Pi should boot up.
When the Pi boots up, if the Pi is booting properly, you’ll see a screen that looks like this one:
When the Pi finishes booting, it will automatically log you in, and you should see a screen like this one:
Don’t see screens like these ones? I’ve flashed disk images and tried to boot the Pi only to see a blank screen staring back at me. In such a case, a number of things wrong might be wrong. First, check to see that your monitor is connected properly (not that that’s ever happened to me). Next, make sure that you inserted the micro SD card all the way into the slot.
If that still doesn’t fix it, chances are something went wrong when you flashed the image. Try to flash the image again. If that doesn’t work, make sure the image you downloaded didn’t get corrupted (file corruption is one of the reasons to use shasum to verify the checksum).
Before you go any further, you should change a few of the default settings. To access the Raspberry Pi settings, click the Raspberry in the upper left corner of the screen and choose Preferences > Raspberry Pi Configuration, and you’ll see a dialog like Figure 7.
Yes. I consider the Raspberry Pi to be a serious computing platform. I’ve been a developer for a long time, and the Pi is way more powerful than many of the computers I have used in my career, and it should be treated as such. You wouldn’t leave the security on your development computer wide open, would you?
Respect the Pi, young Padawan. Make it secure.
I recommend that you take these security precautions (see Figure 7):
Change the default password. To change the default password (which is raspberry, in case you wondered), click the Change Password button. Then, on the dialog that comes up, enter the new password, confirm it, and click OK. The next time you restart your Pi you will need to log in, so make sure and pick a password you will remember (yeah, I know, but I had to say it).
Disable Auto Login. When Auto Login is checked, every time you start your Pi, you will be logged in as the pi user. I tend to work with my Pi a lot over the network (rather than sitting in front of it), so there are lots of times when I turn it on and walk away. If Auto Login was enabled, anyone could walk right up and use my Pi. To prevent this security issue, uncheck As current user next to Auto Login.
Enable SSH. By default, SSH is disabled on your Pi. I recommend that you enable SSH access. I really like being able to use my Pi from anywhere in my home (and I think you will too). Click the Interfaces tab, and select Enabled next to SSH.
Finally, your Pi will need to be able to connect to your network. If you’re using the Ethernet port, you can skip this step. In any event, did you know that the Raspberry Pi 3 has built-in wifi? To enable wifi, click the Network icon in the upper right corner of the screen, and select the network that you want to connect to.
Enter the pre-shared key of your wifi network, and click OK.
Your Pi is now configured and secured, and it can connect to the internet, which it will need to be able to do for Parts 2 and 3 of this series.
So, you’ve ordered all of the parts on the parts list, and you’ve set up your Raspberry Pi. At this point, you might be wondering exactly how you’re going to build this home automation system. I mean, where do the receiver and transmitter modules go? How do they get power? How do they send and receive signals to and from the Pi?
The answer is to use a breadboard.
If you’re like me, at this point you want to build something. Well, you’re in luck. I’ve put together a video that shows you how to build a simple LED circuit so you can get familiar with how the breadboard is laid out and how to use it before you tackle the rest of the project.
A breadboard, like the one in Figure 9, is a specially constructed circuit board that lets you quickly build electronic circuit prototypes.
To build circuits, you insert jumper wires into the breadboard’s holes to make connections (see Figure 10).
Internally, the breadboard’s holes are connected in a very specific (and consistent) way. Because of the way the breadboard’s connections are laid out, you know which holes in the breadboard are connected and which ones aren’t, allowing you to easily change the flow of the current in the circuit.
In Figure 11 you can see two types of holes: vertically connected groups of 5 holes where your circuit components connect to each other and horizontally connected holes called the rails. The rails are holes that are connected horizontally along the top and bottom of the breadboard. The rails are where you will supply voltage and ground to your circuits (as in “power rails”).
Okay, I know, I know. I went on a rant in the Parts List section about authors who use different parts in their illustrations than in the project. Let me explain. I use a really cool program called Fritzing to draw the circuit board illustrations, and they didn’t have a Kuman expansion board.
So, an expansion board is an expansion board is an expansion board. It’s a pretty simple piece of hardware. If it makes you feel better, you can order the Adafruit expansion board from Amazon.
Now that you’ve seen how a breadboard is laid out, it’s time to set up the expansion module (Part 4). The expansion module has two rows of 20 pins each. Align the expansion module so that each set of horizontal pins is seated across the gap in the middle of the board as shown here:
Not all of the rails of the breadboard are connected to each other. This is by design so that different power sources can be supplied to the breadboard for more complex circuits.
For our purposes, we will be using the +5V supply that is coming off of the Pi to supply the receiver and transmitter modules, so all of the rails can be connected to each other. When you have the rails all connected to each other, it will look something like this:
Now all of the breadboard’s rails are connected. I typically use white wires to illustrate power (VCC or +) and black to indicate ground (GND, or -). You don’t have to use black and white jumper wires, you can use whatever colors you want. But, keep in mind that, as your circuits get more complex, using a consistent color coding idiom helps you diagnose problems faster.
The final step in this part of the tutorial series is to set up the 433-MHz hardware devices. These devices use the ISM frequency band between 433.05 and 434.79 MHz, with a center frequency of 433.92 MHz as defined by the Electronic Code of Federal Regulations, Title 47, Part 15, Subpart C, paragraph 15.231 (I’m not making this up).
Hardware that is designed to operate in this frequency band is everywhere. From car remote controls to alarm systems to electrical outlets to home weather stations, the 433 MHz band is full of products that you can control, if you know how.
According to the specification, you are allowed to transmit in the 433 MHz band if the signal meets these conditions:
There are also limits to the strength of the signal, etc., etc., etc.. Basically, I’m just trying to say, “Don’t do something stupid like modify your 433-MHz hardware to create your own pirate radio station to broadcast in the 433 MHz band and you should be fine.”
The hardware that we use in this tutorial uses a technique where the transmission’s amplitude (carrier signal strength) is altered to encode information in binary form. This technique is called Amplitude Shift Keying (ASK for short), where the “1” signal is a large amplitude, and the “0” signal is a lower amplitude.
Some 433-MHz devices use a technique called On-Off Keying (OOK), which is a variant of ASK. With the OOK technique, the device transmits a large amplitude to represent a “1”, but no carrier signal at all to represent a “0”, thus saving power versus an ASK device, which must still draw current in order to send a “0” signal.
Asleep yet? No worries. Just remember, at the end of the day, it’s all ones and zeros. And, you’ll have software to help encode and decode the signals from the hardware that you’ll be using to build the project. But, you’ll have to wait until Part 2 for the software building (trust me, it’ll be worth it).
If you ordered the 6 pack of receiver and transmitter modules (Part 5), there are actually 12 items: 6 receivers and 6 transmitters. The receiver and transmitter look different from one another, so you need to be to tell them apart. Figure 13 shows you what they look like.
First, set up the receiver module. Place it on the breadboard a few holes away from the right edge of the breadboard, like this:
Working around the breadboard clockwise from the upper left corner, follow these steps to make the circuit connections using the jumper wires from the expansion board kit (Part 4):
When you’re finished, the connections should resemble this:
Place the transmitter module on the breadboard between the receiver module and the Pi expansion board, like this:
I couldn’t decide which module should go next to the expansion board, so I flipped a coin. I’m not kidding. The relative positions of the transmitter and receiver have no bearing on their function in the project. The transmitter can go where the receiver is, and vice versa, so long as they’re wired up correctly.
Working right-to-left from the transmitter module, follow these steps to make the circuit connections using the jumper wires from the expansion board kit (Part 4):
Here’s what it looked like when I finished the project, including a case for my Raspberry Pi (which I ordered from —you guessed it —from Amazon.com).
Confused by the previous section? Maybe a video will help. In the video below, I’ll show you how to connect everything up.
All the hardware for your home automation system is wired up and ready to go. It might not seem like much because you can’t see anything happen yet, but believe me, you’ve done a lot of work. The hardware portion of the setup is done. The rest will be done with software.
Do you need a break? Or, are you ready to tackle Part 2, where you set up the system software for your home automation system.
The author used the circuit diagrams from these Fritzing components to create his own circuit diagrams for this tutorial:
March 8, 2019
May 8, 2019
November 13, 2018
Back to top