0
0
FreertosHow-ToBeginner · 4 min read

How to Interface Temperature Sensor with PLC: Step-by-Step Guide

To interface a temperature sensor with a PLC, connect the sensor output to an analog input module of the PLC and configure the input scaling. Then, use PLC programming to read the analog value and convert it to temperature using the sensor's characteristics.
📐

Syntax

Interfacing a temperature sensor with a PLC involves these key steps:

  • Wiring: Connect sensor output to the PLC's analog input channel.
  • Scaling: Configure the PLC to convert raw analog input (e.g., 4-20mA or 0-10V) to temperature units.
  • Programming: Use analog input read instructions and math operations to calculate temperature.
structured_text
ANALOG_INPUT := ReadAnalogInput(Channel);
TEMPERATURE := (ANALOG_INPUT - OFFSET) * SCALE_FACTOR;
💻

Example

This example shows how to read a 4-20mA temperature sensor connected to analog input channel 1 and convert it to degrees Celsius in Structured Text (ST) language.

structured_text
VAR
  RawInput : INT; (* Raw analog input value from 0 to 27648 for 4-20mA *)
  Temperature : REAL; (* Calculated temperature in Celsius *)
END_VAR

(* Read raw analog input from channel 1 *)
RawInput := AI_Channel1;

(* Convert raw input to temperature *)
(* 4mA corresponds to 0°C, 20mA corresponds to 100°C *)
Temperature := (REAL(RawInput) - 5529.6) * (100.0 / (27648.0 - 5529.6));
Output
If AI_Channel1 = 16589 then Temperature = 50.0
⚠️

Common Pitfalls

Common mistakes when interfacing temperature sensors with PLCs include:

  • Incorrect wiring causing no signal or damage.
  • Not calibrating or scaling the analog input correctly, leading to wrong temperature readings.
  • Ignoring sensor type and output range (e.g., confusing 0-10V with 4-20mA).
  • Not filtering noise on analog signals, causing unstable readings.
structured_text
(* Wrong scaling example: treating 4-20mA as 0-20mA *)
Temperature := (REAL(RawInput) * 100.0) / 27648.0;  (* Incorrect, causes offset error *)

(* Correct scaling example: subtract offset for 4mA *)
Temperature := (REAL(RawInput) - 5529.6) * (100.0 / (27648.0 - 5529.6));
📊

Quick Reference

Tips for successful temperature sensor interfacing:

  • Always check sensor output type and range.
  • Use proper analog input modules compatible with sensor signals.
  • Calibrate scaling in PLC program to match sensor specs.
  • Test wiring and signal with a multimeter before programming.
  • Use filtering or averaging in software to stabilize readings.

Key Takeaways

Connect the temperature sensor output to the PLC's analog input module correctly.
Configure and scale the analog input in the PLC program to convert raw signals to temperature.
Always verify sensor type and output range before wiring and programming.
Use filtering or averaging in PLC code to get stable temperature readings.
Test wiring and calibration thoroughly to avoid incorrect temperature values.