Notifications
Clear all

Smart Weather Warning Terminal System Based on ESP32-P4

7 Posts
2 Users
1 Reactions
367 Views
Yassin
(@yassin)
Member
Joined: 5 months ago
Posts: 47
Topic starter  
Abstract

 

Hello everyone, I'm Yassin. Under the trend of the intelligent connection of all things, I have designed and implemented a smart weather warning terminal system based on ESP32-P4. The system consists of two main parts: a meteorological data acquisition board and a display terminal. It can collect various environmental data in real time, including temperature and humidity, air pressure, light intensity, ultraviolet radiation, carbon dioxide concentration, wind speed and direction, as well as lightning warning information. All data is wirelessly transmitted to the display terminal via LoRa for visual presentation. Adopting a modular design concept, the system completes the whole development process from scheme design to physical realization, covering sensor selection, hardware circuit design, communication protocol formulation and software programming. It is a typical application of Internet of Things technology in the field of environmental monitoring.

 
Application Scenarios

 

This system is suitable for various scenarios requiring real-time meteorological monitoring and early warning, with broad application value:

 
Smart Agriculture: Real-time monitoring of farmland microclimate, including key parameters such as temperature, humidity, light intensity and carbon dioxide concentration, provides data support for precision irrigation, scientific fertilization and pest control. Meanwhile, the lightning warning function can remind farmers to take protective measures in advance and reduce economic losses.
 
Urban Environmental Monitoring: Deployed in public places such as communities, campuses and parks, it provides local meteorological information services and real-time data including air quality and temperature-humidity comfort level. The severe weather early warning function helps residents prepare in advance and improve the intelligent management level of cities.
1
2
Hardware Selection and Circuit Design

 

The acquisition board is mainly responsible for collecting meteorological data. The main controller uses the STM32F103 chip, and the display panel is built with the M5STACK TAB5 development board. All key components are supported and supplied by DigiKey. The specific hardware selection is as follows:

 
  1. Main Control Chip of Acquisition Board

     

    STM32F103: A high-performance 32-bit microcontroller launched by STMicroelectronics based on the ARM Cortex-M3 core. It is widely used in embedded introductory learning and common embedded products, with abundant resources, massive tutorials and easy development.

     
  2. Sensor Modules

     

    Temperature and Humidity Sensor: The AHT20 is a high-precision, fully calibrated I2C digital output composite temperature and humidity sensor. It adopts a new-generation dedicated ASIC chip, improved MEMS capacitive humidity sensing element and integrated on-chip temperature sensing element. With reliable performance, plug-and-play feature and excellent cost performance, it is a mainstream option for temperature and humidity detection in embedded projects and consumer electronics.

     
 
Air Pressure Sensor: The BME280 pressure sensor communicates via the I2C interface. It features high precision and low power consumption, making it ideal for meteorological monitoring. Its pressure measurement accuracy reaches ±1hPa, which fully meets the accuracy requirements of weather monitoring.
3
Light Intensity Sensor: The BH1750 is a digital ambient light intensity sensor. It outputs 16-bit digital signals through the I2C interface, with a measurement range of 0 to 65535 lux, and can work without external components. Adopting ROHM photodiode technology, it features spectral response close to the human eye and ultra-low power consumption with a typical current of 0.12μA. It supports high-resolution mode with 1lx accuracy and low-power mode, and is widely used in automatic backlight adjustment systems for smartphones, tablets, smart home devices and other products.
4
Ultraviolet Sensor: The S12SD is an analog-output UV‑band ultraviolet sensor for UV‑B. Its measuring wavelength ranges from 280nm to 315nm, and the output current is proportional to UV intensity. Adopting GaN-based photodiode technology, it features high sensitivity and fast response. The operating voltage is 2.7‑5.5V with a power consumption of only 0.1mA. It is suitable for outdoor ultraviolet monitoring, sun protection reminders, meteorological monitoring and other scenarios, and can be directly connected to the ADC interface of the MCU.
5
Carbon Dioxide Sensor: The SGP30 adopts metal oxide semiconductor technology to measure CO₂ concentration and TVOC (Total Volatile Organic Compounds). It communicates via the I2C interface with fast response speed and low power consumption. The CO₂ measurement range is 400 to 60000 ppm, and the TVOC measurement range is 0 to 60000 ppb, which can effectively monitor air quality.
6

Wind Speed and Direction Sensor: A sensor with 485 communication interface is selected. It adopts RS485 communication and supports the Modbus protocol, featuring high measurement accuracy and excellent stability. The wind speed measuring range is 0-60m/s, and the wind direction measuring range is 0-360°. It requires 12V power supply, which is converted by a boost module.

7
Lightning Early Warning Sensor: The AS3935 module is adopted. It can detect lightning activities and provide data of lightning distance and intensity. Supporting I2C and SPI communication interfaces, it realizes early lightning risk warning and ensures the safety of outdoor equipment.
8
Screen Display Module: A 0.96-inch OLED module is adopted. It features low power consumption, high display brightness and a wide viewing angle, and realizes data display through IIC communication.
9
   3.Communication Module

 

LoRa Module: A LoRa module equipped with the SX1278 chip is selected. Adopting LoRa modulation technology, it features long transmission distance (up to several kilometers), low power consumption and strong anti-interference ability, which is highly suitable for meteorological monitoring scenarios requiring long-distance and low-power data transmission.

10
System Hardware Block Diagram:
 
11
  1. Display Board Hardware
     

    The Tab5 is a highly expandable and portable intelligent IoT terminal development device for developers, integrating a dual-chip architecture and abundant hardware resources. Its main controller adopts the ESP32‑P4 SoC based on the RISC‑V architecture, equipped with 16MB Flash and 32MB PSRAM. The wireless module adopts ESP32-C6-MINI-1U with Wi-Fi 6 support. Its antenna system can be freely switched between the built-in 3D antenna and the external MMCX antenna interface, adapting to various deployment scenarios flexibly to guarantee stable data throughput and low-latency control.

12
5.Power Management

 

Power Supply Unit: The AMS1117-3.3 voltage regulator chip is used to convert external 5V voltage to 3.3V, providing stable power for all rear-end sensors and display devices.

13
Boost Module: The S09 DC-DC boost module is adopted to step up 5V voltage to 12V, supplying power for the wind speed and direction sensor.
14
6.Hardware Design

 

Schematic Design of Acquisition Board:

15
PCB Design Drawing of Acquisition Board:
16
Physical Image After Welding:
 

(The file exceeds 10MB and cannot be uploaded. I have no idea why it cannot be compressed further.)

 

Software Development

 

The software part is developed based on the Arduino framework environment, adopting the modular programming concept to improve code readability and maintainability. The specific implementation is as follows:

 
  1. Development Environment Setup
     

    The acquisition board is developed using STM32Cubemx + Keil5, the common tools for STM32.

18
19
Arduino Framework: Developed based on the Arduino framework, making full use of abundant third-party library resources to improve development efficiency.
20
  1. Firmware Design of Acquisition Board
     

    Sensor Drivers: Independent driver functions are developed for each sensor, including initialization, data reading, and data conversion, achieving a modular design for easy maintenance and expansion.

 
Data Acquisition: Timed acquisition mode is adopted, with sensor data collected every 500ms.
 
		//每0.5S获取传感器数据
		if (CompareTime(&TimeSensor_Get))
    {
        SetTime(&TimeSensor_Get, 500); // 每500ms进来一次

				AHT20_Get_Value(&Humiture);
				
				bmp280_read_float(&bmp280_dev, &temperature, &pressure, &humidity);							
				Alt=data_conversion(pressure,temperature);
				pressurehpa=pressure*2/100.0;

			
				BH1750_ReadData(g_ucaDataBuff,2);/*获取照度数据*/
        ftmp = (g_ucaDataBuff[0]<<8 | g_ucaDataBuff[1]) / 1.2f + 0.5f;/*转换照度数据*/
        g_usLux = (uint16_t)ftmp;	
										
				ult_value = Get_ADC_Value();	
				UV_VALUE = Get_Ultraviolet_Intensity(ult_value);
				
			//SGP30读取
				if (sgp30_read(&CO2, &TVOC) == 0)
				{
						sgp30_data.CO2 = CO2;
						sgp30_data.TVOC = TVOC;
		//        usartPrintf(huart1, "CO2: %d ppm, TVOC: %d ppb\r\n", CO2, TVOC);
				}
				else
				{
		//        usartPrintf(huart1, "SGP30 read failed\r\n");
				}

			
			  GET_Wind_Speed_Data();
			GET_Wind_Direction_Data();

		}	
LoRa Transmission: The encapsulated data frames are sent via the LoRa module, supporting a data retransmission mechanism to ensure the reliability of data transmission.
		if (CompareTime(&TimeWiFi_Send))
    {
			SetTime(&TimeWiFi_Send, 500); // 每3000ms进来一次
			static char jsonString[300]; // 假设 JSON 字符串不超过 512 字节
			snprintf(jsonString, sizeof(jsonString),
					"{\"T\":%.1f,\"H\":%.1f,\"P\":%.1f,\"L\":%u,"
					"\"UV\":%d,\"TVOC\":%d,\"Ws\":%.1f,\"Wl\":%.1f,"
					"\"Fx\":\"%s\",\"Wa\":%.1f,\"Ld\":%d}",
					Humiture.Temp,
					Humiture.RH,
					pressurehpa,
					g_usLux,
					UV_VALUE,
					TVOC,
					windSpeed,
					windLevel,
					fengxiang,
					Wind_Angle,
					lightning_distance
			);


			usartPrintf(huart1, "%s\r\n", jsonString);		
			
		}
 
  1. Firmware Design of Display Board
     

    LoRa Reception: The data frames sent by the acquisition board are received through the LoRa module. JSON parsing is adopted to extract sensor data, and unit conversion and data processing are performed.

void parseSerialJSON() {
  while (mySerial.available()) {
    char c = mySerial.read();

    if (c == '\n') {

      StaticJsonDocument<512> doc;
      DeserializationError err = deserializeJson(doc, serialBuffer);

      if (!err) {

        // ===== 温湿度 & 气压 =====
        if (doc.containsKey("T"))
          sensorData.temperature = doc["T"].as<float>();

        if (doc.containsKey("H"))
          sensorData.humidity = doc["H"].as<float>();

        if (doc.containsKey("P"))
          sensorData.pressure = doc["P"].as<float>();

        // ===== 光照 =====
        if (doc.containsKey("L"))
          sensorData.lightLux = doc["L"].as<uint32_t>();

        // ===== UV =====
        if (doc.containsKey("UV"))
          sensorData.uv = doc["UV"].as<int>();

        // ===== TVOC =====
        if (doc.containsKey("TVOC"))
          sensorData.tvoc = doc["TVOC"].as<int>();

        // ===== 风速 & 风力 =====
        if (doc.containsKey("Ws"))
          sensorData.windSpeed = doc["Ws"].as<float>();

        if (doc.containsKey("Wl"))
          sensorData.windLevel = doc["Wl"].as<float>();

        // ===== 风向字符串 =====
        if (doc.containsKey("Fx")) {
          const char* fx = doc["Fx"];
          strncpy(sensorData.windDirStr, fx,
                  sizeof(sensorData.windDirStr) - 1);
          sensorData.windDirStr[sizeof(sensorData.windDirStr) - 1] = '\0';
        }

        // ===== 风向角 =====
        if (doc.containsKey("Wa"))
          sensorData.windAngle = doc["Wa"].as<float>();

        // ===== 雷电距离=====
        if (doc.containsKey("Ld")) {
            sensorData.lightningDistance = doc["Ld"].as<float>();
            sensorData.lightning = (sensorData.lightningDistance > 0);
        }

        drawUI();
      }

      serialBuffer = "";
    }
    else {
      if (serialBuffer.length() < 512)
        serialBuffer += c;
      else
        serialBuffer = "";
    }
  }

}
 
 
Graphical User Interface: The GUI is developed based on the LVGL library, including the main interface, data details interface, historical data interface, etc. The main interface displays real-time meteorological parameters such as temperature, humidity, air pressure, light intensity, ultraviolet intensity, CO₂ concentration, wind speed, wind direction, as well as lightning warning information.
 
void drawUI() {
  canvas.fillScreen(TFT_WHITE);
  uint16_t greenColor = display.color565(120, 180, 70);
  // ===== 顶部标题条 =====
  canvas.fillRoundRect(0, 0, screenWidth, 60, 4, greenColor);
  canvas.setTextDatum(TL_DATUM);
  canvas.setTextSize(3);
  canvas.setTextColor(TFT_WHITE);
  canvas.drawString("Weather IOT Platform", 20, 20);
  char buf[16];
  int row = 0;
  // ================= 第 1 行 =================
  // 温度
  snprintf(buf, sizeof(buf), "%.1f", sensorData.temperature);
  drawCard(marginSide + 0 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "TEMP", buf, "C");
  // 湿度
  snprintf(buf, sizeof(buf), "%.0f", sensorData.humidity);
  drawCard(marginSide + 1 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "HUMID", buf, "%");
  // 气压
  snprintf(buf, sizeof(buf), "%.0f", sensorData.pressure);
  drawCard(marginSide + 2 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "PRESS", buf, "hPa");
  // 光照
  snprintf(buf, sizeof(buf), "%u", sensorData.lightLux);
  drawCard(marginSide + 3 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "LIGHT", buf, "Lux");
  // ================= 第 2 行 =================
  row = 1;
  // UV
  snprintf(buf, sizeof(buf), "%d", sensorData.uv);
  drawCard(marginSide + 0 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "UV", buf, "UV");
  // TVOC
  snprintf(buf, sizeof(buf), "%d", sensorData.tvoc);
  drawCard(marginSide + 1 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "CO2", buf, "ppb");
  // 雷电距离
  snprintf(buf, sizeof(buf), "%.1f", sensorData.lightningDistance);
  drawCard(marginSide + 2 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "LIGHT DIST", buf, "km");
  // 雷电状态
  if (sensorData.lightning) {
    strcpy(buf, "ALERT");
  } else {
    strcpy(buf, "NORMAL");
  }
  drawCard(marginSide + 3 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "LIGHT STATE", buf, "");
  // ================= 第 3 行 =================
  row = 2;
  // 风速
  snprintf(buf, sizeof(buf), "%.1f", sensorData.windSpeed);
  drawCard(marginSide + 0 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "WIND SPD", buf, "m/s");
  // 风等级
  snprintf(buf, sizeof(buf), "%.1f", sensorData.windLevel);
  drawCard(marginSide + 1 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "WIND LV", buf, "");
  // 风向
  snprintf(buf, sizeof(buf), "%s", sensorData.windDirStr);
  drawCard(marginSide + 2 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "WIND DIR", buf, "");
  // 风向角
  snprintf(buf, sizeof(buf), "%.1f", sensorData.windAngle);
  drawCard(marginSide + 3 * (cardWidth + spacingX),
           marginTop + row * (cardHeight + spacingY),
           cardWidth, cardHeight, "WIND ANG", buf, "o");
  canvas.pushSprite(0, 0);
}

 

So far, the three core functions of meteorological data collection, transmission and display have been completed. The modular design is adopted mainly to shorten the development cycle and verify system functions quickly.

 

In the upgraded version, all external modules will be replaced with on-board components to reduce the overall size. Meanwhile, lithium battery management and solar power supply modules will be added to realize independent data collection and self-sustaining power management.

 
Thank you for your careful reading. Due to my limited technical ability, I sincerely welcome any comments and corrections for omissions or errors in this project.

Yassin

 

Yassin | Building Compact, High-Current Connections for Drones & Robots


   
Quote
Yassin
(@yassin)
Member
Joined: 5 months ago
Posts: 47
Topic starter  
I am willing to open-source the acquisition and display code. However, the compressed file package is still 29.7M, which exceeds the upload limit and cannot be uploaded directly. Friends in need can contact me via email or WeChat to get the source code.

Yassin | Building Compact, High-Current Connections for Drones & Robots


   
maximuz4 reacted
ReplyQuote
(@maximuz4)
Member
Joined: 1 month ago
Posts: 11
 

Hello @yassin, I will be working on a project on solar energy output forecasting and IOT monitoring, I notice you used the BH1750 light sensor to get the value of solar irradiance, although the BH1750 give it output in lux and not W/m^2,

I will be converting it value in lux to W/m^2 by multiplying by a factor of 0.0079 OR dividing by a range from 210-220.

My current challenge comes from the max lux output of the BH1750 light sensor(65355) I need to be able to get up to 120,000 LUX: what can i do?

I saw a software fix by setting the value of MTReg() to a lower value from it default value of 69 to 31...
i don't know how this would work out though as I haven't tested it out.



   
ReplyQuote
Yassin
(@yassin)
Member
Joined: 5 months ago
Posts: 47
Topic starter  

@maximuz4 

Hi there, great to see you’re working on solar irradiance monitoring and IoT projects!
For the BH1750’s upper limit of 65535 lux, changing the MTreg register from 69 to 31 does work to extend the measurable range beyond 65535 lux, so you can get close to 120,000 lux for solar forecasting. Just keep in mind that resolution will decrease slightly at very high light intensity.
You can also use a physical light-shading filter (neutral density filter) over the sensor for more stable high-light readings, which is more reliable than software adjustment alone. The conversion from lux to W/m² using 0.0079 or 1/210–1/220 is a standard and practical method in solar projects.

Yassin | Building Compact, High-Current Connections for Drones & Robots


   
ReplyQuote
(@maximuz4)
Member
Joined: 1 month ago
Posts: 11
 

@yassin 
Great to know! Then neutral density filter option is a bit confusing to know which filter resolution or type to use. 

I also saw the "red BH1750 module" that comes with a white plastic dome that can vary the light sensed by the sensor and reduces the chance of it maxing out at direct sunlight(noon).


This post was modified 2 weeks ago by maximuz4

   
ReplyQuote
Yassin
(@yassin)
Member
Joined: 5 months ago
Posts: 47
Topic starter  

@maximuz4

The red BH1750 board with the white dome is a really good choice for outdoor use. That dome helps diffuse direct sunlight and keeps the sensor from hitting its upper limit easily, which works perfectly for measuring strong daylight.
If you want to use a neutral density filter, just pick one with standard light attenuation like ND‑8 or ND‑16,a light reduction type with 50%–70% transmittance. They’ll bring high light levels down into a readable range without losing accuracy.
Using either the dome or a filter together with the MTreg setting should handle 120,000 lux reliably for your solar project.

This post was modified 1 week ago by Yassin

Yassin | Building Compact, High-Current Connections for Drones & Robots


   
ReplyQuote
(@maximuz4)
Member
Joined: 1 month ago
Posts: 11
 

@yassin Thanks a lot man!



   
ReplyQuote