AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Sensor Spacing Rules for Detecting Box Length With Two Sensors

Sensors, encoders and machine vision on the machine Published 10 min read By AutomateDirectUSA engineering team

Short answer

Two sensors sort boxes by length only when their spacing separates the classes: the longest reject box stays shorter than the spacing and the shortest pass box runs longer, each by at least one beam width plus placement tolerance. When every box is shorter than the spacing, use the timed gap t = (D − L − w)/v at a measured belt speed, and carry each reject decision to the pusher in retained per-box state or encoder counts.

On this page
  1. How far apart should two sensors be to sort boxes by length?
  2. How much margin does the sensor spacing need for beam width and mounting?
  3. Do both sensors have to see the box at the same time?
  4. What if the sensors are farther apart than the boxes are long?
  5. What timer preset separates a short box from a long one?
  6. How does the reject pusher know which box to kick?
  7. What if the box lengths overlap the sensor spacing?
  8. How do I verify the spacing before writing the ladder logic?
  9. Questions asked

Two sensors can sort boxes by length only when the spacing between the beams does the sorting: the longest box you must reject stays shorter than the spacing, the shortest box you must pass runs longer, and each side carries margin for the beam spot and your mounting tolerance. When every box is shorter than the spacing, nothing ever bridges both beams at once, and the same geometry becomes a timing problem — the gap between one beam dropping and the next rising shrinks as the box grows. This page gives the spacing rule, the margin arithmetic, the timed-gap formula with a worked preset, and the tracking logic that carries a reject decision to the pusher. Throughout, D is the center-to-center sensor spacing along travel, w the beam spot width, L the box length and v the belt speed.

How far apart should two sensors be to sort boxes by length? #

Set the spacing D so it strictly separates the two classes: the longest reject box must be shorter than D and the shortest pass box must be longer than D, with margin on both sides.

The beams carry length information only while one box is in front of them. The reject box must meet the beams one after the other and never span them together; the pass box must span them, so both inputs read on during the same part of its travel. That single difference is the entire length signal a two-sensor layout has, which is why the spacing rule is a hard geometric requirement and not a number you can tune in software later.

Measure D on the assembled frame, along the direction of travel, from beam center to beam center. Then measure the physical boxes: the longest one you must reject and the shortest one you must pass, not the nominal size printed on the carton. The spacing has to separate the worst cases, and carton labels are nominal.

How much margin does the sensor spacing need for beam width and mounting? #

Leave one beam width plus placement tolerance on each side of the spacing: with a 5 mm spot and ±10 mm bracket tolerance, keep reject boxes at or under 285 mm and pass boxes at or over 315 mm on a 300 mm spacing.

A beam occupies a spot, not a line. Sensor 1 stays on while any part of the box is inside its spot, so both beams see one box at once as soon as its length exceeds the clear distance between the spot edges, D − w. The working rule follows: longest reject box at or below D − w − δ, shortest pass box at or above D + w + δ, where δ is the placement tolerance along travel — it has to absorb bracket repeat-position, belt wander and box skew, and ±10 mm here is an example to replace with your own measurement. On the example numbers, 300 − 5 − 10 = 285 mm and 300 + 5 + 10 = 315 mm.

Boxes between those two limits are not guaranteed either way: the same box can read short on one pass and long on the next. Give that band an explicit rule — boundary length passes and everything under it rejects, or the reverse, whichever failure is cheaper for you — or move the beams until the band is empty.

Do both sensors have to see the box at the same time? #

Yes — the length test is both inputs on in the same scan while one tracked box is in front of the beams; a box that touches sensor 1 and later sensor 2 proves nothing, because every box long enough to cross the belt eventually does both.

Sequential detections carry no length information at all. Short boxes and long boxes alike arrive at sensor 1 and, if the belt keeps moving, at sensor 2, so a logic that remembers “one, then the other” cannot sort anything. The sort lives in the overlap: the AND of the two inputs while the same box is present.

Size the overlap window on the worst case, the shortest pass box: the both-on time is (L − D + w)/v. On the running example's limits that window is 0.020 m of travel, 40 ms at 0.5 m/s. Keep input filtering plus scan time well inside it — a 10 ms filter and a 10 ms scan consume half the window before the logic sees it — so shorten the filter, use an on-change input, or slow the belt until the arithmetic holds.

What if the sensors are farther apart than the boxes are long? #

Then no box can bridge the two beams, so classification moves from overlap to timing: the gap between sensor 1 dropping and sensor 2 rising is t = (D − L − w)/v, valid only while D exceeds L + w and the belt speed holds steady.

A longer box closes that gap and a shorter box stretches it, and that inversion is the entire test. Start a timer on sensor 1's falling edge — the trailing edge of the box — reset it if sensor 2 rises before the preset, and treat a completed timer as a short box: reject.

The preset is only as good as the speed it assumes, because every gap time scales as 1/v. A belt running 10% slow stretches every gap by about 11%, and a pass box starts to look short. So either hold the speed regulated, measure it each cycle and rescale, or replace clock time with distance: an encoder on the belt turns both edges into counts, and the count gap between them is speed-independent. For how encoder counts get scaled against a moving belt, see matching a stepper feed rate to conveyor speed with an encoder.

What timer preset separates a short box from a long one? #

With D = 300 mm, w = 5 mm and v = 0.5 m/s, a 200 mm reject box gives a gap of 0.19 s and a 250 mm pass box gives 0.09 s, so set the preset between them at 0.14 s.

The arithmetic, shown once for these inputs: t_reject = (0.300 m − 0.200 m − 0.005 m) ÷ 0.5 m/s = 0.19 s, and t_pass = (0.300 m − 0.250 m − 0.005 m) ÷ 0.5 m/s = 0.09 s. Any preset strictly between 0.09 s and 0.19 s separates the classes, and 0.14 s leaves about 50 ms of margin on each side. This is the population where every box is shorter than the spacing — rejects up to 200 mm, passes from 250 mm — so no box ever bridges the beams and the overlap test never fires.

Check the preset at the speed extremes before trusting it. At 0.45 m/s the same two boxes gap 0.21 s and 0.10 s; at 0.55 m/s they gap 0.17 s and 0.08 s. For this example 0.14 s still separates all four, with the tightest margin roughly 30 ms on the reject side at the fast speed — past about a ±10% speed swing a fixed preset stops being a decision you can defend, and distance counting takes over.

One ladder detail decides whether the rung behaves: in the timers this kind of rung uses, the elapsed value stops climbing at the preset, so “waited longer than the preset” never appears as a number — the done bit is the only signal, which is exactly the subject of why a timer's elapsed time never exceeds its preset in ladder logic. Reset the timer on sensor 1's rising edge as well, so a stale done bit from the previous box cannot fire the pusher into an empty station.

How does the reject pusher know which box to kick? #

The classification is worthless unless it travels with the box: hold one retained record per box — unknown, pass or reject — and fire the pusher only when the box carrying a reject record reaches the station, tracked by encoder counts or a queue.

A one-scan edge event is not a record. The decision made at the beams has to survive the whole ride to the pusher, through seconds of scanning, start-stop commands and other boxes in between. Create the record when the box's leading edge finds sensor 1 and consume it at the pusher or at the end of the belt.

Distance decides when to fire. Register the box's position from an encoder, add the known beams-to-pusher distance, and command the solenoid when the tracked box reaches the station. If more than one box can sit between the beams and the pusher, a single pending bit will push the wrong one, so track the boxes in order — the exact job covered by tracking conveyor parts with an encoder and a FIFO buffer. A single bit is defensible only when the infeed mechanics guarantee one box is decided and dispatched before the next can be.

Keep the kick-off station guarded as a pinch point, and let the e-stop drop out the conveyor drive directly as the machine's stop function requires under IEC 60204-1 — never route the stop through the sorting logic.

What if the box lengths overlap the sensor spacing? #

No spacing can separate classes that overlap: if a box you must reject can be longer than a box you must pass, two on/off sensors cannot classify every box, and the fix is a boundary rule, a third beam or a sensor that measures length directly.

Check it on paper before building anything. List the shortest and longest box in each class and confirm every reject length sits below every pass length; if any reject length can exceed any pass length, the two-beam layout is finished.

The ambiguous band around the spacing — 285 mm to 315 mm in the running example — is a softer version of the same problem, and it needs an explicit rule too: treat the band as pass or as reject, whichever failure is cheaper to sort out by hand. When the classes truly interleave, your options are a third beam at a new spacing, a boundary rule agreed with production, or a sensor that measures length directly. Measuring is the clean fix: a machine vision camera over the belt returns a length for every box, and the decision moves from geometry to a threshold you set in software.

How do I verify the spacing before writing the ladder logic? #

Prove the geometry with hardware before writing a rung: measure D on the assembled frame, check the exact sensor's response time against the edge-crossing time w/v, then run one known reject box and one known pass box past the beams and watch both inputs in the controller's monitor.

The response check is where spacing designs quietly fail. A box edge sweeps the spot in w/v — 10 ms at the running speed with a 5 mm spot, only 5 ms at 1 m/s — and the output has to follow that edge cleanly. Response times documented for one major photoelectric family, the PHOTOSWITCH technical data from Rockwell Automation, span 30 µs to 30 ms across models, a thousand-to-one spread, so a slow model can smear or miss a short pulse entirely. Take the response time from the datasheet of the exact sensor you mounted, and size the in-beam time at ten times that figure or more; at the example speed, that rules out anything slower than 1 ms.

Then watch real boxes. Run the known reject box past the beams and confirm the two inputs never read on together; run the known pass box and confirm a both-on window at least as wide as the arithmetic predicted, on every pass, not once. If a pass box occasionally fails to overlap, suspect the input filter, a skewed box or a spot wider than the datasheet's typical figure. Test the boundary boxes too — the longest real reject and the shortest real pass — because those are the only boxes the spacing actually has to get right.

That leaves three clean decisions. If the longest reject clears the spacing by a beam width plus tolerance and the shortest pass clears it the other way, use overlap logic and AND the inputs. If every box is shorter than the spacing, use the timed gap with the preset computed at your measured speed, or encoder counts if the speed moves. If neither geometry holds, add a beam, set an explicit boundary rule, or measure each box.

Questions asked

Which photoelectric sensor type suits box detection on a conveyor?

Through-beam pairs are the default for box work: sender and receiver sit on opposite sides of the belt, so the reading does not depend on box color, print or finish, and through-beam models reach the longest ranges — a sensor maker's application guide gives more than 10 m for the type. Retroreflective models mount everything on one side with a reflector, while diffuse models read the box surface itself, which varies with packaging and print.

Can the same two sensors measure box length instead of just sorting it?

Yes. While a box blocks one sensor, the on-time is (L + w) / v, so L = t × v − w: time how long the input stays on, multiply by the measured belt speed, subtract the spot width. Each percent of speed error becomes the same percent of length error, so measure the speed with an encoder rather than assuming it, and keep the spot width correction so short boxes do not read long.

Does the reject cylinder need its own feedback sensor?

Add a magnetic or proximity sensor at the full-out position of the pusher cylinder. The pusher must complete its stroke before the next tracked box arrives, and the controller should not treat a box as cleared until it has seen full-out followed by the return. Without stroke feedback, a slow valve or low air pressure can leave a reject half-pushed in the path of the next cycle.

What should the logic do if the conveyor stops with a box between the beams?

Keep the retained per-box record and the position counts through the stop, and decide the restart behavior in advance: either resume counting from where the box stopped, or require the belt to run clear and delete every pending record. Never clear a pending reject while its box is still on the belt — the next box inherits the push, or the reject rides off the end of the conveyor.

Keep reading

  • How-to

    Wiring a Proximity Switch to Trigger a Robot Gripper and Conveyor

    Wire the sensor's positive and 0 V supply wires to the 24 V DC source and the switched output wire to a robot digital input, taking all three terminal assignments from the sensor datasheet rather than wire color. Confirm the input changes state at Menu > I/O > Digital, then prove the 3-second conveyor run lands the part in the next slot over many cycles, because a timed index only matches the slot pitch while travel stays repeatable.

    Sensors, encoders and machine vision on the machine

  • How-to

    How to Build a DIY Belt Conveyor Scale With One Load Cell

    Yes, but only as a calibrated system: suspend one idler on a load cell, keep it within 1 mm of its neighbors, measure belt speed at a non-drive pulley, and multiply load per foot by speed. Calibrate the span against weighed material. Expect percent-level totals, not 5 lb accuracy on short runs.

    Sensors, encoders and machine vision on the machine

  • Troubleshooting

    Why an inductive proximity switch cannot sense motion itself

    An inductive proximity switch cannot sense motion: its output reports only whether a metal target is inside the sensing field. To detect a stopped or very slow mechanism, convert the switch's on/off transitions into events, measure the time between identical edges, and trip a slow-or-stopped fault when that interval exceeds a timeout set from the process. Verify first that the target switches the output decisively at both ends of travel.

    Sensors, encoders and machine vision on the machine