This project implements a Digital Twin of an industrial process using a Python-based Modbus TCP server and Node-RED.
The Python application acts as a virtual PLC / industrial process simulator, generating continuously changing sensor values such as:
- Temperature
- Pressure
- Valve Status
The simulated data is exposed through Modbus TCP Holding Registers, which are then read by Node-RED. Node-RED is used for data processing, monitoring, visualization, and alarm generation through a dashboard.
┌──────────────────────────┐
│ Python Simulator │
│ │
│ Temperature │
│ Pressure │
│ Valve Status │
└────────────┬─────────────┘
│
│ Modbus TCP
│ Port 5020
▼
┌──────────────────────────┐
│ Node-RED │
│ │
│ Modbus Read │
│ Data Processing │
│ Alarm Logic │
│ Dashboard │
└────────────┬─────────────┘
│
▼
┌──────────────────────────┐
│ Digital Twin HMI │
│ │
│ Temperature │
│ Pressure │
│ Valve Status │
│ Trends / Alarms │
└──────────────────────────┘
The main objectives of this project are:
- Simulate an industrial process without requiring physical PLC hardware.
- Implement a Modbus TCP server using Python.
- Generate dynamic sensor values to represent an industrial process.
- Use Node-RED to communicate with the virtual PLC.
- Visualize real-time process parameters through a dashboard.
- Demonstrate the basic architecture of an industrial Digital Twin.
- Provide a foundation for adding alarms, control logic, data logging, and predictive maintenance.
The project represents a simplified industrial process containing a temperature sensor, pressure sensor, and control valve.
The Python program acts as a virtual PLC connected to a simulated process.
Every two seconds, the simulator generates new temperature and pressure values:
Temperature: 20–90 °C
Pressure: 90–160 PSI
These values are written into Modbus Holding Registers.
Node-RED periodically reads these registers and presents the information through a graphical dashboard.
| Technology | Purpose |
|---|---|
| Python | Industrial process simulation |
| PyModbus | Modbus TCP server |
| Modbus TCP | Industrial communication protocol |
| Node-RED | Data processing and visualization |
| Node-RED Dashboard | HMI / Digital Twin interface |
| Threading | Continuous sensor simulation |
The simulator uses Holding Registers (HR) for process data.
| Register | Parameter | Unit | Example Range |
|---|---|---|---|
| HR0 | Temperature | °C | 20–90 |
| HR1 | Pressure | PSI | 90–160 |
| HR2 | Valve Status | — | 0 / 1 |
The valve can be represented using:
0 → Closed
1 → Open
Note: The original Python code comments indicate
0as "Valve Open". The README uses the conventional mapping0 = Closedand1 = Open. Ensure that the Python and Node-RED implementations use the same mapping.
The Python program performs three major functions.
The following holding registers are initialized:
hr=ModbusSequentialDataBlock(
0,
[25, 100, 0]
)This represents:
HR0 = 25 °C
HR1 = 100 PSI
HR2 = Valve Status
A background thread continuously generates new values:
temp = random.randint(20, 90)
press = random.randint(90, 160)The values are then written to the Modbus registers:
store.setValues(3, 0, [temp])
store.setValues(3, 1, [press])The simulator updates the process every 2 seconds.
The Modbus server listens on:
IP Address: 127.0.0.1
Port: 5020
Node-RED can therefore communicate with the virtual PLC using:
127.0.0.1:5020
Install the following software:
- Python 3.x
- Node.js
- Node-RED
- Web browser
- PyModbus
git clone https://github.com/<your-username>/<repository-name>.git
cd <repository-name>pip install pymodbusDepending on the PyModbus version being used, the API and imports may differ. This project uses the API style shown in the simulator code.
Run:
python simulator.pyYou should see:
Industrial PLC Simulator started on localhost:5020...
The terminal will then periodically display values similar to:
PLC Update -> Temp: 47°C, Pressure: 132 PSI
PLC Update -> Temp: 63°C, Pressure: 101 PSI
PLC Update -> Temp: 29°C, Pressure: 148 PSI
This confirms that the virtual process is generating dynamic values.
Start Node-RED:
node-redOpen the Node-RED editor in your browser:
http://localhost:1880
Configure the Node-RED Modbus client to connect to:
Host: 127.0.0.1
Port: 5020
Use the appropriate Modbus Read nodes to read the Holding Registers.
Example:
Modbus Read
│
▼
HR0 → Temperature
HR1 → Pressure
HR2 → Valve Status
The exact address configuration may depend on the Node-RED Modbus package and whether it uses zero-based or one-based addressing.
A basic Digital Twin flow can be structured as:
┌───────────────┐
│ Modbus Read │
└───────┬───────┘
│
▼
┌───────────────┐
│ Function │
│ Data Mapping │
└───────┬───────┘
│
┌───────────┼───────────┐
▼ ▼ ▼
Temperature Pressure Valve Status
│ │ │
▼ ▼ ▼
Gauge/Chart Gauge/Chart Indicator
│ │ │
└───────────┼───────────┘
▼
┌───────────────┐
│ Digital Twin │
│ Dashboard │
└───────────────┘
The Node-RED dashboard can contain the following components.
Display the current temperature using:
- Gauge
- Numerical indicator
- Time-series chart
Example:
Temperature
57 °C
Display the current pressure:
Pressure
134 PSI
A time-series chart can be used to visualize pressure variation.
Use an indicator to display the current valve condition:
VALVE STATUS
OPEN
or:
VALVE STATUS
CLOSED
Node-RED can implement basic industrial alarm logic.
For example:
Temperature > 80 °C
↓
High Temperature Alarm
Similarly:
Pressure > 150 PSI
↓
High Pressure Alarm
Example Node-RED function logic:
if (temperature > 80) {
msg.payload = "HIGH TEMPERATURE ALARM";
}
return msg;The project demonstrates the basic concept of a Digital Twin by maintaining a digital representation of an industrial process.
Physical Process
│
│ Sensor Data
▼
PLC / RTU
│
│ Modbus TCP
▼
Digital Representation
│
▼
Node-RED
│
├── Visualization
├── Monitoring
├── Alarms
└── Data Analysis
In this project, the physical process is replaced by a software-based process simulator.
Therefore:
Python Simulator
↓
Virtual PLC
↓
Modbus TCP
↓
Node-RED
↓
Digital Twin Dashboard
digital-twin-node-red/
│
├── simulator.py
├── README.md
│
├── node-red/
│ └── flows.json
│
├── screenshots/
│ ├── dashboard.png
│ └── node-red-flow.png
│
└── docs/
└── architecture.png
The current project can be extended into a more realistic industrial Digital Twin.
Instead of completely random values, implement:
- Gradual temperature changes
- Pressure dynamics
- Process disturbances
- Sensor noise
- Equipment response time
Example:
Temperature
│
90°C ┤ ╭───
│ ╭──╯
60°C ┤ ╭───╯
│ ╭──╯
30°C ┤───╯
└────────────────── Time
Allow Node-RED to send commands back to Python:
Node-RED
│
│ Modbus Write
▼
Python Simulator
│
▼
Virtual Valve
This would convert the project from a monitoring-only Digital Twin into a closed-loop simulation.
Store historical process data using:
- SQLite
- InfluxDB
- PostgreSQL
This enables trend analysis and historical visualization.
Historical data can be analyzed to detect abnormal operating conditions.
Example:
Normal Pressure
↓
Increasing Temperature
↓
Abnormal Condition
↓
Maintenance Alert
The random-value generator can eventually be replaced by a mathematical process model.
For example:
Tank
↓
Pump
↓
Valve
↓
Pipeline
↓
Process
This would make the Digital Twin more representative of a real industrial system.
This project is intended for education, simulation, and laboratory experimentation.
The Modbus TCP server binds to:
127.0.0.1
which restricts communication to the local machine.
For real industrial deployment, additional considerations would be required, including:
- Network segmentation
- Authentication
- Access control
- Firewalls
- Secure industrial protocols
- PLC safety systems
- Industrial cybersecurity practices
After completing this project, you should understand:
- How Modbus TCP communication works
- How PLC registers can be simulated using Python
- How sensor data can be generated programmatically
- How Node-RED communicates with industrial devices
- How industrial data can be visualized
- How alarms can be implemented
- How a basic Digital Twin architecture is structured
- How a software simulator can replace physical industrial hardware during development
Industrial Automation / Digital Twin Project
The project can be further developed into a complete Industrial Digital Twin platform by integrating:
Python Process Model
│
▼
Virtual PLC
│
▼
Modbus TCP
│
▼
Node-RED
│
┌──────┼─────────┐
▼ ▼ ▼
HMI Database Alarms
│ │ │
└──────┼─────────┘
▼
Analytics / AI
│
▼
Predictive Maintenance
This provides a foundation for demonstrating PLC communication, SCADA/HMI concepts, industrial networking, process monitoring, and Digital Twin technology.