IMDHMIControls LibraryShop main store

How-to

How to program a PLC container filling sequence

PLC programming Published 8 min read By IMDHMI controls team

Short answer

The Start push button at I:1/0 seals in a RUN bit through an on-state contact of the normally closed Stop input at I:1/1. A FILLING bit latches when the proximity input I:1/3 sees the container and drops when the level input I:1/4 sees full; a LEAVING bit keeps the restarted conveyor from re-triggering the fill while the full container is still at the sensor. Motor, valve and three LEDs follow those bits.

On this page
  1. I/O map and where the addresses sit
  2. Latch the run command and match the Stop polarity
  3. Sequence the fill with three state bits
  4. Sizing the I/O for four inputs and five outputs
  5. Verify the sequence online
  6. Decisions for your station
  7. Questions asked

Conveyor brings a container to a proximity sensor, the motor stops, a valve fills it to a level sensor, the valve closes, and the conveyor carries it away. Program that as six rungs on an SLC 500 rack, driven by three internal state bits — RUN, FILLING and LEAVING — with the Start push button sealed in at I:1/0. Two details decide whether the station runs at all: the Stop instruction at I:1/1 must test the on state because the button is wired normally closed, and the LEAVING bit must block the fill from re-triggering while the full container is still under the sensor after the motor restarts. What follows is the I/O map, the rungs in scan order, and the online checks that prove each transition.

I/O map and where the addresses sit #

The station needs four input points and five output points, so one 8-point input module and one 8-point output module carry it. The CPU sits in slot 0 and the output module in slot 2; every input address in the program is written to slot 1, so the input module must occupy slot 1 — confirm that on the rack before you download.

Signal Address Wired as Job in the sequence
Start push button I:1/0 normally open, momentary latches RUN
Stop push button I:1/1 normally closed drops RUN
Proximity sensor I:1/3 container at the fill position starts the fill
Level sensor I:1/4 maximum level reached ends the fill
Conveyor motor O:2/0 contactor coil moves containers
Solenoid valve O:2/1 valve coil fills the container
RUN LED O:2/2 indicator conveyor running
FILL LED O:2/3 indicator fill in progress
FULL LED O:2/4 indicator full container leaving

In these addresses the image file comes first — file 1 is the input image, file 0 the output image — the digit after the colon is the module's rack slot, and the digit after the slash is the point on that module. I:1/3 is point 3 of the input module and O:2/4 is point 4 of the output module, counted from zero.

Latch the run command and match the Stop polarity #

Rung 1 is the master latch: an examine-if-closed contact of I:1/0 in a parallel branch with an examine-if-closed contact of RUN itself, in series with an examine-if-closed contact of I:1/1, driving the RUN coil. The parallel branch is the seal-in that lets the momentary Start button be released; it is the same pattern as a sealed motor starter rung in STEP 7 ladder, applied to an internal bit instead of a motor coil.

The Stop contact is where this program fails when it fails. The button is normally closed, so while it is released the input circuit is energized and I:1/1 reads on. The on-state test passes power while the button is released, breaks the rung when it is pressed, and also breaks it if the button's wire is cut — exactly the failure behavior a stop function needs. An off-state test is the wrong polarity here: it would hold the rung open the whole time and let RUN latch only while someone held Stop pressed. For the contact-level view of the two tests, see what each ladder logic symbol does in a rung.

One boundary: this Stop is a process stop. An emergency stop belongs in the hardwired circuit that removes power from the motor and valve, not in a program rung.

Sequence the fill with three state bits #

Pick three free bits in the controller's binary file, label them RUN, FILLING and LEAVING in the rung comments, then enter rungs 2 to 6 in this scan order:

  1. Rung 2, LEAVING latch. An examine-if-closed contact of FILLING in series with an examine-if-closed contact of I:1/4, in a parallel branch with an examine-if-closed contact of LEAVING; then in series with examine-if-closed contacts of I:1/3 and RUN; coil LEAVING. It sets on the scan the level input rises, holds while the full container is still at the sensor, and drops when the sensor clears.
  2. Rung 3, FILLING latch. An examine-if-closed contact of I:1/3 in series with an examine-if-open contact of LEAVING, in a parallel branch with an examine-if-closed contact of FILLING; then in series with an examine-if-open contact of I:1/4 and an examine-if-closed contact of RUN; coil FILLING. The latch sets when a container arrives and drops the moment the level input rises or RUN falls.
  3. Rung 4, conveyor motor. Examine-if-closed RUN in series with examine-if-open FILLING; coil O:2/0. The motor runs whenever the process is active and not filling, so it restarts by itself on the scan the fill ends.
  4. Rung 5, fill valve. Examine-if-closed FILLING; coil O:2/1. The valve is energized exactly while FILLING is latched, and FILLING already contains RUN.
  5. Rung 6, indicators. O:2/2 from the same two contacts as the motor, O:2/3 from FILLING, O:2/4 from LEAVING. Give each indicator its own rung unless you already know how the SLC 500 handles multiple outputs on one ladder rung.

The scan order matters once: the LEAVING rung must sit above the FILLING rung. In the scan where I:1/4 rises, the LEAVING rung still sees FILLING on and sets first; the FILLING rung below then drops its latch. Reversed, LEAVING never sets, and with the container still at the sensor the FILLING latch re-sets on the very next scan and reopens the valve on a full container. That is the same lesson as why a pick-and-place rung needs sequence state rather than one condition: one true input must not be able to re-fire a step the sequence has already left.

Two more behaviors fall out of the structure. Stopping mid-fill leaves a defined state: Stop drops RUN, FILLING falls with it, the valve closes and every LED goes dark; pressing Start again re-latches RUN, and since the container is still at the sensor with the level input off, the fill resumes on that same container. And the design assumes a gap between containers: the proximity input must drop off between fills so LEAVING can reset. Containers running back to back never clear the sensor, LEAVING stays latched, and every container after the first passes the valve unfilled.

Sizing the I/O for four inputs and five outputs #

The inputs, with where each comes from:

  • 4 discrete input points — the station's signal list: Start, Stop, proximity, level.
  • 5 discrete output points — the same list: motor, valve, three LEDs.
  • 8 points per module, one input module and one output module — the rack layout, with the CPU in slot 0 and the output module in slot 2.
  • Input module in slot 1 — fixed by the addresses themselves: every input address in the program begins with I:1/, and the digit after the colon is the slot.

The rule: every address the program uses must land on a point its module actually has, so in each file the points used must not exceed the module's point count, and no bit number may exceed the module's last point.

The arithmetic:

  • Input side: 4 points used of 8, so 8 − 4 = 4 points spare; the highest bit used is 4, below the module's last point at bit 7.
  • Output side: 5 points used of 8, so 8 − 5 = 3 points spare; the highest bit used is 4, also below bit 7.

The result: one input module and one output module carry the whole station, with room left for a stop-request selector or a second sensor on the input side.

The decision: the layout is right as drawn, and it holds until the station needs a ninth point in either file — that is the threshold at which a module goes into the next free slot and only the new signals take the new addresses, because the existing ones never move. Before download, verify in the rack that slot 1 holds the input module and slot 2 the output module: outputs addressed to a slot with no module in it cannot energize, whatever the rungs do.

Verify the sequence online #

  1. With the controller in run and the ladder open for monitoring, watch I:1/1 while you work the Stop button: released must read on, pressed must read off. Anything else is a wiring or contact-type fault, and no rung edit will compensate for it.
  2. Press and release Start: RUN latches, and O:2/0 with O:2/2 turn on and stay on after the button is released.
  3. Bring a container to the fill position: I:1/3 turning on stops O:2/0 and turns on O:2/1 and O:2/3 in the same scan.
  4. Let the level rise, or simulate the level input on the bench: O:2/1 and O:2/3 drop, O:2/4 lights, and O:2/0 restarts while the container is still at the sensor.
  5. Pull the container clear: I:1/3 drops, O:2/4 goes out, and the station is ready for the next container.
  6. Press Stop during a fill: the valve closes at once. If you then pull the container away before pressing Start, the station runs empty until the next container arrives; if you leave the container in place, Start resumes the fill.

If you force inputs or outputs for a bench test, isolate the valve's supply and the conveyor drive first; forcing proves logic, it does not run a station.

Decisions for your station #

  • Stop button normally closed, as wired here: keep the on-state contact of I:1/1 — it drops RUN on a press and on a cut wire alike.
  • Stop button normally open in an existing panel: rewire it normally closed rather than inverting the contact — an inverted off-state test still stops on a press, but the station would keep running with a broken Stop wire.
  • Containers arriving with a gap: run this program as written.
  • Containers touching so the sensor never clears: add a second reset condition for LEAVING, such as a sensor downstream of the station, before running product.
  • More signals later: the layout holds up to each module's full point count; past that, the next free slot takes the new module and only the new points get new addresses.

Questions asked

Start is pressed but the RUN LED never lights. What do I check first?

Watch I:1/1 online with the Stop button released: it must read on, because the rung is written for an energized-when-released Stop input. If it reads off, the button circuit is open or the contact is normally open, and no program edit will make the sequence run, so fix the wiring first. If I:1/1 is healthy, check that no second rung writes the RUN bit: two coils on one internal bit overwrite each other every scan, and the latch never holds.

What happens if the level sensor sticks on after a container leaves?

A stuck-on level input blocks the FILLING latch, because that rung needs I:1/4 off before it can set: the FILL LED never lights again while the conveyor keeps cycling containers past the valve. A stuck-off level input is worse, since the valve never closes and the container overflows. Prove the level input with a real fill before production, and treat either stuck state as a sensor fault, not a program fault.

Can I stop the station after the current container instead of immediately?

Yes, with one spare input point. Wire a stop-request selector to a free point on the input module and add a contact of it in series with only the FILLING latch's start branch: the container already filling finishes and leaves, and the next container passes the valve unfilled until the selector is reset. Keep the hardwired Stop as the immediate stop; the selector never replaces it.

Why give each LED its own rung instead of one rung with several coils?

Online testing. With each indicator behind its own rung, you can force one lamp for a check during commissioning without dragging the motor or valve contacts with it, and an LED that is lit when it should be dark points at exactly one rung. One rung with several coils saves space but couples their troubleshooting, so combine them only after confirming how the controller scans multiple coils per rung.

Keep reading

  • How-to

    Program a CODESYS assembly line sequence in ladder logic

    Structure the line as one INT state variable with permissive-qualified station starts: TON timers of T#20s, T#40s and T#60s run the stations, Stop drops the run latch so everything pauses with the timers reset, and a CTU with a preset of 4 releases the vehicle on the fourth door. The Emergency Stop belongs in the safety circuit, with the PLC only monitoring it and clearing the sequence.

    PLC programming

  • Troubleshooting

    SLC 5/03 pulse sequence logic will not run

    Your sequence logic is probably fine: the ladder file holding it is never called from File 2, and green highlighting on both OTL and OTU shows the bit's state, not that both rungs execute. Call the file, one-shot I:8.78 with OSR, latch a sequence bit, and clear it only after the last pulse on O:7.4.

    PLC programming

  • How-to

    Build a siren pulse count sequence in S7-1200 ladder logic

    Use a positive-edge request to load a target of 3, 2, or 1 pulses, then run a four-state ladder sequence — idle, start, stop, count — that drives Q6.2 (START) and Q6.1 (STOP) from separate states so the two SIMOCODE Pro V commands never overlap. With a 2.0 s on-time and a 1.0 s gap, the three patterns finish in 11.0 s, 7.0 s, and 3.0 s.

    PLC programming