Temperature and Humidity Monitoring, PLC Helps You Record Data!
Recording temperature and humidity data is particularly important in factory workshops, warehouses, and agricultural greenhouses. Today, we will use Siemens S7-1200 to create a temperature and humidity recording system that achieves real-time monitoring, recording, and alarm functionalities.
Temperature and Humidity Monitoring + Data Recording
Assuming a warehouse needs to record temperature and humidity data, the following functionalities are required:
-
Real-time monitoring of temperature and humidity data displayed on the touchscreen. -
Trigger an alarm when the set temperature and humidity range is exceeded. -
Record data every 5 minutes for subsequent analysis.
Hardware Requirements
-
Siemens S7-1200 PLC -
Temperature and humidity sensor (with analog output, e.g., 4-20mA) -
Alarm buzzer -
Touchscreen (e.g., KTP series, used to display temperature and humidity data and alarm information) -
Storage card (PLC expansion module, used to save historical data)
Potential Issues
-
High Data Recording Frequency: A short data recording interval will occupy the PLC’s storage resources, affecting performance. -
Inaccurate Signal Conversion: The analog signal from the sensor may need calibration to avoid data deviation. -
Frequent Alarms Disrupt Operations: When temperature and humidity fluctuate, the alarm state can repeatedly occur, affecting the operator’s judgment.
We will solve these issues one by one.
Program Logic Design
The functionalities are divided into several modules:
-
Sensor Signal Processing -
Alarm Logic -
Data Recording -
Touchscreen Display
Analog Signal Processing
The output of the temperature and humidity sensor is a 4-20mA signal, which the PLC needs to convert into actual temperature and humidity values. Code example:
// Analog input processing
// Temperature calculation
Temperature := (REAL_TO_INT(AIW64) * 100.0 / 27648.0) - 50.0; // Assuming range is -50 to 50℃
// Humidity calculation
Humidity := (REAL_TO_INT(AIW66) * 100.0 / 27648.0); // Assuming range is 0 to 100%RH
This uses the conversion formula for analog data, mapping the PLC input range (0-27648) linearly to actual temperature and humidity values.
Alarm Logic
If the temperature and humidity exceed the set range (e.g., temperature greater than 30℃ or humidity greater than 70%), trigger the alarm logic. Here, we add a delay to avoid false alarms due to fluctuations:
// Temperature and humidity alarm logic
Network 1
A Temperature > 30.0 // Temperature exceeds 30℃
O Humidity > 70.0 // Humidity exceeds 70%
L T1 // Timer
= M0.0 // Stable alarm signal
TON T1, T#5s // Delay 5 seconds to avoid false alarms
// Alarm buzzer
Network 2
A M0.0
= Q0.0 // Alarm buzzer
Data Recording Logic
Data recording uses the PLC’s storage function to save temperature and humidity values to the storage card every 5 minutes. Code example:
// Timer triggers recording
IF Timer_5min.Q THEN
WriteData(Temperature, Humidity); // Call data recording function
Timer_5min.IN := FALSE; // Restart timer
END_IF;
// Timer settings
Timer_5min.IN := TRUE;
Timer_5min.PT := T#5m; // Set 5-minute timer
<span>WriteData</span>
is a function for writing data to save the temperature and humidity values to the storage card. The specific implementation can use the PLC’s file writing instructions, such as<span>WRREC</span>
.
Touchscreen Display
The touchscreen displays the current temperature and humidity values and alarm status, easily achieved through PLC variables:
// Data transfer to touchscreen
HMI_Temperature := Temperature;
HMI_Humidity := Humidity;
HMI_Alarm := M0.0; // Alarm signal
In the touchscreen, bind these variables to the corresponding display controls to see the data in real-time.
Optimization Solutions
-
Data Recording Frequency Issues: Adjust the recording interval according to actual needs, such as recording every 10 or 15 minutes, to reduce storage pressure. -
Signal Conversion Issues: Use multiple data points to average, filtering out signal noise to stabilize the data. -
Alarm Interference Issues: Add an alarm history function to save alarm times and reasons for subsequent troubleshooting.
Check and Test
After writing the program, check the following:
-
Simulate temperature and humidity signals to test if the data conversion is accurate and if the alarm logic is functioning correctly. -
Check the historical data on the storage card to ensure the recorded times and values are correct. -
Verify if the touchscreen display updates in real-time and if the alarm status is synchronized.
Conclusion
The temperature and humidity data recording system is actually not complex; the key is clear logic and accurate data. When writing the program, pay attention to signal processing and data recording frequency, and the system’s stability will be ensured.
If you have any questions, feel free to leave a message, and we can solve them together!