Science and technology

Build a child monitor with a Raspberry Pi

Hong Kong could be scorching and humid, even at evening, and many individuals use air-con to make their properties extra bearable. When my oldest son was a child, the air-con unit in his bed room had handbook controls and no thermostat performance. It was both on or off, and permitting it to run constantly in a single day prompted the room to get chilly and wasted power and cash.

I made a decision to repair this downside with an Internet of Things resolution primarily based on a Raspberry Pi. Later I took it a step additional with a baby monitor add-on. In this text, I will clarify how I did it, and the code is available on my GitHub web page.

Setting up the air conditioner controller

I solved the primary a part of my downside with an Orvibo S20 WiFi-connected smart plug and smartphone software. Although this allowed me to manage the air-con unit remotely, it was nonetheless a handbook course of, and I needed to attempt to automate it. I discovered a mission on Instructables that appeared to match my necessities: It used a Raspberry Pi to measure native temperature and humidity readings from an AM2302 sensor and report them to a MySQL database.

Using crimp terminal contacts with crimp housings made it a pinch to attach the temperature/humidity sensor to the right GPIO pins on the Raspberry Pi. Fortunately, the AM2302 sensor has open source software for taking readings, with useful Python examples.

The software program for interfacing with the AM2302 sensor has been up to date since I put my mission collectively, and the unique code I used is now thought-about legacy and unmaintained. The code is made up of a small binary object to hook up with the sensor and a few Python scripts to interpret the readings and return the right values.

With the sensor linked to the Raspberry Pi, the Python code can appropriately return temperature and humidity readings. Connecting Python to a MySQL database is easy, and there are many code examples that use the python-mysql bindings. Because I wanted to observe the temperature and humidity constantly, I wrote software program to do that.

In truth, I ended up with two options, one that might run constantly as a course of and periodically ballot the sensor (sometimes at one-minute intervals), and one other Python script that ran as soon as and exited. I made a decision to make use of the run-once-and-exit method coupled with cron to name this script each minute. The foremost purpose was that the continual (looped) script sometimes wouldn’t return a studying, which may result in a buildup of processes attempting to learn the sensor, and that might ultimately trigger a system to hold on account of lack of accessible sources.

I additionally discovered a handy Perl script to programmatically management my sensible plug. This was an important piece of the jigsaw, because it meant I may set off the Perl script if sure temperature and/or humidity circumstances had been met. After some testing, I made a decision to create a separate checking script that might pull the most recent values from the MySQL database and set the sensible plug on or off relying upon the values returned. Separating the logic to run the plug management script from the sensor-reading script additionally meant that it operated independently and would proceed to run, even when the sensor-reading script developed issues.

It made sense to make the temperature at which the air conditioner would swap on/off configurable, so I moved these values to a configuration file that the management script learn. I additionally discovered that, though the sensor was typically correct, sometimes it could return incorrect readings. The sensor script was modified to not write temperature or humidity values to the MySQL database that had been considerably completely different from the earlier values. Likewise the allowed variance of temperature or humidity between consecutive readings was set in a normal configuration file, and if the studying was exterior these limits the values wouldn’t be dedicated to the database.

Although this appeared like various effort to make a thermostat, recording the info to a MySQL database meant it was accessible for additional evaluation to determine utilization patterns. There are many graphing choices accessible to current knowledge from a MySQL database, and I made a decision to make use of Google Chart to show the info on an online web page.

Adding a child monitor digicam

The open nature of the Raspberry Pi meant I may proceed so as to add performance—and I had loads of open GPIO pins accessible. My subsequent thought was so as to add a digicam module to set it up as a child monitor, provided that the gadget was already within the child’s bed room.

I wanted a digicam that works at nighttime, and the Pi Noir digicam module is ideal for this. The Pi Noir is similar because the Raspberry Pi’s common digicam module, besides it would not have an infrared (IR) filter. This means daytime pictures could have a barely purple tint, however it’s going to show pictures lit with IR mild at nighttime.

Now I wanted a supply of IR mild. Due to the Pi’s reputation and low barrier of entry, there are an enormous variety of peripherals and add-ons for it. Of the numerous IR sources accessible, the one which caught my consideration was the Bright Pi. It attracts energy from the Raspberry Pi and matches across the digicam Pi module to supply a supply of IR and regular mild. The solely disadvantage was I wanted to mud off my rusty soldering expertise.

It may need taken me longer than most, however my soldering expertise had been as much as it, and I used to be capable of efficiently connect all of the IR LEDs to the housing and join the IR mild supply to the Pi’s GPIO pins. This additionally meant that the Pi may programmatically management when the IR LEDs had been lit, in addition to their mild depth.

It additionally made sense to have the video seize uncovered through an online stream so I may watch it from the net web page with the temperature and humidity readings chart. After additional analysis, I selected to make use of a streaming software that used M-JPEG captures. Exposing the JPG supply through the net web page additionally allowed me to attach digicam viewer functions on my smartphone to view the digicam output there, as nicely.

Putting on the ending touches

No Raspberry Pi mission is full with out choosing an applicable case for the Pi and its numerous elements. After plenty of looking out and evaluating, there was one clear winner: GoodPi’s Lego-style case. The Lego compatibility allowed me to construct mounts for the temperature/humidity sensor and digicam. Here’s the ultimate final result:

Since then, I’ve made different modifications and updates to my setup:

  • I upgraded from a Raspberry Pi 2 Model B to a Raspberry Pi 3, which meant I may eliminate the USB WiFi module.
  • I changed the Orvibo S20 with a TP-Link HS110 sensible plug.
  • I additionally plugged the Pi into a sensible plug so I can do distant reboots/resets.
  • I migrated the MySQL database off the Raspberry Pi, and it now runs in a container on a NAS gadget.
  • I added a flexible tripod to permit for the very best digicam angle.
  • I recompiled the USB WiFi module to disable the onboard flashing LED, which was one of many foremost benefits to upgrading to a Raspberry Pi three.
  • I’ve since constructed one other monitor for my second youngster.
  • I purchased a bespoke evening digicam for my third youngster … on account of lack of time.

Want to study extra? All the code is available on my GitHub web page.

Do you’ve gotten a Raspberry Pi mission to share? Send us your story idea.

Most Popular features the latest multimedia technologies, from live video streaming to audio packages to searchable archives of news features and background information. The site is updated continuously throughout the day.

Copyright © 2017 Breaking Express, Green Media Corporation

To Top