PLC Tutorial 2: OpenPLC Editor First Program, One Contact One Coil

Share:
PLC Tutorials
PLC Tutorial 2: OpenPLC Editor First Program, One Contact and One Coil From New Project to a Running Lamp

Your first ladder program in OpenPLC is one rung: a switch contact that drives a lamp coil. We build it in the editor, generate the file, run it on the runtime and watch the lamp turn ON in Monitoring.

One Rung NO Contact & Coil Generate .st Monitoring Real Screenshots

Build a one rung ladder program in OpenPLC Editor, turn it into a .st file and run it on the OpenPLC runtime. Every screenshot comes from the project we built and tested for this lesson.

Hello everyone, today we are going to build an OpenPLC Editor first program: one switch contact, one lamp coil, tested live on the runtime.
openplc editor first program
Quick Answer

How do you make an OpenPLC Editor first program?

OpenPLC Editor first program is a single ladder rung where a normally open contact SWITCH at %IX0.0 drives a coil LAMP at %QX0.0. You create a project, declare both variables, draw the rung, generate a .st file and upload it to the runtime. In our test, switching %IX0.0 to TRUE turned LAMP TRUE in Monitoring within half a second.

  1. File, New: pick an empty folder, POU type program, language LD.
  2. Add SWITCH (BOOL, %IX0.0) and LAMP (BOOL, %QX0.0).
  3. Draw a contact for SWITCH and a coil for LAMP between the rails.
  4. Click Generate program for OpenPLC Runtime and save the .st file.
  5. Upload it on port 8080, start the PLC and open Monitoring.

What Is an OpenPLC Editor First Program?

An OpenPLC Editor first program is the smallest useful ladder program: one normally open contact that switches one output coil. It takes you through the full workflow, from an empty project to a running PLC, with no logic to get in the way.

Key Facts
  • One rung: SWITCH at %IX0.0 drives LAMP at %QX0.0.
  • The editor saves a .st file that the runtime compiles.
  • Task interval T#20ms, so the rung runs 50 times a second.
  • Monitoring refreshes every 500 ms by default.

PLC Tutorials series: this is lesson 2. In Lesson 1 we installed the OpenPLC runtime on Linux, and this lesson uses that same runtime on port 8080.

If ladder symbols are new to you, read ladder logic for beginners first. A quick look at what a PLC is also helps you picture where inputs and outputs come from.

Advertisement

What Do You Need Before You Start?

You need OpenPLC Editor on your PC and a running OpenPLC runtime that you can open in a browser. The editor is free for Windows, Linux and macOS, and it builds every lesson in this series.

ItemWhat we usedWhy
EditorOpenPLC Editor on LinuxDraw and generate
RuntimeOpenPLC runtime, port 8080Compile and run
Loginopenplc / openplcDefault account
InputPython script as a switchNo input card
BrowserAny modern browserUpload and Monitoring
Do You Know?

OpenPLC Editor is built on an open source IEC 61131 3 editor, so it also offers FBD, ST, IL and SFC. We use ladder (LD) here because most plant technicians read it first.

How to Create a New Project in OpenPLC Editor

Create the project with File, New, choose an empty folder, and the editor asks for the first POU. Name it FirstProgram, keep POU type as program and set the language to LD.

1
New project
File, New, then select or create an empty folder.
2
First POU
Name FirstProgram, type program, language LD.
3
Add SWITCH
Green plus button: Name SWITCH, Class Local, Type BOOL, Location %IX0.0.
4
Add LAMP
Second row: Name LAMP, Class Local, Type BOOL, Location %QX0.0.
5
Save
Ctrl+S saves plc.xml and beremiz.xml in the folder.

The project tree of the OpenPLC Editor first program then holds FirstProgram and a resource called Res0. Res0 holds the task that calls your program every T#20ms.

OpenPLC Editor variable table with SWITCH and LAMP above one ladder rung
Screenshot by Instrumentation Blog from OpenPLC Editor with the FirstProgram variable table for SWITCH and LAMP above the finished one rung ladder and its comment.

The Location column decides whether a variable is real I/O. %IX0.0 is input byte 0 bit 0 and %QX0.0 is output byte 0 bit 0, the same scheme explained in PLC memory addressing.

Quick Tip

Leave Location empty for internal bits. Only located variables, the ones with a %I or %Q address, appear on the runtime Monitoring page.

How Does the One Rung Program Work?

The rung works like a wire through a switch: when SWITCH is TRUE the contact closes, power flows from the left rail to the coil, and LAMP becomes TRUE. When SWITCH is FALSE the contact opens and the coil drops in the same scan.

openplc editor first program ladder diagram with switch contact and lamp coil
Diagram by Instrumentation Blog showing the OpenPLC first program: a switch at %IX0.0 closes the SWITCH contact, power flows through the rung and the LAMP coil drives %QX0.0.

To draw it, place a contact from the ladder toolbar, double click it and pick SWITCH with the Normal modifier. Then place a coil, pick LAMP, and drag wires from the left rail to the contact, the contact to the coil, and the coil to the right rail.

SWITCH %IX0.0ContactLAMP %QX0.0
FALSEOpenFALSE
TRUEClosedTRUE

A comment box above the rung, such as Rung 1: SWITCH ON turns LAMP ON, costs nothing and helps the next person who opens your OpenPLC Editor first program.

Do You Know?

The coil in this rung is not a physical relay coil. It writes a bit in the output image, and the runtime copies that bit to the output at the end of the scan.

Advertisement

Why the Scan Cycle Matters Even for One Rung

The scan cycle matters because the lamp never follows the switch instantly: the runtime reads inputs, solves the rung, then writes outputs, once every task interval. A change that lands just after an input read waits for the next scan.

Read%IX0.0 into SWITCH
SolveLAMP := SWITCH
WriteLAMP to %QX0.0
WaitRest of 20 ms

With T#20ms the program runs 50 times a second, which is fast enough for any push button. The full read, solve and write cycle is covered in how the PLC scan cycle works.

The calculator adds the input filter, one task interval and the output delay to give the worst case delay from switch to lamp. Our defaults assume a 3 ms input filter and a 10 ms relay output, typical figures for a DC input card and a relay output module.

Switch to Lamp Delay Calculator
Result
Worst case switch to lamp delay is 33 ms and best case is 13 ms. The task runs 50 times a second.
Worst case = filter + interval + output
= 3 + 20 + 10 = 33 ms
Best case = 3 + 10 = 13 ms
Scans per second = 1000 ÷ 20 = 50
switch to lamp response time infographic with 33 ms worst case and 13 ms best case
Diagram by Instrumentation Blog showing the switch to lamp delay for a 20 ms task: 3 ms filter, up to 20 ms waiting for the scan and 10 ms output, 33 ms worst case.

With a transistor output the last term almost disappears. Compare both in PLC output module types.

How to Generate the Program and Upload It to the Runtime

Click the orange down arrow, Generate program for OpenPLC Runtime, and the editor compiles the ladder to IEC Structured Text and asks where to save the .st file. The console must end with OpenPLC program generated successfully before you upload anything.

OpenPLC Editor console after generating the first program successfully
Screenshot by Instrumentation Blog from OpenPLC Editor after Generate program, with the rung above and the console ending in OpenPLC program generated successfully.

Open the saved first_program.st in a text editor and the whole rung is one line: LAMP := SWITCH;. The file also holds the variable list and the CONFIGURATION block with task0 at T#20ms, all written in Structured Text.

1
Log in
Open http://localhost:8080 and log in to the runtime.
2
Programs
Click Programs, then Upload Program.
3
Choose file
Select first_program.st and click Upload Program.
4
Describe
Name it First Program, add a short description, click Upload program.
5
Compile
Wait for Compilation finished successfully, then Go to Dashboard.
OpenPLC runtime compile log for the first ladder program
Screenshot by Instrumentation Blog from OpenPLC runtime compiling the first program, with __IX0_0 and __QX0_0 found and Compilation finished successfully at the end.

In the glueVars lines, __IX0_0 and __QX0_0 are your two located variables. If one is missing, its Location field in the editor is empty or wrong.

Quick Tip

Upload a new .st file whenever you change the rung. The runtime always runs the last program you compiled, not the project open in the editor.

Advertisement

How to Test the Program in OpenPLC Monitoring

Press Start PLC on the Dashboard, open Monitoring and change %IX0.0: LAMP must copy SWITCH within one refresh. Monitoring can write %QX outputs but not %IX inputs, so the input needs a source.

Our PC had no input card, so we used the runtime Python submodule as the hardware layer, and a small script set %IX0.0 TRUE or FALSE like a real selector switch. With SWITCH FALSE both rows read FALSE, and after we switched it ON both turned TRUE.

OpenPLC monitoring page with switch input true and lamp output true
Screenshot by Instrumentation Blog from OpenPLC Monitoring with First Program running, SWITCH at %IX0.0 TRUE and LAMP at %QX0.0 TRUE.

That screen proves your OpenPLC Editor first program runs. The top bar reads Running: First Program, and the green markers follow the switch.

Do You Know?

The Write buttons on the LAMP row can force the output, but the rung overwrites it in the next scan. For this program LAMP always follows SWITCH.

Siemens and Allen Bradley Equivalents

The rung of your OpenPLC Editor first program exists on every PLC: a normally open contact on an input and an output coil. Only the symbol names and address format change.

Siemens TIA Portal LAD

Normally open contact on I0.0 and an assignment coil on Q0.0 in OB1.

Best for: S7 1200 and S7 1500
I0.0 to Q0.0
Studio 5000

XIC on the input tag and OTE on the output tag in the MainRoutine.

Best for: ControlLogix, CompactLogix
XIC, OTE
RSLogix 500

XIC on I:0/0 and OTE on O:0/0.

Best for: MicroLogix and SLC 500
XIC, OTE

Before you port the rung, check the hardware families in S7 1200 vs S7 1500 and types of Allen Bradley PLCs. All of them follow the IEC 61131 3 programming languages ideas you meet here.

What this first program teaches
  • The full edit, generate, upload and run loop
  • How located variables map to real I/O
  • How to prove a rung with live Monitoring
What it does not cover yet
  • Holding an output after the button is released
  • Normally closed contacts and stop logic
  • Timers, counters and analog values

Common Mistakes and Troubleshooting

Most faults in an OpenPLC Editor first program come from an empty Location field, a rung not wired to both rails, or an older program still running. Check each step of the flowchart before you change the logic.

flowchart of openplc editor first program from new project to monitoring
Diagram by Instrumentation Blog showing the first program workflow: new project, variables, rung and generate in the editor, then upload, compile, start and Monitoring in the runtime, with a loop back on errors.
SymptomLikely causeFix
Generate failsWire not connected to a railRedraw the wire to the pin
Variable not in MonitoringNo Location addressSet %IX0.0 or %QX0.0
LAMP never turns TRUEInput never reaches %IX0.0Check the hardware layer or wiring
Old behaviour after editOld .st still runningGenerate and upload again
Monitoring asks for ModbusModbus server offEnable it in Settings
Myth: Saving the project updates the running PLC.
Fact: Only an uploaded and compiled .st file changes what the runtime runs.
Myth: A contact address can be any free number.
Fact: It must match a real input, like %IX0.0 for byte 0 bit 0.
Myth: Forcing LAMP from Monitoring proves the rung.
Fact: The rung overwrites the forced value in the next scan.
  • Both variables have a Location address.
  • Rung wired from the left rail to the right rail.
  • Console ends with program generated successfully.
  • Runtime log ends with Compilation finished successfully!
  • Monitoring: LAMP follows SWITCH.

If the input never changes on real hardware, check the field wiring with sinking and sourcing in PLC and work through PLC troubleshooting steps.

PDF
Logix 5000 Controllers General Instructions (PDF)
Reference for XIC, XIO and OTE, the contact and coil of this first rung

The video below builds a beginner ladder example in OpenPLC; compare it with your rung.

For more editors and simulators see free PLC programming software, and for more rungs to practise try PLC ladder logic examples. When you are ready, test yourself with the PLC objective quiz.

OpenPLC Editor First Program FAQ

How do I create my OpenPLC Editor first program step by step?

Create a new project in an empty folder, add a program POU in LD, declare SWITCH at %IX0.0 and LAMP at %QX0.0, and draw one contact to one coil.

Then generate the .st file, upload it on port 8080 and start the PLC.

Why does my variable not appear on the OpenPLC Monitoring page?

The Monitoring page holds only located variables, the ones with a %I, %Q or %M address in the Location column. An internal bit with an empty Location stays hidden there.

Give it a spare address while testing, then generate and upload the program again.

What is the difference between saving and generating in OpenPLC Editor?

A save writes the project files, plc.xml and beremiz.xml, so you can edit the rung later. Generating compiles the ladder into a .st file that the runtime can upload and run.

The runtime never reads plc.xml, only the generated .st file that you upload.

How fast does a PLC output follow an input with a 20 ms task?

Worst case is about filter plus one interval plus output delay, so 3 + 20 + 10 = 33 ms with a relay output. Best case is about 13 ms.

Monitoring refreshes every 500 ms, so the screen lags behind the real output.

Can I test an OpenPLC program without any input or output hardware?

Yes, the runtime runs with no I/O card, and Monitoring can force %QX outputs directly. For %IX inputs we used the Python submodule as the hardware layer, with a script acting as the switch.

The program logic behaves the same as on real hardware.

Which language should I choose for a first OpenPLC program?

Choose ladder (LD) if you work with relay panels or read electrical drawings, because contacts and coils match those symbols. The editor turns it into Structured Text anyway when you generate.

Later lessons in this series cover ST and FBD for maths and function blocks.

Advertisement

Related Articles

External References

What We Learn Today

  • An OpenPLC Editor first program is one rung where a normally open SWITCH contact at %IX0.0 drives a LAMP coil at %QX0.0.
  • The editor generates a .st file, the runtime compiles it on upload, and Monitoring proves the program by showing LAMP follow SWITCH live.
  • Response time depends on the scan: with a 20 ms task, a 3 ms filter and a relay output, the worst case delay is about 33 ms.
Advertisement
I hope you like above blog. There is no cost associated in sharing the article in your social media. Thanks for reading!! Happy Learning!!
Sunayana Gadepatil, author at Instrumentation Blog
Author · instrumentationblog.in
Ms. Sunayana Gadepatil is an instrumentation professional, technical writer, and the author behind Instrumentation Blog. With a strong interest in industrial instrumentation, process measurement, and automation, she specializes in simplifying complex technical concepts into clear, practical, and easy to understand insights. Through her articles, Ms. Sunayana shares valuable knowledge on flow, pressure, level, temperature, control systems, and industrial automation for engineers, students, technicians, and industry professionals.
Technically reviewed on

Leave a Reply

Your email address will not be published. Required fields are marked *

Support free learning

Help keep every guide, calculator and tool 100% free

Hosting, software and hours of research go into every article. Even a small contribution helps us publish more in-depth guides for students, technicians and engineers.

  • No paywalls
  • No sign up
  • Free for everyone