Introduction: ESP32 WiFi Weather Station With a BME280 Sensor

Picture of ESP32 WiFi Weather Station With a BME280 Sensor

Dear friends welcome to another tutorial! In this tutorial we are going to build aWiFi enabled weather station project! We are going to use the new, impressive ESP32 chip for the first time along with a Nextion display.

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 find links to these video in this Instructable, don't worry.

Let’s start!

Step 1: Get All the Parts

Picture of Get All the Parts

In order to build this project we need the following parts:

The cost of the project is around 30$.

Instead of the ESP32, we could use the cheaper ESP8266 chip, but I decided to use the ESP32 to gain some experience with it and see what works and what not.

Step 2: The ESP32

Picture of The ESP32

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 for this board. I have attached the video on this Instructable. It will help understand why this chip will change the way we make things forever!

Step 3: The Nextion Display

Picture of The Nextion Display

Also, this 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 Instructable about this Nextion display which explains in depth how they work, how to use them and their drawbacks. You can read it by clicking here: https://www.instructables.com/id/Arduino-Weather-S...

Step 4: BME280 Sensor

Picture of BME280 Sensor

The BME280 in a new great sensor from Bosch.

So far I was using the BMP180 sensor which can measure temperature and barometric pressure. The BME280 sensor can measure temperature, humidity, and barometric pressure! How cool is that! We just need one sensor to build a complete weather station!

In addition to that, the sensor is very small in size and very easy to use. The module we are going to use today uses the I2C interface so it makes communication with Arduino very easy. We only to connect power and two more wires to make it work.

There are already many libraries developed for this sensor so we can use it in our projects very easily! The cost of the sensor is about 5$. You can get it here ▶ http://educ8s.tv/part/BME280

NOTE: We need the BME280 sensor. There is also a BMP280 sensor which does not offer humidity measurement. Be careful to order to sensor you need.

Step 5: Connecting the Parts

Picture of Connecting the Parts

The connection of the parts is straightforward as you can see from the schematic diagram.

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!

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. Let’s now see the software side of the project.

Step 6: The Code of the Project

Picture of The Code of the Project

To parse the weather data, we need the excellent Arduino JSON library. We also need a library for the sensor.

? ESP32 BME280: https://github.com/Takatsuki0204/BME280-I2C-ESP32
? Arduino JSON: https://github.com/bblanchon/ArduinoJson

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 at 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.

const char* ssid = "yourSSID";
const char* password = "yourPassword"; String CityID = "253394"; //Sparta, Greece String APIKEY = "yourAPIkey"; #define ALTITUDE 216.0 // Altitude in Sparta, Greece

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 like this:

void showConnectingIcon()
{ Serial.println(); String command = "weatherIcon.pic=3"; Serial.print(command); endNextionCommand(); }

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 attached to this Instructable!

Step 7: Final Thoughts & Improvements

Picture of Final Thoughts & Improvements

As you can see, an experienced maker today can build exciting projects in just a few hours with a few lines of code and only three parts! 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!

Comments

tytower (author)2017-11-18

Wow there have been some improvements while I was looking elsewhere . Screen looks terrific . How accurate is the sensor?

educ8s (author)tytower2017-12-05

The sensor is really accurate. It is the latest sensor developed by Bosch.

bostonoa (author)2017-11-21

Great project! To be a complete weather station, we need a wind speed measurement.

educ8s (author)bostonoa2017-12-05

We need to find some inxpensive wind sensor then. Any ideas?

bblanchon (author)2017-11-21

Awesome article Nick, as usual.

Thank you for using ArduinoJson again ;-)

https://arduinojson.org

educ8s (author)bblanchon2017-12-05

Thank you Benoît for your kind words!

Your library is a life-saver. Thank you for this excellent tool!

mischa72 (author)2017-11-27

This is a very, very cool project. Is it real hard to add a synchronized clock and date to the display? That would make this project even more awesome.

educ8s (author)mischa722017-12-05

No, it is not hard, but we are running out of space on the screen ;-)

ron342 (author)2017-11-22

Great project!

As has been noted, wind speed and direction, maybe with max/min wind speeds and some trending up or down arrows on the display whould be a great add on.

Do you know of any simple wind speed/direction sensors?

Michal Choma (author)2017-11-22

Hello, dont you have problem with fake bmp or bme sensors from china? They have different I2C adress and doesnt works proper. I buy one BMP and use library from here:

http://giocarduino.altervista.org/e47-sensore-pres...

It works on arduino pro mini, but not on esp8266. Pressure was wrong, when I try, even temperature was good. I think problem is in using char variables in esp.

cmoegele (author)2017-11-22

Is it possible to add some 1-wire DS18xx sensors to use it perhaps for steering the solar-thermal installation and switching some pumps or motors

ajaisb (author)2017-11-22

Thanks for a nice project .Nextion is not available in India. Whats the alternative. Please help.

MichaelS440 (author)2017-11-21

looks easy. Ordered the 3.2, and need to check and see if I have the baro/thermos sensor. Looking forward to a wind version. I have two aerometers right now, one an old davis, and one a piece from something, possibly davis.

dtbarnett (author)2017-11-21

Be careful when ordering the BME280; I ordered some from China and got BME/P280 which may be either the BME280 or the BMP280. Unforunately, mine were all BMP280.

I like your project and will take a good look at the display.

Ghostrider513 (author)2017-11-21

I was wondering if this can provide relative humidity too?

АнатолийД (author)2017-11-21

Interesting project, but I'll try to do it on ESP8266.

misterxp (author)2017-11-20

Nice one thanks!

agulesin (author)2017-11-20

Nice project! It certainly shows how things have advanced since my days - all we could do with three components back then (1980s) was flash a single LED!! :-)))))

ahmet_024102 (author)2017-11-18

thnk you

tytower (author)2017-11-18

An arrow on each section of the screen showing the trend would help. Especially the pressure

About This Instructable

17,521views

317favorites

License:

Bio: I am Nick Koumaris from Sparta, Greece. I'm extremely passionate about electronics, making things and design. I love teaching what I know and sharing ... More »
More by educ8s:ESP32 WiFi Weather Station With a BME280 SensorArduino Temperature Monitor and Real Time Clock With 3.2" DisplayArduino TEA5767 FM Radio Receiver
Add instructable to: