6 minute read

Here I will show my attempt to build a wireless weather monitor module, using ESP32 microcontroller, that connects to the internet via WiFi and pulling some useful weather status information from OpenWeatherMap.org let’s say every 5 minutes.

Main features

  • Pulling data through wireless connection
  • Various weather info are available including
    • temperature, feels-like temperature, etc
    • pressure,
    • humidity
    • wind speed
    • visibility
  • Temperature status indicator LEDs:
    • Red (too hot)
    • green (normal)
    • blue (too cold)
  • Weather indicator in case of extreme weather
    (e.g. rain or snow)
    • Yellow LED
    • Buzzer (single or double beep)
  • Change texts color when the weather status is not normal
    (e.g. high wind speed, low visibility, rain)
  • Report date and time of the latest update using NTP client

How does it work?

The brain of the module is ESP32 microcontroller, a low-powered with built-in WiFi and Bluetooth functionality, which submits an HTTP request to OpenWeatherMap as the weather data server. The server returns a response to the ESP32 which contains all the required information. Finally, it reads the data into JSON format, represents them in a TFT display, and reacting to them using, changing the text color, different LED indicators, or generating a gentle beep sound.

Prerequisites

  • Access:
    • Connection to a WiFi network
    • OpenWeatherMap enabled API to request weather data (account creation is required, see here)
  • Hardware:
    • EPS32 microcontroller
    • 1.8 SPI TFT 128x160 display
    • Four LEDs (red, green, blue, and yellow)
    • A Piezo buzzer
    • Few 100 Ohm resistors for LEDs
    • A breadboard and some wires (or soldering prototype board)
  • Software

Wiring

The wiring is pretty straightforward as follows (see ESP32 Pinout Reference):

  • TFT display pins:
    • CS ➡ 12
    • RST ➡ 14
    • DC ➡ 13
    • SCLK ➡ 22
    • MOSI ➡ 21
  • LEDs pin:
    • Blue ➡ 25
    • Green ➡ 26
    • Red ➡ 27
    • Yellow ➡ 32
  • Buzzer pin ➡ 15

Code adjustment

A few parameters have to be known and set before compiling the sketch.

  • SSID : WiFi network’s name
  • PASSWORD : WiFi password
  • APIKEY : Open weather map api key (see the references)
  • CITY : e.g. “Antwerp”
  • COUNTRY : e.g. “BE”
  • TIMEZONE : Time zone respect to GMT e.g. 7200 for GMT+2h
const char* ssid = "SSID";
const char* password = "PASSWORD";

// Your Domain name with URL path or IP address with path (see references)
String openWeatherMapApiKey = "APIKEY";

// Replace with your country code and city
String city = "CITY";                // e.g. "Antwerp"
String countryCode = "COUNTRY";      // e.g. "BE"
unsigned long timezone = "TIMEZONE"  // e.g. 7200 (GMT+2)

Blow parameters work just fine with their default values but they can be also adjusted based on your needs.

// LED indicators
#define LED_COLD        25    // pin
#define LED_NORM        26    // pin
#define LED_HOT         27    // pin
#define LED_WEATHER     32    // pin

// Set thresholds
#define TEMP_COLD       5.0   // Celsius
#define TEMP_HOT        25.0  // Celsius
#define WIND_SPEED_HIGH 30.0  // km/h 
#define VISIBILITY_LOW  2.0   // km
#define HUMIDITY_HIGH   90.0  // Percent

// Define settings for buzzer
#define BUZZER_PIN      15    // pin
#define BUZZER_FRQ      2000  // Hz
#define BUZZER_CHANNEL  0     // PWM channel

// Define pins of TFT screen
#define TFT_CS          12    // pin
#define TFT_RST         14    // pin 
#define TFT_DC          13    // pin
#define TFT_SCLK        22    // pin
#define TFT_MOSI        21    // pin    

// Pulling time in Milliseconds (e.g. 5 min)
unsigned long timerDelay = 300000; 

For more details and the sketch (C++ source code) please see https://github.com/hghcomphys/weather-monitor-module.

References

Some useful links that part of this work is based on them are as follows: