Walkthrough: Problem 10: Photoelectric Sensor

Difficulty

Target behavior

Run the belt conveyor, count the workpieces that pass the photoelectric sensor, and show the count with lamps (stop at 3)

What you will learn

  • Increment (INC) instruction and data memory (DM)
  • Compare instruction (=)
  • Falling edge pulse (LDF)

Problem

This model uses a belt conveyor and a photoelectric sensor.

First, let's explain belt conveyors and photoelectric sensors.


Driving the belt conveyor

A belt conveyor is a system that carries workpieces on a belt by rotating a motor.

In this simulation, a magnetic contactor is used to control the conveyor motor.

A magnetic contactor is a device that lets the PLC output unit switch the AC200V power for driving the motor ON and OFF.

Try wiring it yourself using the figure as a reference!



Photoelectric sensors

A photoelectric sensor uses light to detect whether a workpiece is present.

It consists of two parts, an emitter and a receiver, and there are two types: light-on and dark-on.

With light-on, the PLC input turns ON when light from the emitter reaches the receiver. With dark-on, the PLC input turns ON when light from the emitter does not reach the receiver.

In this model we want to catch the moment a workpiece passes between the emitter and receiver and blocks the light, so dark-on is used.



The motion to reproduce is driving the belt conveyor, counting the workpieces that pass through the photoelectric sensor, and lighting lamps according to the count.

To reproduce this, you need the INC and = (equal) instructions that handle numbers! Take on numeric operations!

Target behavior (video)

Approach

Count the number of times the photoelectric sensor detects a workpiece in DM0, and light lamps according to that value. Stop the conveyor after the third workpiece has completely fallen off.

Based on this approach, try writing the ladder yourself first.
In the simulator, you can create the wiring and ladder and actually run the 3D equipment model.

Try it in the simulator
Show the sample ladder and explanation(click to open)

Devices used

DeviceComment
Inputs
X0Conveyor start button
X1Photoelectric sensor
Outputs
Y0Conveyor (contactor)
Y1Workpiece 1 lamp
Y2Workpiece 2 lamp
Y3Workpiece 3 lamp
Internal relays
MR03rd workpiece passed
MR1Complete
Timers
T0Waiting to stop
Data memory
DM0Number of workpieces passed

Ladder explanation

The row numbers in the figures match the row numbers in the simulator's ladder window.

1Starting the conveyorRows 001–002

On the rising edge of X0 (start button), SET Y0 (conveyor). While MR1 (complete) is ON, it does not restart.

2Counting workpiecesRows 003–004

On the rising edge of X1 (photoelectric sensor), add 1 to DM0.

INC adds 1 every scan while its input is ON. With LD X1 it would keep counting the whole time a workpiece blocks the sensor, so always make it a pulse with LDP.

3Count lampsRows 005–008

The compare instruction = is a contact that closes only while the value of DM0 equals the specified value. Y1 lights for the 1st workpiece, Y2 for the 2nd, and Y3 for the 3rd (only while the conveyor is running).

4Stop after the 3rd workpiece passesRows 009–014

  • Row 010: on LDF X1 (the falling edge of the sensor = the moment a workpiece leaves the sensor), if DM0 is 3, SET MR0
  • Row 011: while MR0 is ON, wait 1.5 seconds with T0 (time to carry it to the end of the conveyor)
  • Rows 012–014: when T0 turns ON, stop the conveyor (Y0 RES), SET complete MR1, and RES MR0

The sample wiring and ladder data can be downloaded fromGitHuband loaded with "Load wiring" and "Load ladder" in the simulator.

Key points

  • LDP closes for one scan at the moment a signal turns ON, and LDF at the moment it turns OFF. They let you catch "a workpiece has arrived" and "a workpiece has left" respectively.
  • Word devices (DM) hold numbers. Use them separately from ON/OFF devices such as X, Y, and MR.