ESP32 Based IoT Weather Station

NextPCB
6 min readFeb 17, 2022

Hi, in this blog I will show you how to make a Weather Station using the very famous ESP32 with 3 sensors that can measure and display live values including:

Supplies

Here’s what you will need for this project:

  • ESP32 Development Board
  • DHT11/21/22 Temperature & Humidity Sensor
  • SI1145 Sunlight Sensor
  • BMP180 Barometric Pressure Sensor
  • Perfboard or Breadboard (to make connections)
  • Male to Female Jumper Wires
  • Grove Connector Cables (only if you’re using grove sensors)
  • Micro USB Cable

Thanks to NextPCB for helping me with this project.

NextPCB is one of the most experienced PCB manufacturers globally. It has specialized in the PCB and assembly industry for over 15 years. Not only could NextPCB provide the most innovative printed circuit boards and assembly technologies in the highest quality standards, the fastest delivery turnaround as fast as 24 hours.

If you have a PCB project, please visit their website and get exciting discounts and coupons!

Only 0$ for 5–10pcs PCB Prototypes: https://www.nextpcb.com/?code=Kumar

Register and get $100 from NextPCB: https://www.nextpcb.com/register?code=Kumar

See more info about PCB Assembly Capabilities: https://www.nextpcb.com/pcb-assembly-services

Step 1: Connections

Connections for DHT Temperature & Humidity Sensor:

  • Vcc (red) → Vin on ESP32
  • Gnd (black) → Gnd on ESP32
  • NC (white) → Not Connected
  • SIG (yellow) → D5 on ESP32

Connections for BMP180 Barometric Pressure Sensor:

  • Vcc (red) → Vin on ESP32
  • Gnd (black) → Gnd on ESP32
  • SDA (white) → D21 on ESP32
  • SCL (yellow) → D22 on ESP32

Connections for SI1145 Sunlight Sensor:

  • Vcc (red) → Vin on ESP32
  • Gnd (black) → Gnd on ESP32
  • SDA (white) → D21 on ESP32
  • SCL (yellow) → D22 on ESP32

Step 2: Make Everything Look Neat

After I was done with the connections, I placed all the sensors and ESP32 on a piece of hard board with some double sided tape and then also cleaned up the wiring with tape such that everything looks neat.

Step 3: Code

Download the code for this project from below and open it in your Arduino IDE.

Step 4: Setup ESP32 on Arduino IDE

If you’re using your ESP32 for the first time, it is not added by default on the Arduino IDE. So in order to make it compatible with Arduino IDE, we need to add it to the IDE first. You can skip this step if you’ve already used ESP32 with Arduino IDE before.

First go the official Espressif Documentation and copy the stable realease link. I have mentioned it below so you can copy from here as well:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Now on your Arduino IDE:

  • Go to Files > Preferences
  • Under ‘Additional Boards Manager URLs’ paste the above copied link
  • If there are other link(s) mentioned already, separate this link and the others with a comma
  • Click on OK
  • Now go to Tools > Board > Boards Manager
  • Under the search bar, type ESP32 and hit enter
  • You will see ESP32 by Espressif Systems
  • Click on Install under it
  • Click on CLOSE

Now if you go to Tools > Board, you will now be able to see all the varients of ESP32 added.

Step 5: Install Required Libraries

In order to make our code work, we will have to install the necessary libraries.

Now go to Sketch > Include Library > Manage Libraries

In the search bar type ‘Blynk’ and install the Blynk Library by Volodymyr Shymanskyy

Similarly download the following libraries:

  • DHT Sensor Library by Adafruit
  • Grove Barometer Sensor by Seeed Studio
  • Grove Sunlight Sensor by Seeed Studio

Step 6: Create Blynk Account

Go to blynk.io and create a new account or login if you already have one.

Step 7: Create a New Template

After you’re done logging in, it will say “Start by creating your first template” so click on ‘New Template’.

  • Under the name you can type anything. I named it as ‘Weather Station’
  • Under ‘Hardware’ select ESP32
  • Under ‘Connection Type’ select WiFi
  • You can also add a description if you want
  • Click on ‘Done’
  • Now you will see a unique template ID and name provided

Step 11: Create New Device

After configuring the template, now we will add our device to it. For this:

  • First go to ‘Search’ at the left side
  • Click on ‘New Device’
  • Select ‘From Template’
  • Choose the template that we created (Weather Station in my case)
  • Device Name can be kept as per your choice (I kept it the same as template name)
  • Click on Create
  • Now our device has been created but it will show was offline as it is still not connected

Step 12: Copy Credentials to Code

When you have created a device, you will see some credentials at the top right corner of the page. These are:

  • Template ID
  • Device Name
  • Auth Token

Copy them one by one and replace them in the code in their respective place.

  • After #define BLYNK_TEMPLATE_ID add your template id under “ “
  • After #define BLYNK_DEVICE_NAME add your device name under “ “
  • Under char auth[] = “ “; add your auth token under “ “
  • Under char ssid[] = “ “; add your WiFi name (SSID) under “ “
  • Under char pass[] = “ “; add your WiFi password under “ “

Step 13: Set DHT Sensor Type

There is just one more little change in the code that may be required. If you’re using DHT11 or DHT21 Temperature & Humidity Sensor instead of DHT22 (which is set as default), uncomment the respective line.

Example if you’re using DHT11:

#define DHTTYPE DHT11 // #define DHTTYPE DHT22 // #define DHTTYPE DHT21

And if you’re using DHT21:

// #define DHTTYPE DHT11 // #define DHTTYPE DHT22 #define DHTTYPE DHT21

If you’re using DHT22, do not make any change!

Step 14: Upload the Code to ESP32

Connect your ESP32 to your PC with a Micro-USB cable. Select the right board and com port in tools. Board depends on what model of ESP32 you’re using, like mine was ESP32 Dev Kit.

Finally, click on upload.

You know the drill, as soon as it shows ‘connecting…’, press and hold the boot button on ESP32 for a few seconds and release. It should upload without problems.

Step 17: Testing Mobile Dashboard

Now if you go back, you will see all values being displayed if your device is on and you’ve done everything correctly. The app has some bugs like it automatically deletes widget name and datastream so keep a check on that. The app also works well in dark mode.

Step 18: Conclusion

You can try to add more sensors to this project once you understand the working (such as Wind Speed Sensor, Rain Sensor etc). It’s not that difficult. You will just need more virtual pins and you will have to add more labels and charts. You can also add an LCD display to show data on the device itself. Data can also be stored on the cloud if you buy premium version of Blynk.

Follow for more.

Thanks for reading!

Originally published at https://www.instructables.com.

--

--