8.1 Real-time Weather From @OpenWeatherMap

The IoT Open Weather Display project utilizes the ESP32 board and an I2C LCD1602 module to create a weather information display that retrieves data from the OpenWeatherMap API.

This project serves as an excellent introduction to working with APIs, Wi-Fi connectivity, and data display on an LCD module using the ESP32 board. With the IoT Open Weather Display, you can conveniently access real-time weather updates at a glance, making it an ideal solution for home or office environments.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

ESP32 Starter Kit

320+

ESP32 Starter Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

ESP32 WROOM 32E

BUY

ESP32 Camera Extension

-

Jumper Wires

BUY

I2C LCD1602

BUY

Get OpenWeather API keys

OpenWeather is an online service, owned by OpenWeather Ltd, that provides global weather data via API, including current weather data, forecasts, nowcasts and historical weather data for any geographical location.

  1. Visit OpenWeather to log in/create an account.

    ../../_images/OWM-1.png
  2. Click into the API page from the navigation bar.

    ../../_images/OWM-2.png
  3. Find Current Weather Data and click Subscribe.

    ../../_images/OWM-3.png
  4. Under Current weather and forecasts collection , subscribe to the appropriate service. In our project, Free is good enough.

    ../../_images/OWM-4.png
  5. Copy the Key from the API keys page.

    ../../_images/OWM-5.png

Complete Your Device

  1. Build the circuit.

    ../../_images/2.6_i2clcd1602_bb.png
  2. Open the code.

    • Open the iot_1_open_weather.ino file located in the esp32-starter-kit-main\c\codes\iot_1_open_weather directory, or copy the code into the Arduino IDE.

    • After selecting the board (ESP32 Dev Module) and the appropriate port, click the Upload button.

    • Always displaying “Unknown COMxx”?

    • The LiquidCrystal I2C and Arduino_JSON libraries are used here, you can install them from the Library Manager.

  3. Locate the following lines and modify them with your <SSID> and <PASSWORD>.

    // Replace the next variables with your SSID/Password combination
    const char* ssid = "<SSID>";
    const char* password = "<PASSWORD>";
    
  4. Fill in the API keys you copied earlier into openWeatherMapApiKey.

    // Your Domain name with URL path or IP address with path
    String openWeatherMapApiKey = "<openWeatherMapApiKey>";
    
  5. Replace with your country code and city.

    // Replace with your country code and city
    // Fine the country code by https://openweathermap.org/find
    String city = "<CITY>";
    String countryCode = "<COUNTRY CODE>";
    
  6. After the code runs, you will see the time and weather information of your location on the I2C LCD1602.

Note

When the code is running, if the screen is blank, you can turn the potentiometer on the back of the module to increase the contrast.