How to Turn an Arduino Into a PLC Using OpenPLC

by taste_the_code in Circuits > Electronics

22 Views, 0 Favorites, 0 Comments

How to Turn an Arduino Into a PLC Using OpenPLC

Turn Your Arduino into an Industrial PLC with OpenPLC

Arduinos are great for hobby projects, but if you have ever looked at industrial control panels you will have noticed they run PLCs (Programmable Logic Controllers), not Arduinos. The reason comes down to a fundamental difference in how they execute code. In this Instructable I will show you how PLCs work, how their execution model compares to a standard Arduino sketch, and how to use the free OpenPLC editor to turn an ordinary Arduino Uno into a real PLC running ladder logic. You will need a few basic components and a Windows, Mac, or Linux PC to follow along.

Supplies

MVI_3041.MP4.00_00_13_14.Still001.jpg

For the hardware you will need an Arduino Uno (or an ESP32 — OpenPLC supports both), two momentary push buttons, one standard LED, two 1k ohm resistors for the button pull-downs, one current-limiting resistor for the LED (around 220 to 330 ohms), a breadboard, jumper wires, and a USB cable to connect the Arduino to your computer.

On the software side, download the OpenPLC Editor for free from the OpenPLC project website. It runs on Windows, macOS, and Linux and requires no purchase or licence. No additional libraries need to be installed manually — the editor handles that when it compiles your program.


OpenPLC Editor (free download): https://autonomylogic.com/download

Arduino Uno: https://s.click.aliexpress.com/e/_c2uCtE2z

ESP32 Developement Board: https://s.click.aliexpress.com/e/_c3qFwwvb

Push buttons: https://s.click.aliexpress.com/e/_c3u4XXsd

Breadboard Starter Kit: https://s.click.aliexpress.com/e/_c3YcR457

Mini Breadboards: https://s.click.aliexpress.com/e/_c40EONED

Soldering Station: https://s.click.aliexpress.com/e/_c3wKGx7b

Bench Power Supply: https://s.click.aliexpress.com/e/_c4N33Vf7

Soldering Microscope: https://s.click.aliexpress.com/e/_c41T3ic1

How a PLC Scan Cycle Works (and Why It Beats an Arduino Loop)

2026-05-18 15-51-46.mp4.00_01_36_17.Still001.jpg

A standard Arduino sketch has a setup function that runs once and a loop function that runs continuously. That loop is simple and flexible, but it has a critical weakness: any delay, blocking call, or infinite condition will stop everything else from running. In a machine where a sensor press must always be detected immediately, that is not acceptable.

PLCs solve this with a concept called the scan cycle. Every cycle has four stages that happen in strict order: all digital inputs are read at once, all program logic is executed, all outputs are written at once, and then any communications or diagnostics are handled. The cycle then repeats, typically every 10 to 50 milliseconds. Nothing inside the logic stage can block the next cycle, because input reading and output writing happen as separate, atomic phases. That guarantee is what makes PLCs the standard choice for industrial control.

Ladder Logic Basics: Contacts, Coils, and Latches

2026-05-18 15-55-27.mp4.00_00_06_25.Still001.jpg

Ladder logic is the programming language of PLCs. It looks like old electrical relay diagrams and is designed to be readable by electricians and control engineers without software training. Every program is made up of rungs, and each rung controls one outcome based on one or more input conditions.

The three building blocks used in this project are contacts, coils, and function blocks. A contact is a binary input, it is either true or false. In this project the contacts are two physical push buttons. A coil is an output that you energize, just like an LED you want to switch on. The function block used here is the SR bistable latch: when its Set input (S1) receives a true signal, its output (Q1) turns on and stays on. The output only turns off when a true signal arrives at the Reset input (R). Understanding that all contacts are evaluated simultaneously, not one after another like Arduino code, is the key mental shift this project will make concrete.

Install OpenPLC Editor and Create a New Project

2026-05-18 15-47-51.mp4.00_00_00_19.Still001.jpg
2026-05-18 15-47-51.mp4.00_00_26_14.Still002.jpg

Download and install the OpenPLC Editor from the OpenPLC project website. Once it is installed, open it. You will see an option to create a new project or open an existing one.

Create a new project and give it a name. Once the project is open you are looking at the main canvas where you will build your ladder logic diagram. The left panel contains the component library, which includes contacts, coils, and all the function blocks you can drop onto the canvas.

Build the Ladder Logic Program

2026-05-18 15-57-39.mp4.00_01_07_13.Still001.jpg

On the canvas, add a contact and label it with the variable name for button one. Add a second contact for button two. Then, from the function block library, find the SR bistable block and place it on the canvas. Connect the first contact to the S1 pin of the SR block and the second contact to the R pin. Connect the Q1 output of the SR block to a coil, and label that coil with the variable name for the LED output.

This rung says: if button one is pressed, latch the LED on. If button two is pressed, reset the latch and turn the LED off. The state persists between presses because the SR block holds its last output.

Test in the Built-in Simulator

2026-05-18 15-57-39.mp4.00_03_20_00.Still002.jpg

Before touching any hardware, verify your logic in the simulator. In the board selection dropdown, choose Simulator instead of a physical board. Save the project and click Run.

Once the simulator is running, click on the button one contact and force it to true. The connection line should turn green and the coil should energize. Release the force and the coil stays on because the latch is holding. Now force button two to true and the coil de-energizes. Release button two and the coil stays off. If that is the behavior you see, the logic is correct and you are ready to move to hardware.

Define Variables and Map Pins Using IEC 61131-3 Addressing

2026-05-18 16-08-14.mp4.00_00_09_14.Still001.jpg

OpenPLC uses the IEC 61131-3 addressing standard to map logical variable names to physical pins. Each address has three parts: a location prefix (I for input, Q for output, M for memory), a data size indicator (X means a single bit), and a two-part memory address in the format byte.bit.

Open the variable declaration table in your project. Create a variable for button one, set its address to %IX0.0, and assign it to Arduino pin 2. Create a variable for button two at %IX0.1, mapped to pin 3. Create a variable for the LED output at %QX0.0, mapped to pin 4.

Those addresses tell OpenPLC exactly which physical pins to read from and write to when the scan cycle runs.

Wire the Circuit

video.00_00_25_07.Still002.jpg

Wire the breadboard as follows. Connect the first push button between 5V and Arduino pin 2, with a 1k resistor from pin 2 to ground. This holds the pin LOW when the button is not pressed and pulls it HIGH when it is. Repeat the same wiring for the second push button using pin 3. Connect the LED's anode through a current-limiting resistor to Arduino pin 4, with the cathode going to ground.

Both button inputs are pulled LOW by default so there is no floating voltage on the Arduino pins. When you press a button, 5V drives the pin HIGH and the PLC contact reads true.

Compile and Upload to the Arduino

In OpenPLC Editor, switch the board selector from Simulator to Arduino Uno. Select the correct serial port for your connected Arduino. Click Compile and Upload.

The editor will download the required libraries and compile the ladder logic into Arduino firmware. This takes a few minutes the first time. When it is finished, the Arduino reboots and is immediately running the PLC program.

The scan cycle runs every 20 milliseconds by default. Every 20ms the Arduino reads both button inputs, executes the SR latch logic, and sets the LED output — exactly as an industrial PLC would.

Test the Hardware

MVI_3049.MP4.00_01_14_02.Still002.jpg

Press button one. The LED lights up immediately and stays on when you release the button since the SR latch is holding its state just as it did in the simulator. Press button two and the LED goes off. It stays off until you press button one again. The behaviour is deterministic, non-blocking, and consistent every scan cycle regardless of anything else happening in the system.

Conclusion

What you have built is a small but genuine PLC. The Arduino is not running a sketch, it is running ladder logic that was compiled into PLC firmware, operating on a real scan cycle. That is the same fundamental architecture used in industrial controllers costing thousands of dollars, running on hardware that costs a few dollars. From here you can explore timers, counters, more complex ladder rungs, and OpenPLC's support for other boards including the ESP32.

If you want to see more projects like this, follow along on the Taste The Code YouTube channel as there is plenty more to build.