Visualizing Weather Conditions

by nikakis30 in Circuits > Arduino

148 Views, 0 Favorites, 0 Comments

Visualizing Weather Conditions

IMG_20240621_154531_727[1].jpg
IMG_20240621_154414_915[1].jpg
IMG_20240621_154421_315[1].jpg
IMG_20240621_154434_359[1].jpg
IMG_20240621_154649_833[1].jpg
IMG_20240621_154623_602[1].jpg
Visualizing the weather
IMG_20240621_192335_277[1].jpg

There are plenty of Smart Weather projects, but none of them can show the weather conditions using LEDs. That’s why I named this project 'Visualization of the Weather'. According to the description of the weather conditions provided by OpenWeatherMap, the program lights up the corresponding LED. Additionally, it inhibits watering in case of a rainy day. I preferred this method, which relies on a web page instead of a sensor, as sensors can send erroneous data to the microcontroller due to corroison or dust or moisture. Besides this, the program is an IoT project designed to provide real-time monitoring and data collection for weather conditions and water usage. This project leverages various sensors and modules to gather information about temperature, humidity, atmospheric pressure, wind speed, wind direction, and water flow. The collected data is displayed on a TFT screen and transmitted to thingSpeak for remote monitoring and analysis. Public channel thingspeak with user id:nikakis30.

Downloads

Supplies

ESP32-NODEMCU-ESP-32S-Kit-pinout-low-res-mischianti.jpg

 ESP32s Microcontroller

 TFT Display (Similar to Adafruit ST7735, 1.8 inch 128x160 SPI Color TFT LCD LED Display)

 AHT20 +BMP280 (Compined)

 Water Flow Sensor (YF-S201)

 LEDs for Weather Indication

Program Description: Weather and Flow Monitoring System With TFT Display

This Arduino program is designed to assist an irrigation system controlled by a Nano Arduino module. Although it could be merged into one, I preferred to keep it separate for hardware simplicity because the TFT alone requires seven wires. I wanted it to be as compact as possible to place it on the lid of the box housing the entire project. The additional feature of this program is to control a water flow valve to inhibit watering in case the weather is rainy. The other features provide statistical data and allow monitoring the system's functionality from a distance. The program can visualize the weather conditions using LEDs corresponding to the actual weather conditions. For example, if the sky is clear, it lights up the LED for clear sky; if it is rainy, it lights up the rain LED, and so on. The data is retrieved from OpenWeatherMap. Besides turning the LEDs on and off, the program also opens or closes an electrovalve attached to the water supply.. For this project, I use an ESP32s microcontroller to monitor weather conditions, water flow rate, and total water consumption. It features a TFT display for real-time data visualization and integrates with ThingSpeak for remote data logging. The system also connects to an NTP server for accurate timekeeping and retrieves weather data from OpenWeatherMap.

Features:

1. Weather Monitoring:

  • Retrieves and displays temperature, humidity, and pressure using the AHT20 and BMP280 sensors.
  • Fetches additional weather data such as wind speed and condition from the OpenWeatherMap API.

2. Flow Monitoring:

  • Measures water flow rate and total water consumption using a flow sensor.
  • Updates flow rate and total flow on the TFT display.

3. Time and Date:

  • Synchronizes time with an NTP server.
  • Displays current time and date on the TFT screen.

4. ThingSpeak Integration:

  • Logs weather and flow data to ThingSpeak for remote monitoring and analysis.

5. TFT Display:

  • Presents data on a TFT display with various screens to show different sets of information.
  • Automatically cycles through different display screens.

Program Flow:

  • On startup, the program initializes hardware and connects to WiFi.
  • It retrieves the initial water consumption data and sets up interrupts for the flow sensor.
  • The main loop continuously monitors the flow sensor and updates flow metrics.
  • Periodically, it fetches weather data, updates time, and sends data to ThingSpeak.
  • The TFT display cycles through different screens, showing various data metrics.

This program provides a comprehensive solution for monitoring environmental and flow data, displaying it in real-time, and logging it for remote monitoring.

Understanding the Code

Libraries Used:

  • Adafruit GFX and ST7735 libraries for display control.

NOTE:If you choose aliexpress 1.8 tft screen, attach this at arduino/libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST7735.cpp after an if statement search for the displayInit(Rcmd3); line, add this:setColRowStart(2, 1);

  • WiFi and WiFiClient libraries for network communication.
  • NTPClient for time synchronization.
  • AHT20 and Adafruit BMP280 libraries for sensor data.
  • Arduino_JSON for JSON parsing.
  • HTTPClient for making HTTP requests.
  • ThingSpeak library for IoT data logging.

Key Functions:

1. setup():

  • Initializes serial communication, WiFi, and sensors.
  • Configures the TFT display and shows initialization messages.
  • Connects to the WiFi network and retrieves the initial total water consumption from ThingSpeak.
  • Sets up an interrupt for the flow sensor.

2. loop():

  • Monitors water flow and calculates flow rate and total consumption.
  • Updates the TFT display with flow and weather data.
  • Periodically fetches weather data and updates time from the NTP server.
  • Logs data to ThingSpeak at regular intervals.
  • Changes the display screen periodically.

3. updateFlowRate():

  • Calculates the flow rate and total water consumption based on pulse counts from the flow sensor.

4. updateWeather():

  • Fetches current weather data from OpenWeatherMap and updates the display.

5. updateTFTDisplay(unsigned long elapsedTimeMillis):

  • Updates the TFT display with the elapsed time of water flow.

6. updateThingSpeakFields():

  • Sends current sensor readings to ThingSpeak.

7. updateTimeAndDate():

  • Synchronizes time with the NTP server and updates the display.

8. changeScreen():

  • Changes the TFT display screen to show different sets of information.

9. pulseCounter():

  • Interrupt service routine to count pulses from the flow sensor.

10. printWifiStatus():

  • Prints the current WiFi connection status.

11. flowscreen():

  • Displays real-time flow rate and total flow on the TFT display.

Serial Explanation

HTTP Response code: 200
Weather data: {"coord":{"lon":25.16,"lat":35.2356},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":298.86,"feels_like":298.87,"temp_min":298.77,"temp_max":300.38,"pressure":1011,"humidity":53,"sea_level":1011,"grnd_level":972},"visibility":10000,"wind":{"speed":9.77,"deg":300},"clouds":{"all":20},"dt":1719752140,"sys":{"type":2,"id":2002279,"country":"GR","sunrise":1719716878,"sunset":1719769074},"timezone":10800,"id":261741,"name":"Archanes","cod":200}Wind Speed : 9.00
Wind Direction: 300.00
Weather: Clouds
cloudLed, ON - noLed, OFF - Date changed at Sunday.Resetting totalMilliLitres and maxFlowRate.Flow rate: 0.00 L/min
Max Flow rate: 0.00 L/min
Daily Quantity: 0.00 L
Total: 201.28 L

Description:

  1. HTTP Response Code:
  • "HTTP Response code: 200" indicates a successful HTTP request.
  1. Weather Data:
  • JSON formatted string showing detailed weather information, including coordinates, weather conditions, temperature, pressure, humidity, wind speed, and direction, visibility, cloud cover, and timestamps for sunrise and sunset.
  1. Wind Speed:
  • "Wind Speed : 9.00" shows the current wind speed in the given unit.
  1. Wind Direction:
  • "Wind Direction: 300.00" indicates the direction of the wind in degrees.
  1. Weather:
  • "Weather: Clouds" summarizes the weather condition.
  1. LED Status:
  • "cloudLed, ON - noLed, OFF" indicates the status of two LEDs: one for clouds and one with no water order. That is a weather condition with clouds but temperature above 18 (adjust as you want).
  1. Date Change Notification:
  • "Date changed at Sunday. Resetting totalMilliLitres and maxFlowRate." signifies that the date has changed, prompting a reset of the totalMilliLitres and maxFlowRate values.
  1. Flow Rate:
  • "Flow rate: 0.00 L/min" displays the current flow rate in liters per minute.
  1. Max Flow Rate:
  • "Max Flow rate: 0.00 L/min" shows the maximum recorded flow rate for the day.
  1. Daily Quantity:
  • "Daily Quantity: 0.00 L" indicates the total volume of liquid measured for the current day.
  1. Total Volume:
  • "Total: 201.28 L" represents the cumulative total volume measured.

This output provides a comprehensive snapshot of current weather conditions, system statuses, and metrics relevant to the device's operations.

Update

30 Ιουνίου 2024

I recently updated the code. Initially, I had four switching screens, but now I have left three. The time that was previously displayed on one of the switching screens has been moved to another existing screen. Additionally, I implemented a daily reset for the max flowmeter and daily quantity and that reset is printed on serial. Finally, the wind direction is now displayed using letters, for example, N for North, S for South, and so on.

Update No2

ESP TFT
IMG_20240707_160940_817[1].jpg
IMG_20240707_160840_420[1].jpg

It seems there is room for improvement. First, I changed the arrangement of the screens. Then, I updated the code to store and retrieve new data from ThingSpeak in case of a power loss, including total time and quantity. Additionally, I implemented a screen that shows daily data. Last but not least, I have a python script in order to zeroize the data stored at thingspeak or send values for test purposes..