STEPS
  • 1distance
  • 2coverage
  • 3focal length
  • 4nearest variant
  • 5recheck

Working Out the Lens You Need

Generic engineering material, applicable to any module from any supplier.

Additional workflow context is available this resource.

The calculation takes ten minutes and is the step most projects skip, arriving instead at a lens by ordering the one in the example and adjusting the mounting until it roughly works.

The five steps

One. Fix the working distance. From the lens to the subject, measured in the intended installation — not from the housing, the bracket or the board, which differ by enough to matter on a short-focal-length module.

Two. Fix the required coverage. The width of the area that must appear in frame, including whatever margin the part position variation demands.

For broader technical context, see Electronic Design.

Three. Compute the focal length. Sensor width × distance ÷ required coverage, using the millimetre sensor dimensions rather than the inch fraction.

Four. Take the nearest available variant and recalculate. No family offers exactly your number, so work out what the available one actually covers and check it against the requirement.

Five. Check the resolution at that coverage. Millimetres per pixel, then pixels across the featurewhich is the requirement the whole exercise serves and which the first four steps do not guarantee.

Where it goes wrong

The working distance, measured optimistically.

People measure to the front of the enclosure, or to where the camera will "roughly" sit, and the error is a straight proportional error in the coverage.

And the coverage, specified without margin.

A field of view exactly the width of the part is a field of view that clips whenever the part sits slightly off — and part position variation is the same quantity depth of field needs, so measuring it once serves both.

Rounding

Round toward covering more, not less.

A system covering slightly more than required wastes pixels at the edges. One covering slightly less fails, and fails intermittently as parts shift.

Which means when the calculation lands between two available variants, take the wider oneunless the resolution check at that coverage falls short, in which case the answer is a different sensor or two cameras rather than a compromise on either.

Recording it

The five numbers, with the assumptions.

Distance, coverage, sensor dimensions, chosen focal length, resulting millimetres per pixel.

Because the calculation gets redone every time somebody asks whether a different variant would work, and because a change to any input makes the consequence visible immediately.

And because a lens chosen without a recorded reason gets questioned indefinitely.

A worked example

A part 80 mm wide, inspected at 250 mm, on a sensor 3.6 mm wide, needing three pixels across a 0.5 mm feature.

Coverage with margin: 100 mm.

Focal length = 3.6 × 250 ÷ 100 = 9 mm. Take the nearest available.

Say the nearest is 8 mm, which covers 3.6 × 250 ÷ 8 = 112 mm — wider than needed, which is the correct direction.

Resolution: 112 mm ÷ 640 pixels = 0.175 mm per pixel, so the 0.5 mm feature lands on under three pixels.

Which fails the requirement, and the answer is a higher-resolution sensor rather than a different lens — because the lens is already as narrow as the coverage permits.

Ten minutes, and it identified the real constraint before anything was ordered.

When the geometry does not close

The example above is the common outcome, and it is useful rather than discouraging.

Something has to move: a shorter working distance, a tighter coverage requirement, a finer sensor, or two cameras.

All four are decisions, and all four are cheaper now than after a module is designed in.

The failure mode is not doing the calculation and discovering the same constraint at integration, when the mechanics are built and the module is in the bill of materials.

Checking against the real thing

Before committing, photograph the actual scene with an evaluation kit carrying the chosen variant.

Measure the coverage and the pixels on the feature rather than trusting the arithmeticsince the arithmetic depends on a sensor dimension, a focal length and a distance, any of which may differ from the assumption.

Agreement between calculation and measurement is the confirmation that all three inputs were right.

The margin question

How much extra coverage is enough.

It comes from three sources: part position variation, mounting tolerance, and whatever the installation might change later.

The first two are measurable and should be measured rather than estimated.

The third is judgement, and a modest allowance is cheap while a system that cannot accommodate a small change is not.

What is not acceptable is no margin at all, which is what a coverage figure equal to the part width represents.

Two cameras, revisited

When the calculation fails, this is the option people consider last and should consider second.

Two narrower cameras covering halves deliver better millimetres per pixel, less distortion at the edges and more even illumination.

They cost a second module, a second interface, a stitching problem, and a second mounting to align.

Against a finer sensor, which costs data rate, light per pixel and processing.

Both are real answers and the arithmetic decides between them — which is why doing it first matters more than which conclusion it reaches.

In one line

Do the arithmetic before ordering, because it takes ten minutes and it finds the real constraint.

The short version

  • Five steps: fix the distance, fix the coverage, compute the focal length, take the nearest variant and recalculate, then check resolution
  • Measure the distance from the lens rather than from the housing, which differ enough to matter on short focal lengths
  • Specify coverage with margin for part position variation, which is the same quantity depth of field needs
  • Round toward covering more: extra coverage wastes edge pixels and insufficient coverage fails intermittently
  • Where the resolution check fails at the wider variant, the answer is a different sensor or two cameras
  • Record the five numbers with the assumptions, since the calculation is redone every time somebody proposes an alternative