Build a Smart Home Dashboard
By Rafik Mitry, Mouser Electronics
Published November 5, 2020
Earlier this year, I built a home automation project
in which I connected some devices to the cloud, and with the help of an Amazon Alexa device, I controlled the
devices using voice commands. After testing that project for a couple of months, it inspired me to expand my
smart home system. In this project, I will describe how easy it is to build a simple graphical user interface
(GUI)
on a touch screen, displaying the TE Ambimate MS4 sensor module's environmental data. I will take you through
how to read the sensor's data, how to create a GUI with Python, and how to put everything together.
Project Materials and Resources
Access the project's bill of materials on
Mouser.com for the
required component:
- 571-2331211-2: TE
Connectivity Ambimate Kit MS4
TH With MIC
- 571-2331211-2:
Raspberry Pi 3 Model B+
- 374-BASICINTLPI3KIT:
TT Electronics
Raspberry Pi 3 Basic Kit (MicroSD card, case, HDMI cable, and power supply)
- 485-2441: Adafruit 3.5" TFT
Touchscreen for Raspberry
Pi
- 530-BC-5UE020M: Bel
Ethernet Cables RJ45 CAT5E
UNSHLD BLUE W/BOOT 2M (optional)
Software and Tools:
- Raspbian OS version
2018-03-14
- balenaEtcher
- Python
Project Technology Overview
For this project, I used the following products and technologies, described in the following sections:
TE Connectivity Ambimate Kit MS4
This project's main component is the Ambimate MS4
sensor module, which will be collecting all the environmental data in my home. The sensor module is
very
compact, only 32mm x 16mm. With that compact footprint, it features multiple sensors:
- A PIR motion sensor
- An ambient light level sensor
- A temperature and a relative humidity sensor
- and a microphone
The microphone allows for augmented motion detection or for detecting any sound events. You can also include
an
additional VOC
and CO2 sensor to the board (Figure 1).
Figure 1: TE Connectivity Ambimate Kit MS4 (Source: Mouser
Electronics).
Raspberry Pi 3 Model B+
To host the Sensor Module and the touchscreen display, I'll be using a Raspberry Pi 3 Model
B+. This
single-board computer features a 1.4GHz 64-bit quad-core Arm® Cortex®- A53 CPU Broadcom processor.
It
also features a dual-band 2.4GHz and 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet, and supports
Power
over Ethernet (PoE) capability via a separate PoE HAT (Figure 2).
Figure 2: Raspberry Pi 3 Model B+ (Source: Mouser Electronics).
Adafruit 3.5" TFT Touchscreen for Raspberry Pi
To display the collected environmental data, I will use the Adafruit 3.5" TFT Touchscreen for Raspberry Pi.
It
features a 3.5" display with 480px x 320px 16-bit color pixels and a resistive touch overlay. The PiTFT fits
perfectly onto the Raspberry Pi through the 2x20 general-purpose input/output (GPIO) header. It also
features a
2x13 header, which we will use in this tutorial to connect the Ambimate sensor to the Raspberry Pi
(Figure 3).
Figure 3: Adafruit PiTFT 3.5" touchscreen display (Source:
Adafruit)
Hardware Setup
In this section, I will walk you through the assembly of all hardware parts. The first thing you'll need to
do is
solder the sensor to the 2x13 GPIO header of the touchscreen (Figure 4).
- Connect the GND (pin 1) of the sensor to the GND (pin 9) of the touchscreen
- Connect the SCL (pin 3) of the sensor to the GPIO pin 5 of the touchscreen
- Connect the SDA (pin 4) of the sensor to the GPIO pin 3 of the touchscreen
- Connect the +3.3V (pin 1) of the sensor to +3.3V (pin 1) of the touchscreen
Figure 4: Circuit diagram for the hardware setup (Source: Mouser
Electronics)
Lastly, I will attach the touchscreen to the Raspberry Pi via the 2x20 GPIO header.
Software Setup
- The first requirement is to flash the micro SD card with the Raspbian OS. For flashing the SD card, I
will
use the Etcher software.
- Adafruit recommends using Raspbian OS version
2018-03-14 as it's the last known tested and working version with the display. Click on the link
and
download the raspbian stretch.zip file.
- Locate the downloaded zip folder and plug in the SD card to the PC. Finally, click on Flash (Figure
5).
Figure 5: SD card flashing process (Source: Mouser Electronics)
- Next, connect the Raspberry Pi to a monitor by connecting an HDMI cable. I will also attach a keyboard,
a
mouse, an Ethernet cable, and lastly, connect it to the power supply. You'll need a 5V power supply with
a
micro USB end. I'll be using the official Raspberry Pi power supply; if you don't have the official one,
make
sure the one you'll use has an output current of 2.5A.
- Follow the instructions on the Adafruit PiTFT website to set up and calibrate the
touchscreen.
Baud Rate:
The Ambimate senor module uses I2C communications. So, after booting up the Raspberry Pi, you'll
need
to enable the I2C settings:
- Open a new terminal window
- Type in 'sudo raspi-config' and hit enter.
- The rasp-config utility will launch.
- Select the Interfacing options
- Select the I2C option and activate it
- Reboot the Raspberry Pi so that the changes take effect
- According to the TE Ambimate manual, the Raspberry Pi I2C baud rate must be slowed down from
100kbaud to 10kbaud to receive valid data.
- Open a new terminal and type in nano /boot/config.txt
- Scroll down to the section of hardware interfaces and insert the following (Figure 6):
dtmparam=i2c_baudrate=10000
Figure 6: Baud rate change on the Raspberry Pi (Source: TE
Connectivity)
Code overview
Reading the sensor data:
TE connectivity offers the source
code for the Ambimate Sensor module for the Raspberry Pi and Arduino. Follow the next steps to flash
the
source code and read the sensor data of the Ambimate module:
- Download the python folder and open a new terminal window
- Unzip the folder; then, using the 'sudo python3' command, run the script
- Select to show all the output of the sensors by typing 'Y' and hitting Enter
- You should see sensor data coming through in the terminal's output (Figure 7):
Figure 7: Terminal output of the Ambimate Sensor data (Source: Mouser
Electronics)
The sensor is working perfectly out-of-the-box, but let's make it more user-friendly. Download the
'smart_home_dashboard' project, which is available on the Mouser GitHub
repository. To run the code, unzip the downloaded folder, then run the gui_ambimate.py scrypt. The GUI
script will automatically call the sensor's readings script.
How the Code Works
I took the sensor's source code and edited it to use it on a GUI. I created the GUI using the Tkinter
library,
which is included in the python standard library.
Using the tk.Button() function, I defined a button for every sensor and added an image to the button.
When a sensor button is pressed, its data will be shown on the bottom right-hand side corner and disappear
after
a couple of seconds (Figure 8).
Figure 8: GUI layout of the smart home dashboard (Source: Mouser
Electronics)
I also programmed a splash screen that appears whenever the motion sensor gets triggered. The Raspberry Pi
has an
auxiliary jack, so I connected a speaker to it and added an alarm tone. Whenever motion is detected, the
alarm
sound goes off for a couple of seconds (Figure 9).
Figure 9: Motion detection splash screen on the smart home dashboard.
(Source: Mouser
Electronics)
Here is the project's final look with the Ambimate and touchscreen built-in and added in a 3D printed box
(Figure 10). You can find the .stl file for the 3D printed box on Thingiverse, created by
Adafruit.
Figure 10: Sensors and board added into a 3D printed box.
(Source: Mouser
Electronics)
Conclusion
This project created a smart home dashboard that is connected to an environmental sensor. Using the Ambimate
MS4
sensor module makes it very easy to host multiple environmental sensors on a very compact package, making it
ideal to be used in various smart home applications. We also showed how easy it is to create a GUI interface
using python and connect the sensors readings to the GUI.
Author Bio
Rafik Mitry
joined
Mouser Electronics in 2019 after finishing his Master's degree in Electrical Engineering at the Technical
University of Munich where he also worked in research in the field of energy harvesting for three years. As
a
Technical Marketing Engineer at Mouser, Rafik creates unique technical content that reflects current and
future
technology trends in the electronics industry. Besides keeping up with the latest in technology trends,
Rafik is
an avid lover of aviation and tennis.