ESP32 Weather Station

Home/Arduino Projects/ESP32 Weather Station

ESP32 Weather Station

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
——————–

ESP32: http://educ8s.tv/part/ESP32

Nextion Display: http://educ8s.tv/part/Nextion32

BME280: http://educ8s.tv/part/BME280

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

ESP32 Weather Station

ESP32 Weather Station

 

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.

 

——————–
LIBRARIES
——————–

📥 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
——————–

Download

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv

2017-10-28T07:37:16+00:00

10 Comments

  1. Pat Molloy November 3, 2017 at 3:12 pm - Reply

    I have built this – great fun – thanks! But I am not there yet .. My ESP32 is at COM46 .. all the Serial.print output us coming to COM46 – debug stuff, *and* the serial data for the display – nothing apparently down the serial port (TX0) to the display itself, so I see this in the COM46 serial monitor … (the 6,3 stuff is some sxtra debug stuff I put in for the WiFi)

    ets Jun 8 2016 00:22:57

    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:956
    load:0x40078000,len:0
    load:0x40078000,len:11904
    entry 0x40078a3c
    Init BME280
    6
    .6
    .6
    .6
    .6
    .6
    .3
    .
    WeatherID: 802⸮⸮⸮weatherIcon.pic=5⸮⸮⸮temperature.txt=”26.5″⸮⸮⸮humidity.txt=”45.4″⸮⸮⸮pressure.txt=”1013.6″⸮⸮⸮temperature.txt=”26.5″⸮⸮⸮humidity.txt=”45.4″⸮⸮⸮pressure.txt=”1013.6″⸮⸮⸮temperature.txt=”26.5″⸮⸮⸮humidity.txt=”45.3″⸮⸮⸮pressure.txt=”1013.6″⸮⸮⸮

    • Nick November 4, 2017 at 9:32 am - Reply

      That’s strange. The results look fine

      • Pat Molloy November 5, 2017 at 6:02 pm - Reply

        Yes, the output does look right – should the output going to *both* the COM46 serial port as well as TXD by default?

  2. Pat Molloy November 5, 2017 at 10:36 pm - Reply

    Ok, I found the issue — I had the Serial.begin at 115200 rather than 9600. The initial debug data is at 115200, so that appears as garbage, but the Nextion wants to be at 9600. The answer to my question of whether COM46 serial monitor (in my case) and TX0 are the same – is yes. COM46 reflects what is being output down TX0

    • Nick January 13, 2018 at 12:35 pm - Reply

      Thanks for sharing!

  3. Charlie November 13, 2017 at 12:38 am - Reply

    Hi Will this work with the esp8266 on a nodemcu? Thanks.

  4. Chris November 24, 2017 at 3:13 pm - Reply

    is it possible to add dht22 and 1-wire DS18xx ?

  5. keith December 5, 2017 at 4:09 am - Reply

    Great little project that works well. What is the code to change to F*

    • keith January 14, 2018 at 10:26 pm - Reply

      Any help to convert the temperature values to Fahrenheit or barometric pressure to inches of mercury?

  6. lasse December 27, 2017 at 11:31 am - Reply

    hello when verifying the code i get a lot of errors
    ESP32_Weather_Station:30: error: no matching function for call to ‘Adafruit_BME280::Adafruit_BME280(int, int)’

    Adafruit_BME280 bme(I2C_SDA, I2C_SCL);
    and then its a lot wifi errors
    wrong librarys? or . any ideas?

    thanks Lasse

Leave A Comment

Close