Have you ever wanted a smart monitor that not only lets you see your kids, but also texts you the temperature in their crib, so you can be certain they are comfortable? I certainly have!

That’s why I made the Raspberry Pi (RPi) Smart Baby Monitor, and I want to show you how easy it is to build yourself using Twilio, a Raspberry Pi, and a little bit of code.

Here's my son at 4 months old along with the smart baby monitor I created for him:

The Tech Stack

The IoT app we are going to create will use the Python programming language, a Raspberry Pi, a Raspberry Pi camera, a DS18B20 temperature sensor, and the Twilio SMS API:

- Python version 3.5: The language we will write our code in

- Raspberry Pi: Environment that will hold our software (code) and our hardware (peripherals)

- RPi Camera: the camera we will use for video stream

- DS18B20 Temperature Sensor: To send temperature data to the Pi

- Twilio SMS: to send a text

What We're Building

Let’s walk through how it will work when finished:

The Raspberry Pi will be live streaming the video over your WiFi network, allowing any device on the network to watch the feed. In my case, it’s my wife’s phone, my phone, and my laptop. The DS18B20 sensor takes a temperature reading every second, and sends that to the RPi. The Python code reads that temperature data, and informs you when the temperature in the baby’s crib falls above or below a threshold. If the threshold is crossed, a text message is sent letting you know that it’s either too hot or too cold in your baby’s crib.

Create a Twilio Account and select your Phone Number

The first thing to do is sign up for a Twilio account. Next, buy a phone number. Make a note of the phone number you’ve bought, as well as your Account SID and Auth Token which can be found in the Twilio Console. You’ll need them all later.

Configuring your Raspberry Pi

If you don’t have an RPi already, you can pick up a kit here. There are lots of good kits out there, you don’t necessarily need the one I bought. But no matter what kit you go with, I would strongly recommend:

Getting a kit that has the NOOBS operating system already installed on the SD card. (It will cost you about one dollar more and save you major headaches when setting up your RPi environment.)

Buying an RPi 3 B or later, to ensure it has WiFi capability.

Ensuring your kit comes with a 2.5A Micro USB Power Supply, which is specifically designed for the RPi. This is much more important than you might think.

Pro tip: The RPi 3 B+ has 5G capability, so if you buy that model you will be a step ahead of the game when that becomes the dominant paradigm!

Once you have your RPi kit assembled, you just need to plug it in and connect a monitor/keyboard/mouse, and you should be ready to go. These are generally very easy to set up. (Troubleshooting item: if your RPi starts up, flickers, then reboots over and over, it is likely due to a power supply issue. Replace your power supply. This is surprisingly common. It is very important to ensure you are using a power supply designed for the RPi.)

Great! You got your RPi up and working! Now you need to connect to your WiFi. You can do this in one of two ways: via the command line (instructions here), or via the desktop. I prefer doing it via the desktop because it is easier. Here is what my desktop looks like at boot up. Pretty plain, huh? Your background may vary.

If you choose to set it up via the desktop, click on the network icon on the right side of the screen, and that will bring up a list of available networks. Choose your home network. (Troubleshooting item: If you don’t see your network, wait 5 - 10 seconds and it should auto-refresh. If you still don’t see it, double check that your network is active.)

Click on your network, and enter your key. The network item will flash to let you know it is connecting.

Try opening the browser and visiting a webpage to ensure you have network connectivity.

Peripheral Hardware

Now that you are connected to the internet, it’s time to add your peripheral devices, e.g. your camera, and temperature sensor. To connect the DS18B20 temperature sensor, you will need some female-to-female jumper wires, available here. I’ve chosen blue, green, and purple wires for no reason in particular.

In the picture above, the green wire represents the voltage, the blue is the ground wire, and the purple is the wire that carries the data.

On the RPi, you will see 2 rows of 20 pins, for a total of 40 pins (see pic above). These are referred to as GPIO, or General Purpose Input/Output pins. Some of the pins are for voltage, some are ground, and some carry data. More information is available in the Raspberry Pi Documentation. This is one of the ways which you can connect sensors to the RPi.

For this tutorial, you need to connect the purple wire to the 4th pin on the inner row. This is data channel 4. This will be important when we write our code.

Connect the green wire to the first pin on the outer row. This is the 5V pin, and powers the sensor.

Finally, connect the blue wire to the third pin on outer row. This is the ground pin, and completes your circuit.

Pro tip: if you want a quick reminder of the GPIO configuration, you can always type pinout on the RPi command line. It will show you this very helpful diagram:

Next, you need to insert the camera into the connector situated between the Ethernet and HDMI ports, with the silver connectors facing the HDMI port. See picture below. You may have to press hard, it is a snug fit.

Awesome, all of your hardware is physically connected!

[a]

Peripheral Software

We need to enable the Web Cam Interface. You can find detailed instructions on how to do that here. Open the Raspberry Pi Configuration:

Click on the “Interfaces” tab. Then click “Enabled” on the Camera.

Then click OK.

Go to your command line, which you can quickly access by hitting Ctrl + Alt + t on your keyboard. It’s important to update your RPi with all the necessary updates.

Modify the boot file so that we can read data from the DS18B20 sensor. It’s very simple, to do it, open your command line, either from the desktop, or you can hit: Ctrl + Alt + t. Once your command line is open, type: