A web-based PLC ladder logic simulator that interprets LDmicro text exports and runs them on a virtual training board with interactive inputs and outputs.
- Text Export Focus: Import ladder logic from LDmicro text ladder diagram export
- Interactive Virtual Board: Simulates a physical PLC training board with:
- π Sensors (light, proximity, motion, trigger, metal detectors)
- π² Toggle switches (S1, S2, S3)
- π’ Push buttons (BTN1, BTN2, BTN3)
- π Fans (FAN1, FAN2, FAN3)
- π‘ Indicator lights (H1-green, H2-yellow, H3-red)
- π¨ Panic strobe and buzzer
- Real-time Simulation: Execute PLC cycles with adjustable speed
- Step Debugging: Single-step through the ladder logic
- Modern UI: Industrial control panel aesthetic with responsive design
# Clone the repository
git clone https://github.com/soggy8/LDmicroWebSim.git
cd LDmicroWebSim
# Start with Docker Compose
docker-compose up -d
# Open in browser
open http://localhost:8000# Clone the repository
git clone https://github.com/soggy8/LDmicroWebSim.git
cd LDmicroWebSim
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the server
python server.pyThen open http://localhost:8000 in your browser.
In LDmicro, export your ladder diagram as text:
- Text Format: File β Export As β Text
Either:
- Paste the exported code directly into the editor
- Click "Upload" to load a file
- Click "Load Example" for a demo
- Click Compile to parse the ladder logic
- Click Run to start the simulation
- Interact with the virtual board inputs
- Watch the outputs respond in real-time!
| Element | Symbol | Description |
|---|---|---|
| Normally Open Contact | ] [ |
True when input is ON |
| Normally Closed Contact | ]/[ |
True when input is OFF |
| Output Coil | ( ) |
Energize output |
| Set Coil | (S) |
Latch ON |
| Reset Coil | (R) |
Latch OFF |
| Timer On-Delay | [TON] |
Delay before turning ON |
| Timer Off-Delay | [TOF] |
Delay before turning OFF |
| Counter Up | [CTU] |
Count up |
| Counter Down | [CTD] |
Count down |
Use these names in your LDmicro program to map to the virtual board:
| Name | Type | Description |
|---|---|---|
FOTO / XFOTO |
Sensor | Light sensor |
SEN / XSEN |
Sensor | Proximity sensor |
MOV / XMOV |
Sensor | Movement sensor |
TRIG / XTRIG |
Sensor | Trigger/door sensor |
PO1 / XPO1 |
Sensor | Metal detector 1 |
PO2 / XPO2 |
Sensor | Metal detector 2 |
S1 / XS1 |
Switch | Toggle switch 1 |
S2 / XS2 |
Switch | Toggle switch 2 |
S3 / XS3 |
Switch | Toggle switch 3 |
BTN1 / XBTN1 |
Button | Push button 1 (green) |
BTN2 / XBTN2 |
Button | Push button 2 (yellow) |
BTN3 / XBTN3 |
Button | Push button 3 (red) |
| Name | Type | Description |
|---|---|---|
FAN1 / YFAN1 |
Fan | Fan 1 |
FAN2 / YFAN2 |
Fan | Fan 2 |
FAN3 / YFAN3 |
Fan | Fan 3 |
H1 / YH1 |
Light | Green indicator |
H2 / YH2 |
Light | Yellow indicator |
H3 / YH3 |
Light | Red indicator |
PANIC / YPANIC |
Strobe | Panic strobe light |
BELL / YBELL |
Buzzer | Emergency bell |
LOCK / YLOCK |
Lock | Door lock / solenoid (digital output) |
K1 / YK1 |
Contactor | Power contactor 1 |
K2 / YK2 |
Contactor | Power contactor 2 |
K3 / YK3 |
Contactor | Power contactor 3 |
Note: LDmicro uses
Xprefix for inputs andYprefix for outputs. The simulator automatically handles both conventions.
LDmicroWebSim/
βββ server.py # FastAPI backend server
βββ interpreter/
β βββ __init__.py
β βββ ladder_parser.py # Ladder text parser
β βββ unified_transpiler.py # Ladder text to JS transpiler
βββ static/
β βββ index.html # Main UI
β βββ styles.css # Industrial theme CSS
β βββ simulator.js # Browser simulation engine
βββ examples/
β βββ simple_ladder.txt # Example ladder text export
βββ Dockerfile
βββ docker-compose.yml
βββ requirements.txt
The included Docker setup provides:
- Python 3.11 slim image
- Automatic dependency installation
- Hot-reload for development
- Port 8000 exposed
# docker-compose.yml
services:
ldmicro-sim:
build: .
ports:
- "8000:8000"
volumes:
- .:/app # For development hot-reload# Run in development mode with auto-reload
uvicorn server:app --reload --host 0.0.0.0 --port 8000LDmicro export text
for 'Microchip PIC16F877 40-PDIP', 8.000000 MHz crystal, 0.5 ms cycle time
LADDER DIAGRAM:
|| ||
|| XS1 XS2 YH1 ||
1 ||-------] [--------------]/[--------------( )-------||
|| ||
|| XS2 XS3 YH2 ||
2 ||-------] [--------------]/[--------------( )-------||
|| ||
|| XS3 XS1 YH3 ||
3 ||-------] [--------------]/[--------------( )-------||
|| ||
||------[END]----------------------------------------||
I/O ASSIGNMENT:
Name | Type | Pin
---------+----------------+------
XS1 | Digital input | 2
XS2 | Digital input | 3
XS3 | Digital input | 4
YH1 | Digital output | 21
YH2 | Digital output | 22
YH3 | Digital output | 23
This creates a "rotating light" pattern:
- S1 ON + S2 OFF β H1 (green) ON
- S2 ON + S3 OFF β H2 (yellow) ON
- S3 ON + S1 OFF β H3 (red) ON
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- LDmicro - The original ladder logic compiler
- Inspired by physical PLC training boards used in education
Made with β€οΈ for PLC education and simulation