PLC Solution Library · Weight sorting simulator
Weigh every piece, track it on the belt, and confirm its exit
A scale weighs each piece while the belt moves. The PLC gives the piece a grade, follows it by encoder or by time, opens the valve of its piston at the right moment and checks with a sensor that the piece reached its exit. In this simulator, one M-Duino 19R+ runs the whole line.
Sort meat, fruit or parcels. Change the limits and the speed, block a valve, dirty a sensor or slow the belt, and see what the PLC does with every piece.
Choose a scenario
Tracking queue (PLC view)
Event log
Commands
In a real line, the emergency stop and the guards are a hardwired safety circuit. The PLC reads its state through a feedback contact of the safety relay.
Grades and exits
Set the weight limits in grams. A piece outside the limits goes to the reject bin at the end of the belt.
| Exit | Grade | Weight | Confirmed |
|---|---|---|---|
| Exit 1 | Grade: | Weight: | Confirmed: 0 |
| Exit 2 | Grade: | Weight: | Confirmed: 0 |
| Exit 3 | Grade: | Weight: | Confirmed: 0 |
| Reject bin | Grade: Out of range, no stable weight | Weight: | Confirmed: 0 |
Not confirmed: 0. The PLC counts a piece when the sensor of its exit sees it, not when the valve opens.
Tracking
Encoder: the PLC counts the pulses of a wheel on the belt, so it follows the real movement. Time: the PLC multiplies the time by the nominal belt speed, 0.5 m/s, and pauses when it stops the belt itself.
Process conditions
40 pieces/min
100 %
Faults to test
Simulation
PLC checks
| Signal | Condition | Action | Now |
|---|
Example times and limits. You set yours from your belt speed, your valves and your product.
Piece record
| Time | Piece | Weight | Grade | Exit | Result |
|---|
One line for each piece: the weight, the decision and the result at the exit. The last 30 pieces are shown. The CSV file has all the pieces and the alarms.
Alarm list
| Time | Tag | Type | Message | State |
|---|
An alarm tells the operator. A trip stops the main belt and stays latched until you acknowledge it, clear its cause and press Reset. FIRST OUT marks the first trip of an event.
What does the PLC do with each piece, from the scale to the exit sensor?
In four steps. A dynamic scale weighs the piece while the belt moves. The PLC compares the weight with the limits and gives the piece an exit, or the reject bin. It puts the piece in a tracking queue and follows its position on the belt. When the piece is in front of its piston, the PLC opens the solenoid valve and the piston pushes the piece onto the exit belt. An infrared sensor on that exit confirms that the piece arrived.
The queue is the core of the program. The pieces stay in the order they left the scale, each one with its weight, its exit and its position. Some lines put a sensor in front of each piston to give the moment of the push. With tracking, the position in the queue gives the moment, and the sensor moves to the exit, where it confirms the result.
Run the Normal sorting scenario and watch the tracking queue under the belt.
Encoder or time: how the PLC knows where the piece is
With an encoder, a measuring wheel on the belt sends pulses. The PLC counts them, so the position follows the real belt, also when it stops, slows down or starts again. Example: 500 pulses per metre give a step of 2 mm, and at 0.5 m/s that is 250 pulses per second. On the M-Duino 19R+, the encoder goes to an isolated input with interrupt, I0.5, so the program does not miss a pulse. Turn on its interrupt with switches 3 and 4 of the lower communication switches. The isolated inputs accept up to 20 kHz, so 250 pulses per second leave a wide margin. A single-channel encoder cannot see the direction: it is enough for a belt that only runs forward.
With time, the PLC multiplies the time since the scale by the nominal belt speed. It needs no encoder and no extra input, and it works when the belt runs at a constant speed and never stops with pieces on it. The error grows with the distance: if the real belt is 5% slower, the PLC position is about 5% too far, so the last exit misses first. When the belt stops, it coasts, and when it starts, it ramps up. The timer does not see these metres.
In this simulator, each piston pushes a piece that is within 9 cm of its centre. Run the Time tracking scenario, then switch the tracking to By encoder, or move the belt speed slider, and compare.
Why confirm every exit with a sensor
An output that switches on does not prove that a piece moved. The valve can stick, the air pressure can drop or the piston can push at the wrong moment. Without a sensor at the exit, the count says the piece is sorted, and nobody knows it went to the wrong place.
In this simulator, the PLC waits 1.5 s after each push for the sensor of that exit. If the sensor stays off, the PLC raises an alarm and waits for the piece at the reject bin. If the reject sensor sees the piece, the push failed: check the valve, the air and the piston. If the reject sensor does not see it either, the piece left the belt at the exit: check the exit sensor. After three misses in a row at the same exit, the PLC stops the main belt.
Run the Valve does not open scenario, then try the fault Sensor of exit 3 dirty and compare the two messages.
Weighing on a moving belt
A dynamic scale needs a moment with one piece alone on the platform, long enough for a stable reading. In this simulator the platform is 0.4 m long, the pieces are 0.15 m long and the PLC needs 0.3 s of stable signal. At 0.5 m/s, that asks for at least 0.35 m from the centre of one piece to the centre of the next one, so about 85 pieces per minute with a perfect spacing. Real pieces do not arrive with a perfect spacing. Move the infeed slider to 80 and watch the rejects with no stable weight.
A load cell gives a few millivolts, so the scale needs a weighing transmitter. In this design, the transmitter sends the weight over RS-485 with Modbus RTU, and the PLC reads it as a register. Choose a transmitter that gives the stable weight itself, with a dynamic weighing mode or a stability flag, so the result does not depend on the polling time of the PLC. Set the zero when the platform is empty, and calibrate the span with known weights.
Another way is a transmitter with a 0-10 V or 4-20 mA output on an analog input. The analog inputs of the M-Duino 19R+ have 10-bit resolution: about 1,000 steps over the full range. With 4-20 mA, add a precision shunt: 500 Ω gives 2 to 10 V. To also see a high fault (21 mA or more, NAMUR NE 43), use a lower value such as 470 Ω. This way uses one more input, so the line has no input left for the safety relay feedback.
If the weight sets the price of a pack, the scale is an automatic catchweigher under legal metrology: OIML R 51 and, in the EU, the Measuring Instruments Directive 2014/32/EU (annex MI-006).
Case studies
Real projects
Read the case studies on these applications:
- Meat sorting line: an M-Duino with relays weighs each piece on a digital scale, sorts it into three grades with pneumatic pistons, runs the climate of the room and sends the counts to a server. In the case, an infrared sensor at each piston gives the moment of the push. This simulator tracks the piece by encoder and uses the sensors to confirm the exits. Read the case study
- Automated warehouse: an M-Duino 19R+ weighs each box at check-in with a load cell and stores the heaviest boxes on the lowest levels. Read the case study
Design choices you make
1. The fire point and the lead
The valve and the piston need some time before the piston plate reaches the belt. The PLC opens the valve a little before the piece arrives: lead distance = belt speed × delay. In this simulator the delay is 0.1 s, so the lead is 5 cm at 0.5 m/s. With an encoder, the PLC measures the speed and the lead follows it.
2. When in doubt, reject
A piece with no stable weight, a piece out of range and a piece that missed its exit all end in the same place: the reject bin at the end of the belt. No valve is needed for it, and a wrong decision never sends a piece to a good exit.
3. Valves through interface relays
The three valves switch many times per minute. Drive them from the three digital outputs of the M-Duino 19R+, each through an interface relay, for example a solid-state type for frequent switching. Each of these outputs gives 20 mA at most (M-Duino family datasheet), and a valve coil needs more. Choose an interface relay or a solid-state relay whose input takes less than 20 mA, or a valve driver. Set the three outputs to digital mode with their switches and feed them with 24 V on QVdc. Keep the eight internal relays for the belt contactors and the alarm lamp, which switch less often. Each relay switches up to 4 A at 230 Vac with a resistive load: drive the motor with a contactor, and add an RC snubber on inductive loads.
4. Exit belts on demand
The main belt runs all the time. Each exit belt starts when its piston fires, as in the meat sorting case, so it does not run empty. In this simulator it stops 5 s after the last push.
5. The queue after a stop or a power cut
After a normal stop, the PLC keeps the queue and the encoder keeps the position, so the line starts again with no loss. After a power cut, the queue is gone: run the pieces on the belt to the reject bin before the line sorts again.
6. Safety stays outside the program
The emergency stop and the guards of the belts and the pistons must not depend on the standard PLC program (IEC 60204-1, ISO 13850). The safety circuit cuts the motors and the air. The PLC reads its state through a feedback contact of the safety relay, drops its commands, stops the sequence and logs the event. See safety interlocks and e-stop on a PLC.
7. Counts from the sensors
Count a piece when its exit sensor sees it, not when the valve opens. Send totals to the server, not increments, so a short network cut does not lose pieces. A typical way: the server reads the counters as Modbus TCP holding registers. See a register map for Modbus TCP on an M-Duino.
Example I/O list for this line
This list follows the simulator: one scale on RS-485, encoder tracking, three exits, a reject bin and the feedback of the safety relay.
| Signal | Count | On the M-Duino 19R+ |
|---|---|---|
| Weighing transmitter of the scale | Count: 1 | On the M-Duino 19R+: RS-485 port, Modbus RTU |
| Encoder pulses | Count: 1 | On the M-Duino 19R+: Isolated input with interrupt, I0.5 |
| Infrared sensors: exits 1, 2, 3 and reject bin | Count: 4 | On the M-Duino 19R+: Isolated input I0.6 and three analog/digital inputs in digital mode |
| Safety relay feedback (E-stop and guards) | Count: 1 | On the M-Duino 19R+: Analog/digital input in digital mode |
| Solenoid valves of pistons 1, 2, 3 | Count: 3 | On the M-Duino 19R+: Digital outputs, each through an interface relay |
| Main belt contactor | Count: 1 | On the M-Duino 19R+: Relay output |
| Exit belt contactors | Count: 3 | On the M-Duino 19R+: Relay outputs |
| Alarm lamp and horn | Count: 1 | On the M-Duino 19R+: Relay output |
| Total used | Count: 6 inputs · 3 digital outputs · 5 relays · 1 RS-485 port | On the M-Duino 19R+: 6 of 6 inputs · 3 of 3 outputs · 5 of 8 relays · 1 of 2 RS-485 ports |
All six inputs are used. For a fourth exit or a reset button, choose the M-Duino 38R+, with 12 inputs and 16 relays. With time tracking, the encoder input is free.
M-Duino 19R+: the specs that matter here
| In the shop | M-Duino 19R (M-DUINO ETHERNET PLC ARDUINO 19R) |
|---|---|
| Inputs | 6: 4 analog/digital (0-10 V, 10-bit) and 2 digital optoisolated, 5 to 24 Vdc, with interrupt |
| Outputs | 11: 3 analog/digital/PWM (0-10 V analog, up to 24 Vdc and 20 mA digital, 8-bit) and 8 relays (230 Vac 4 A / 24 Vdc 2 A, resistive) |
| Controller | Arduino Mega 2560 (ATmega2560, 16 MHz, 256 KB flash, 8 KB SRAM) |
| Communications | Ethernet (W5500, 10/100, RJ45), 2 x RS-485, RS-232, TTL serial, I2C, SPI |
| Built in | Real-time clock, microSD slot |
| Programming | Arduino IDE with the Industrial Shields boards package |
| Power supply | 12 to 24 Vdc |
| Mounting | DIN rail TS35, IP20, inside a cabinet, 0 to 60 °C |
Full specs: M-Duino 19R+ · M-Duino family datasheet.
Learn the building blocks
These examples cover parts of this pattern. Some use an ESP32 PLC: the logic is the same.
- Production pulse counter with interrupts: the base of encoder counting
- Solenoid valve control with a state machine
- Belt speed with a VFD over Modbus RTU on an M-Duino
- Modbus TCP register map on an M-Duino: counters for the server
- Daily log files on an SD card: a piece record on the PLC
- Safety interlocks and e-stop on a PLC
- Machine monitor simulator: counts, OEE and alarms of a machine
More examples: PLC Solution Library · all simulators.
FAQ
How does a PLC track a piece from the scale to its exit?
It keeps a queue: one entry for each piece, in the order the pieces left the scale, with the weight, the exit and the position. The position grows with the encoder pulses, or with the time multiplied by the belt speed. When the position of a piece reaches its piston, minus a small lead, the PLC opens the valve. When the exit sensor confirms the piece, the PLC removes it from the queue.
Encoder or time tracking: which one should I use?
Use an encoder when the belt stops with pieces on it, changes speed, or has exits far from the scale. Time tracking needs no encoder and can work on a short belt at a constant speed that never stops with pieces on it. The error of time tracking grows with the distance, so test it at your last exit.
How does the PLC know that a piece reached its exit?
With a sensor on each exit, for example an infrared sensor across the exit belt or the chute. After each push, the PLC waits a short time for that sensor. No signal means the piece is not confirmed: the PLC raises an alarm, and a sensor at the reject bin tells it if the push failed or if the exit sensor failed.
What happens to a piece the scale cannot weigh?
It goes to the reject bin. When two pieces are on the platform at the same time, there is no stable reading for one piece, so the PLC does not guess a grade. The same happens with a weight below the lowest limit or above the highest limit.
How many pieces per minute can a dynamic scale weigh?
It depends on the platform length, the piece length, the belt speed and the time the reading needs to be stable. One piece must be alone on the platform for that time. With a 0.4 m platform, 0.15 m pieces, 0.3 s of stable reading and 0.5 m/s, the minimum pitch is 0.35 m, about 85 pieces per minute with a perfect spacing. Plan a margin for real spacing.
Can the M-Duino 19R+ drive the solenoid valves directly?
Not directly. Its three digital outputs give up to 24 Vdc and 20 mA, less than a solenoid coil needs. Drive each valve through an interface relay or a solid-state relay with an input under 20 mA, or through a valve driver. The valves switch many times per minute, so keep the internal relays for loads that switch less often, such as the belt contactors.
Do I need to be a programmer to build this?
The logic is a list of rules: the limits, the distances, the times and what to do on each fault, like the tables in this simulator. The M-Duino 19R+ is programmed in the Arduino IDE. The examples above cover the parts. If you prefer, an integrator can write the program from your limits, your belt layout and your I/O list.
Get the I/O list for your line
Tell us about your line: the product, the grades, the pieces per minute and the belt speed. Our team replies with a proposed I/O list and tracking method for your line. Your simulator settings go with the request.