Today we build an ESP32 Weather Station with WiFi connectivity. We are going to use the new, impressive ESP32 chip for the first time along with a Nextion display. Let’s get started!
Intro to the ESP32 Weather Station Tutorial
In this video, we are going to make this. It is yet another weather station project I know, but this time we use the new ESP32 chip! We also use the new BME280 sensor which measures the temperature, the humidity, and the barometric pressure. When we power up the project, it connects to the WiFi network, and it is going to retrieve the weather forecast for my location from the openweathermap website. Then it will display the forecast on this 3.2” Nextion Touch Display along with the readings from the sensor! The readings are updated every two seconds and the weather forecast every hour! As you can see, in this project we use the latest technologies available to a maker today! If you are a DIY veteran, you can build this project in five minutes. If you are a beginner, you have to watch a couple of videos before attempting this project. You can watch those videos by clicking on the cards that will appear during the video. Let’s start!
WHERE TO BUY
Nextion Display: http://educ8s.tv/part/Nextion32
Small Breadboard: http://educ8s.tv/part/SmallBreadboard
Jumper Wires: http://educ8s.tv/part/JumperWires
3 in 1 wires: http://educ8s.tv/part/Wires
Power Bank: http://educ8s.tv/part/Powerbank
Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!
This is the first project I ever build with the new ESP32 chip. If you are not familiar with it, the ESP32 chip is the successor of the popular ESP8266 chip we have used many times in the past. The ESP32 is a beast! It offers two 32 processing cores which operate at 160MHz, a massive amount of memory, WiFi, Bluetooth and many other features with a cost of around 7$! Amazing stuff! Please watch the detailed review I have prepared about the chip by clicking on the card here. It will help you understand why this chip will change the way we make things forever!
The ESP32 Weather Station is the first project I build with a Nextion touch display. The Nextion displays are new kind of displays. They have their own ARM processor at the back which is responsible for driving the display and creating the graphical user interface. So, we can use them with any microcontroller and achieve spectacular results. I have prepared a detailed review of this Nextion display which explains in depth how they work, how to use them and their drawbacks. You can watch it by clicking on this card.
The connection of the parts is straightforward as you can see from this schematic diagram. You can find a link to the schematic diagram in the description of the video below. Since the BME280 sensor uses the I2C interface, we only need to connect two wires to communicate with ESP32. I have attached the sensor to Pins 26 and 27. In theory, every digital pin of the ESP32 board can be used with I2C peripherals. In practice though, I found out that some pins did not work because they are reserved for other uses. Pins 26 and 27 function great!
Schematic Diagram of the ESP32 Weather Station Project
To send data to the display, we only need to connect one wire to the TX0 pin of the ESP32. I had to bend the pin like this to connect the female wire of the display since the ESP32 board is too big for this breadboard. After connecting the parts, we have to load the code to the ESP32, and we have to load the GUI to the Nextion display. If you have trouble uploading the program to the ESP32 board, hold down the BOOT button after pressing the upload button on the Arduino IDE. To load the GUI to the Nextion display, copy the WeatherStation.tft file I am going to share with you to an empty SD card. Put the SD card into the SD card slot at the back of the display. Then power up the display, and the GUI will be loaded. Then remove the SD card and connect the power again.
After successfully loading the code the project will connect to the WiFi network, it will get the weather forecast from the openweathermap.org website, and it will display the readings from the sensor. The hardware of the ESP32 Weather Station is ready. Let’s now see the software side of the project.
📥 ESP32 BME280: https://github.com/Takatsuki0204/BME280-I2C-ESP32
📥 Arduino JSON: https://github.com/bblanchon/ArduinoJson
To parse the weather data, we need the excellent Arduino JSON library. We also need a library for the sensor.
Let’s see the code now. At first, we have to set the SSID and the password of our WiFi network. Next, we have to enter the free APIKEY from operweathermap.org website. To create your own API key, you have to sign up on the website. Getting current weather data and forecast is free, but the website offers more options if you are willing to pay some money. Next, we have to find the id of our location. Find your location and copy the ID which can be found in the URL of your location. Then enter your city’s id in the CityID variable. Also, enter the altitude of your town in this variable. This value is needed for accurate barometric pressure readings from the sensor. Now we are ready to move on.
At first, we initialize the sensor, and we connect to the WiFi Network. Then we request weather data from the server. We get a reply with the weather data in JSON format. Before sending the data to the JSON library, I manually delete some characters that were causing me problems. Then the JSON library takes over, and we can easily save the data that we need in variables. After we have kept the data in variables, all we have to do, is to display them on the screen and wait an hour before requesting new data from the server. The only information I present is the weather forecast, but you can display more information if you wish. It all here saved in variables. Then we read the temperature, the humidity and the barometric pressure from the sensor and we send the data to the Nextion display.
To update the display, we simply send some commands to the serial port. If you get this compilation error while compiling, you have to add this -fno-threadsafe-statics at the platform.txt file. Press save, and then the project will compile fine. The software for the ESP32 is not mature, yet so some things do not work at once yet.
The Nextion GUI consists of a background, some textboxes and a picture that changes depending on the weather forecast. Please watch Nextion display tutorial for more information. You can quickly design your own GUI if you wish and display more things on it. As always you can find the code of the project in a link in the description of the video.
As you can see, an experienced maker today like can build exciting projects in just a few hours with a few lines of code and only three parts, like this ESP32 Weather Station! A project like this would have been impossible to make even two years ago! Of course, this is just the beginning of the project. I would like to add many features to it, like graphs, touch functionality that is now missing, maybe a bigger display and of course a beautiful looking 3D printed enclosure. I will also design a better looking GUI and icons. I have some very fresh ideas to implement!
I would love to hear your opinion about today’s project. What kind of features do you want me to add to the project? Do you like how it looks? How do you want to see it evolve? Please post your ideas in the comments section below; I love reading your thoughts!
CODE & SCHEMATICS
SUBSCRIBE ON YOUTUBE
Never miss a video: Subscribe to educ8s.tv