by Sebastian Gustavsson (sg222yu)
This tutorial contains information on how you create a temperature and humidity sensor. The devices also use an oled display and tree led lights. The microcontroller used for this work is an ESP32 from ZHITING. To handle all the data and events this tutorial uses Node-RED (low-code programming tool for event-driven applications) and InfluxDb (time series database).
The device uses the home network (Wi-Fi) to connect to the internet.
The programming language used to program the EPS32 is micropython and some basic javascript was used in Node-red.
Everything was created on a Window 10 PC.
This project was created over 5 weeks (full time), most of this time was used for lectures. I've created things like this before, which made it possible to create this device in a couple of days. When following this tutorial you should also be able to achieve this.
This project was chosen mostly because I already had most of the hardware to create the device. To gain new knowledge I chose to get an old display that was used to display the latest collected data. I also chose to use Node-red since this isn't something I've used before.
The device collects the temperature and humidity data from my house and displays in on Node-red's dashboard. The dashboard provides a detailed view of the humidity and temperature in both celsius and fahrenheit. You will be able to see the current and average values, also the lowest and highest reached temperatures and lastly three charts showing the last 24 hour readings.
This tutorial will give the insights of how you can easily create a weather station with node-red. The user can on your own expanded the weather station with addition devices, by giving the devices a unique location.
Parts | Used for | Store | Picture | Price |
---|---|---|---|---|
Zhiting ESP32 (2pcs) | The main device | Amazon.se | 160kr | |
Dht11 (Sensor pack) | Temperature and humidity sensor | Amazon.se | 260kr | |
Led stop light (Sensor pack) | Used to flash to indicate when things happen | |||
USB cable | To connect the microcontroller to the PC | Amazon.se | 130kr | |
Breadboard and jumper wires | To wire things together | Amazon.se | 138kr | |
Oled display | To show the latest readings | Amazon.se | 85kr | |
773kr |
This program uses Thonny as IDE and is used to both write and upload the code to the microcontroller.
All of the components used in this tutorial got built in resistors, so there is no need to add any additional resistors. If any other components are used than the one linked in the table above, there could be a need to add resistors.
The inputs used in Fig. 1 could have a different placement on your device.
fig. 1.
This project uses Node-RED and this choice was made because I wanted to learn how to use this tool and I've knowledge about programming since earlier, the tool is free and at the moment it's set up locally.
InfluxDB is used to store all the data and the a free account is used, since I had some troubles getting the networking to work locally. This database was chosen since I used it before and Node-RED has built in support for this database.
The data is sent once every hour by Wi-Fi over UDP (User Datagram Protocol).
The Wi-Fi connection uses a lot of battery and that is why its only used for short periods before disconnected.
The range of the Wi-Fi is quite short, even with a good router. Sadly I couldn't use anything else where I live.
Fig. 2 shows the flow set up in Node-RED.
fig. 2.
The data is saved to the database (InfluxDB) on every reading made by the ESP32 and is stored for 30 days.
The choice of using InfluxDB was made because I had prior knowledge about this database from earlier, Node-RED has support for it and it's a great database for time series data.
Node-RED fetches data 5 times each update, something that most likely could be improved upon, but for simplicity I will leave it like it is.
As seen in Fig. 2 there is some automation, the "Automatic update" and "Initial load" nodes.
The Automatic update node is run on every upload from the ESP32, which updates the dashboard after 15 seconds.
The Initial load node is run on the first page load which updates all the values on the dashboard.
Fig. 3 shows the dashboard from Node-RED's. Where you can see the humidity and temperature in both celsius and fahrenheit. All of these values are displayed in current, average, lowest reached and highest reached form. They also have a chart providing a 24 hour overview of the readings.
fig. 3.
Fig 4. shows the data stored in InfluxDB. At the moment there is just one location added, since there is just one device, but a new device could be added with another location.
fig. 4.
I'm very happy how the project turned out, and it would be cool to create more devices and place them around the house. Sadly I don't own a 3D printer else it would be nice to create a case as well.
Fig. 5 shows the device.
fig. 5.
Fig. 6 shows the display.
fig. 6.