Author: Cajsa Schoultz (cs224mj)
This tutorial will guide you through the process of building a temperature and humidity monitoring system using IoT technology. By the end of this tutorial, you will be able to measure and display real-time temperature and humidity data.
This project will take approximately 4-6 hours to complete.
By building a beginner-level weather station, individuals can gain hands-on experience in combining hardware components, programming, and cloud connectivity to create a practical IoT solution.
The objective of this tutorial is to empower beginners with the knowledge and skills to create their own weather station that measures temperature and humidity. By using sensors, we can accurately capture real-time data from the environment. The collected data is then transmitted wirelessly to a cloud-based platform, allowing users to remotely access and monitor the weather conditions from anywhere in the world.
Through this tutorial, the aim is to provide a step-by-step guide that simplifies the process of building an IoT weather station for beginners. By combining hardware setup, coding, connectivity, and data presentation, users will gain a comprehensive understanding of how different components interact to create a functional and practical IoT solution. This project serves as a foundation for individuals interested in exploring IoT applications.
List of materials
Item | Description | Cost | |
---|---|---|---|
Raspberry Pi Pico WH | Microcontroller | 109 sek | |
Breadboard | Microcontroller board | 39 sek | |
DS18B20 | Digital temperature sensor | 42 sek | |
DHT11 | Digital temperature and humidity sensor | 49 sek | |
USB-cable A-male – micro B 5p male 1.8m | Connection between microcontroller and computer | 130 sek | |
USB-A female to USB-C male | For computers with only USB-C | 249 sek | |
Jumper Wires x8 | 29 sek |
The reason why two different temperature sensors are used for this project is to get a more accurate measurement of the surrounding environment. Each temperature sensor has its own strengths and limitations, and by combining their readings, we can obtain a more reliable and precise measurement. At first, I planned on only including the DHT11 to measure temperature and humidity; however, upon doing some research it revealed that there is an accuracy for ±2%. Therefore I chose to include DS18B20 which has an accuracy of ±0,5%.
Everything is bought through Electrokit, where I purchased their LNU starter kit.
This project was developed on a MacBook updated with macOS Ventura 13.4.1. Therefore, there might be differences for other computing systems for the installation and setup process.
For this project, I have chosen to use Visual Studio Code (VS Code). VS Code is a free IDE and open-source code editor developed by Microsoft. VS Code provides a lightweight and customizable environment that offers a rich set of features, making it the preferred choice for this beginner project.
Initial to the project, you have to install VS Code. This can be done through downloading VS Code and download and install the IDE on the preferred operating system. VS Code is available for Windows, macOS, and Linux. Thus, making it accessible to many users.
Once installed, launch VS Code by opening it from your applications or using the desktop shortcut.
The next step is to install Node.js to be able to proceed to the next step due to the dependability of using PyMakr.
The third step is to install the plugin Pymakr. In VS Code, click on the Extensions icon on the left sidebar (or use the keyboard shortcut Ctrl+Shift+X / Cmd+Shift+X). In the search bar, type "Pymakr" and press Enter. Look for the "Pymakr" extension in the search results, and click the Install button. Wait for the installation process to complete.
When the software and plugin is installed, it is time to unpack the microcontroller and attach it to the breadboard. Make sure that the microcontroller is appropriately attached, that is vertically aligned with the board.
Afterward, it is time to plug in the USB cable into the Raspberry Pi. Note that the port that is attached to the microcontroller is fragile, so it is recommended that the USB-port that is plugged into the computer is attached/removed during development and setup of sensors.
At the same time as you are connecting the USB cable to the computer, press down the BOOTSEL button on the microcontroller. By doing this, the microcontroller will appear as a file named RP1-RP2 in your system.
The next step is to download the micropython firmware, which you should make sure is the latest release. After downloading, drag this file onto the RPI-RP2 file.
The board will automatically disconnect and reconnect again. However, it may not always reconnect again depending on your computer software. In this case where a Macbook is used, it did not reconnect.
Now you are up and running and ready to start developing the project!
Before putting everything together, please note that no power source is connected to the board. This can be ensured by deattaching the USB-cable from the computer.
Below, a step-by-step guide for this will be presented with a circuit diagram at the end:
Gather the necessary components:
Set up the Raspberry Pi and Breadboard
Wiring the DHT11 Sensor
Connect the DHT11 sensor to the Raspberry Pi GPIO pins using jumper wires as follows:
Wiring the DS18B20 Sensor
Connect the DS18B20 sensor to the Raspberry Pi GPIO pins using jumper wires as follows:
If it looks like this you are all set!
The circuit diagram is done through Fritzing.
IMPORTANT NOTE!
Verify the connections:
You are now set to plug in your breadboard to the computer and start coding!
Initial to this project, it was difficult to select the appropriate platform. I wanted the platform to be suitable for not only myself but also considering other people that may use this tutorial. The ease of use, the cost or subscription fee, and the documentation was therefore taken into consideration.
After carefully evaluating the available options, it was determined that MQTT utilizing Adafruit.io emerged as the most optimal selection. Adafruit.io offers a comprehensive platform for efficiently managing, analyzing, and visually representing data obtained from IoT devices. One notable advantage is that it is freely accessible to all users upon creating an account, further enhancing its appeal.
You must create an account to be able to connect your device to the platform.
In order to simplify the process and ease of understanding the presentation of the code is divided into smaller parts.
We then start with the boot.py
file in order to connect the device to the internet. Instructions can be found here. Note that I have imported the Wi-Fi name and passwords from secrets. This file has been added to protect the Wi-Fi credentials.
As we are using a MQTT protocol to transmit the data, we first need to add a new folder which we name mqtt.py
. Here, we insert this code. More information can be found here.
When we have established an internet connection and our MQTT is up and running, we can start creating the code for the project. This code is inserted into main.py
. See code below:
The code in itself is pretty straightforward and simple. Note that I have removed my Wi-Fi credentials in this code on line 75 and 76, where they would normally be stated.
If you have followed all the previous steps in this tutorial you should be able to recreate this project.
The sensor data is transmitted to Adafruit on a five minute interval. The reason for choosing a five minute interval is that temperature changes typically occur at a slower pace, and frequent updates may not be necessary for most applications. By using a five-minute interval, we can strike a balance between timely updates and efficient use of network resources. This interval allows for periodic monitoring of temperature changes while minimizing unnecessary data transfers.
However, it's important to evaluate the specific needs of your application. If your environment experiences rapid temperature fluctuations or if real-time monitoring is critical, you may need to adjust the transmission interval to a shorter duration. On the other hand, if temperature changes occur slowly and real-time updates are not vital, you can consider extending the interval to conserve network bandwidth and reduce power consumption.
Wi-Fi is used as the wireless protocol for this project. As this is an indoor project, it does make sense to use the Wi-Fi available. The data is sent through a MQTT protocol.
When using Adafruit.io, it is possible to add blocks which best illustrates the desired presentation of the data. For this project, I wanted to visualize the data in two ways - trough gauges and line charts. This not only allowed for a clear understanding of the current data, but also illustrating how it has changed over time. Essentially, you can add any widget that you find suitable.
Every five minutes, data is transmitted to Adafruit.io, and the values are presented in the span of 24 hours. Furthermore, I chose to use the value span of -60 to 130°C for illustration and as it captures the values of both sensors.
Note that the DHT11 can only measure temperature between 0 and 50°C, while DS18B20 can measure temperature between -55 to 125°C. When you are using the free version of Adafruit.io, the data feeds are stored for 30 days.
Below, the data is presented from this project. The gauges and line charts are specified with the sensor used.
I also chose to include an additional line chart, presenting temperature data from both sensors side by side for illustration (the green line represents DS18B20 and the blue line represent DTH11):
Based on the accuracy levels of the temperature sensors, we can calculate the mean value of both sensors (e.g. 25+26/2=25,5). However, as the accuracy of DS18B20 is somewhat more accurate than DHT11, we will use the value of the former twice (e.g. 25+25+26/3=25,33).
As this was my first ever project within IoT, I am very satisfied with the results I have gotten. It was truly a great beginners project to learn and understand the basics. For future projects, I am eager to create something more advanced or even level up this project. For example, I was interested in monitoring soil as well, but did not have the time to gather the sufficient sensor. This will most likely be the next project I pursue.
The actual device is currently very fragile, as I did not prioritize any design in this particular project. This would have been helpful to greate a more enduring device that would last longer. In addition to this, I have now only used my computer for powering the device. It would be useful to include another type of power distibutor, such as a powerbank. Additionally, as seen in the final design, the jumper wires are somewhat messy due to the length, and I would therefore switch these to shorter ones.
In conclusion, it was a fun (although sometimes challenging) project. Considering the above mentioned final notes, I am aware of the natural steps going forward to improve the device and design.