← back to projects
Project 02 · PLC · Beckhoff · TwinCAT 3

Refrigerator Control on a Beckhoff PLC

A refrigerator controller in Structured Text (IEC 61131-3), run on a Beckhoff IPC with real EtherCAT I/O. Door light, a timed door alarm that latches until reset, and compressor control around a setpoint, with an LM35 temperature sensor and a TwinCAT VISU HMI. Control Systems course at HAMK, spring 2026, Group 7.

Spring 2026Group of 4TwinCAT 3 · 4024Structured TextEtherCAT
See the testSource on GitHub
Beckhoff training panel
Beckhoff training panel: terminals on the DIN rail, toggle switch, buttons and LEDs for the inputs and outputs.
01 — Highlights

What it does

3EtherCAT terminals wired and scanned: EL1008 in, EL2008 out, EL3074 analog
10 sdoor-open delay before the alarm, TON timer, latched until reset
±1.0 °Ccompressor hysteresis around the 8.0 °C setpoint
10 mV/°CLM35 sensor on a 0–10 V input, REAL32
24.8 → 20.3 °CScope trace with the sensor in cold water, about 15 s
6 POUsbuilt step by step, from door light to compressor control
02 — Demonstration

Test on the real panel, 21 Apr 2026

TwinCAT Scope: LM35 in cold water
TwinCAT Scope logging the EL3074 value while the LM35 is put into cold water.

What was tested. The LM35 was put into cold water while TwinCAT Scope logged the analog input. The reading fell from about 24.8 °C to 20.3 °C in roughly 15 s and then levelled off.

During the same session the compressor output switched on and off around the setpoint, the yellow LED followed the door switch, and the red alarm LED came on after 10 s with the door open and stayed on until the reset button was pressed.

The VISU shows the actual temperature and has a knob for the setpoint, so the controller can be run from the lab monitor.

TwinCAT VISU on the lab monitor
TwinCAT VISU on the lab monitor
LM35 sensor in cold water
LM35 sensor in cold water
Beckhoff IPC
Beckhoff IPC
03 — How it works

I/O and programs

SignalHardware
DoorToggle switch on EL1008
Alarm resetMomentary button on EL1008
Interior lightYellow LED on EL2008
Door alarmRed LED on EL2008
CompressorGreen LED on EL2008
TemperatureLM35 on EL3074, 0–10 V, powered from 24 V
HMITwinCAT VISU: actual temperature, setpoint knob
  1. Fridge1: the light follows the door.
  2. Fridge2: door alarm with a TON timer, 10 s.
  3. Fridge2B: the alarm latches and stays on until reset.
  4. Fridge3A / 3B: compressor on above the 8.0 °C setpoint.
  5. TemperatureSimulator: compressor with ±1.0 °C hysteresis, and a warming model for testing without hardware.
  6. GVL: variables mapped to the terminals with AT %I* / AT %Q*.
04 — Code

Structured Text from the project

POUs/Fridge2B.TcPOU
// Fridge2B: light, door alarm after 10 s, latched until reset
bLight := bDoorOpen;

fbTimerDoorAlarm(IN := bDoorOpen, PT := T#10S);

IF fbTimerDoorAlarm.Q THEN
    bAlarmLatched := TRUE;
END_IF
IF bAlarmReset THEN
    bAlarmLatched := FALSE;
END_IF
bAlarmOut := bAlarmLatched;
POUs/TemperatureSimulator.TcPOU
// TemperatureSimulator: compressor with hysteresis
IF GVL_Var.fTempActual > (GVL_Var.fTempSet + GVL_Var.fHysteresis) THEN
    GVL_Var.bCompressure := TRUE;
END_IF
IF GVL_Var.fTempActual < (GVL_Var.fTempSet - GVL_Var.fHysteresis) THEN
    GVL_Var.bCompressure := FALSE;
END_IF

// warming: +0.1 C every 2 s, every 1 s with the door open
tImTemp := SEL(GVL_Var.bDoorOpen, T#2S, T#1S);
fbT2(IN := TRUE, PT := tImTemp, Q => bRaiseTemp);
IF bRaiseTemp THEN
    GVL_Var.fTempActual := GVL_Var.fTempActual + 0.1;
    fbT2(IN := FALSE);
END_IF
GVL with the variables mapped to physical I/O
GVL with the variables mapped to physical I/O
05 — Follow-up lab

PLC and a Dobot MG400

In the next lab the same PLC was wired to a Dobot MG400 with one signal in each direction: EL2008 output 4 to MG400 DI8, and MG400 DO8 to EL1008 input 8. The robot moved a part from a pick point to a cooling station, and the PLC released it to the output position once the temperature was low enough. The PLC program for this lab is not in the repository yet.

MG400 at the pick point
MG400 at the pick point
MG400 at the cooling station
MG400 at the cooling station
06 — Team

Group 7

Sazzad Ibna Mahfuz, Ahmad Tanveer, Muhammad Taqi, Pramoda Medis. Work covered I/O wiring, EtherCAT device scan, mapping GVL variables to the terminals, the ST programs from light control to latched alarm and compressor control, the VISU, and logging the sensor in TwinCAT Scope.

Known gaps: the cooling branch of the simulator is declared but not written, so in simulation the temperature only rises; bCompressor and bCompressure are two separate variables.

← Previous projectGift Box Packing Cell Back →All projects