Lenses & opticsHow-to

M12 lens focusing: adjust, check corners and lock

Use M12 lens focusing steps to set working distance, compare center and corner sharpness, diagnose tilt, and verify focus after locking the lens.

LumaSpec Vision10 min read Share on LinkedIn

On this page 8 sections
  1. 01Prepare the camera, target and focusing tools
  2. 021. Set the working distance and square the target
  3. 032. Stabilize illumination, exposure and image display
  4. 043. Sweep the threaded lens through focus
  5. 054. Compare focus positions before diagnosing tilt
  6. 065. Lock the lens without changing its position
  7. 076. Verify the operating range and record acceptance
  8. 08Questions

A threaded lens can produce a sharp center while leaving an inspection feature near the edge unreadable. Tightening its lock can then move the focus again. For an embedded vision station, focusing must therefore include target alignment, controlled image acquisition, and a final check after locking. This procedure helps you find a repeatable focus position at the intended working distance, compare several image regions, and separate ordinary defocus from problems that need mechanical investigation.

Prepare the camera, target and focusing tools

Start with a rigid camera fixture, a flat target, steady illumination, and access to the lens without pressing on the camera board. You also need live images at native resolution and a way to save frames without changing their processing.

Confirm the lens thread specification, available adjustment travel, rear clearance, and approved locking method from the component documentation. A matching nominal mount does not establish clearance throughout the focusing range. The lens focal length and back focus explanation covers why focal length alone cannot tell you where a lens must sit.

For optical compatibility, check the M12 board lenses category and the board-camera lens selection guide. The lens finder helps narrow candidates before you attempt mechanical adjustment.

The LS-MBL-0012 and LS-MBL-0113 are catalog options with an M12 mount. Their listings are starting points, not confirmation of compatibility with your holder or required focus distance.

M12 board lenses5 MP S-mount low distortion board lens, 12 mm, 1/1.8" (LS-MBL-0012)LS-MBL-0012
Sensor format
1/1.8"
Mount
M12
$89.00View part
M12 board lenses12 mm, F2.8, 1/1.8", 5 MP lens, M12-mount (LS-MBL-0113)LS-MBL-0113
Sensor format
1/1.8"
Mount
M12
$39.00View part

For an existing camera, establish its sensor dimensions, lens-holder arrangement, and image-processing settings. If these are still undecided, use the board-level cameras category and camera finder. The embedded camera selection guide explains the broader integration checks.

Choose a target containing repeatable edges or fine patterns across the field. The LS-LXR-0029 is a dot-grid calibration target. Its dot boundaries can provide local sharpness checks, provided their projected size suits your camera; a calibration pattern is not automatically a fine-resolution focus chart.

Lens accessoriesCalibration boards and depth-of-field rulers, dot diameter 0.5 mm, dot grid, 76 x 76 mm (LS-LXR-0029)LS-LXR-0029
Type
Calibration targets
$189.00View partBuild a system with it

1. Set the working distance and square the target

Place the target at the actual inspection plane. Measure working distance from a clearly recorded camera or lens reference surface, rather than an unspecified point on the assembly. Keep that reference consistent during later verification.

Make the target flat and approximately parallel to the sensor plane. Use a fixture or measured mechanical references rather than judging alignment from the live image alone. Perspective can make a tilted target look acceptable, especially with a narrow field of view.

Use one focus patch at the center and four additional patches toward the corners. A repeatable starting layout places those outer patches about 75% of the distance from image center toward each corner. Move them outward if critical inspection features occupy the outermost image area.

Check that the patterns are adequately sampled. As an illustrative example, assume an image spans 80 mm across 1600 horizontal pixels:

Object sampling = field width / horizontal pixels = 80 mm / 1600 pixels = 0.05 mm/pixel Pixels across a feature = feature width / object sampling = 0.20 mm / 0.05 mm/pixel = 4 pixels

Four pixels across the feature provide a more useful focusing signal than a feature occupying only one pixel. This is a sampling illustration, not a guarantee of inspection performance. The target still needs sufficient contrast and optical detail.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

2. Stabilize illumination, exposure and image display

Use steady lighting that reveals all target patches without clipped highlights or deep shadows. Avoid glare across the patterns. If brightness changes while you rotate the lens, a focus score may change for reasons unrelated to sharpness.

Disable automatic exposure and automatic gain during the focus sweep. Where available, also hold sharpening, noise reduction, gamma, and other processing settings constant. Use the same illumination wavelength and filter arrangement intended for inspection.

Set exposure so bright target regions retain detail. There is no universal gray-level value that establishes correct focus: bit depth, processing, target reflectance, and illumination all affect the displayed number. The exposure brightness target guide explains how to establish a repeatable exposure reference.

View the image at native pixel scale, using separate crops for the center and outer patches. A scaled preview can hide blur or create misleading edge patterns. Keep the camera and target stationary, and allow vibration from each adjustment to stop before evaluating a frame.

3. Sweep the threaded lens through focus

First identify the permitted adjustment range. Do not search for focus by driving the lens against an unknown mechanical stop. Moving inward can bring the rear lens assembly dangerously close to the sensor or cover glass.

For a verified thread pitch, axial movement follows this relationship:

Axial movement = thread pitch × rotation in turns Example for a verified 0.5 mm pitch: Movement for 1/16 turn = 0.5 mm × 1/16 = 0.03125 mm ≈ 31 µm

The example applies only when the documented pitch is 0.5 mm. Do not infer pitch or safe travel from the mount name alone. Small angular changes can produce meaningful axial movement, so progressively reduce the adjustment size near the sharpest position.

Follow a controlled sweep:

  1. Capture a reference frame and record the initial lens position using a removable witness mark or an angular reference.
  2. Rotate the lens slightly within its verified safe travel, release it, and capture another frame.
  3. Compare the same center and outer target patches using unchanged display and acquisition settings.
  4. Continue while sharpness improves, then pass slightly beyond the apparent maximum if clearance permits.
  5. Return toward the best position using smaller increments and the same final approach direction.
  6. Repeat the approach once to check that the apparent best position is reproducible.

Using the same approach direction reduces ambiguity from thread clearance; it does not eliminate tilt or guarantee repeatability. Avoid lateral pressure on the lens while evaluating focus.

For numerical evaluation, use one consistent metric on comparable regions. The image sharpness measurement guide explains why noise, saturation, and target content can distort a focus score. Compare each patch against its own sweep history rather than assuming different patterns should produce equal scores.

4. Compare focus positions before diagnosing tilt

Record where each patch reaches its best sharpness. Equal scores are not required; the useful question is whether the patches reach acceptable sharpness at the same lens position.

For example, suppose the center and left patches peak near the same witness mark, but the right patches improve only after another small rotation. That indicates different preferred focus positions across the image. It does not, by itself, identify the tilted component.

Observed behavior Likely explanations Discriminating check
All patches improve and soften together Ordinary defocus Repeat a smaller sweep around the common maximum
One side peaks before the opposite side Target tilt or optical/mechanical misalignment Re-square the target, then repeat the sweep
Center peaks separately from all corners Field curvature, target shape, or lens performance limits Verify target flatness and compare all outer patches
One corner remains weak throughout the sweep Local target problem, contamination, decentering, or assembly fault Inspect the target and optical surfaces, then repeat
Sharpness changes when hand pressure is released Fixture movement or thread/holder movement Remove applied loads and check mechanical stability

Correct target alignment before assigning blame to the holder. A tilted target places opposite sides at different object distances, which can imitate an image-plane alignment problem.

If the pattern persists after careful target setup, inspect holder seating, mounting stress, thread engagement, and assembly documentation. Images alone generally cannot distinguish sensor tilt from holder tilt or lens decentering. Refer unresolved assembly concerns to the component vendor rather than bending the holder or modifying the camera board.

When center and corners prefer different focus positions, select the position that meets the actual inspection requirement across the required field. Do not automatically maximize the center score at the expense of a critical edge feature.

5. Lock the lens without changing its position

Use the locking arrangement approved for the lens and holder. Suitable approaches depend on the assembly; a lock ring, retaining feature, or adhesive must not be assumed interchangeable.

Before locking, save an image and record the focus scores or visual acceptance checks for every patch. Support the assembly without loading the board or pushing the lens sideways.

If the design uses a lock ring, hold the lens position while tightening the ring according to the documented method. Ring contact can rotate the lens or change its seating. Capture another image after releasing your hands completely.

Use adhesive only when the component documentation permits it and specifies a compatible material and application location. Follow the documented curing process and handling precautions. Do not introduce adhesive near optical surfaces or improvise a curing process around an exposed sensor.

Check focus after the locking operation and, where applicable, after curing. If it moves, correct the locking process rather than treating a pre-lock image as proof of final performance. Repeatedly compensating by guesswork can hide a mechanically unstable assembly.

For compatible fixtures and targets, browse lens accessories or the accessory finder. Confirm the interface before ordering any retaining component.

6. Verify the operating range and record acceptance

A flat target verifies one object plane. Your inspection may also include part-height variation, placement tolerance, and a camera assembly that warms during operation. Check those conditions after the lens is locked.

Depth of field around the focus plane Light from the lens converges on the focus plane. In front of and behind it, each point spreads into a blur circle; the zone where that blur stays below about a pixel or two is the depth of field. A smaller aperture gives a narrower cone and a deeper zone.depth of fieldfocus planeapertureoutside it, pointsblur into circleswide aperture: steep cone, shallow zonesmall aperture (high F#): deeper zone
Depth of field around the focus plane. Light from the lens converges on the focus plane. In front of and behind it, each point spreads into a blur circle; the zone where that blur stays below about a pixel or two is the depth of field. A smaller aperture gives a narrower cone and a deeper zone.

Depth of field describes an acceptable object-distance range, not a region of identical sharpness. Define acceptance using the inspection task, such as reliable edge localization or recognition of the smallest required feature. A visually attractive image can still fail that task.

As a worked acceptance example, suppose a nominal target plane is 100 mm from your chosen reference and part placement varies by ±2 mm. Test at 98 mm, 100 mm, and 102 mm, keeping the camera fixed. These are example application distances, not lens specifications. Include intermediate positions if the inspection margin is narrow.

If only the center position passes, changing focus alone may not solve the problem. You may need different optics, a smaller usable field, tighter part positioning, or another supported aperture arrangement. Many compact lenses do not provide an adjustable iris, so verify the actual construction before planning an aperture change.

Repeat the check after thermal stabilization. If warm-up changes sharpness, use the temperature-related focus drift procedure to separate optical drift from changing exposure or motion.

Before releasing the setup, confirm:

  • Geometry: The reference surface, working distance, target plane, and required inspection field are recorded.
  • Acquisition: Exposure, gain, processing, illumination, and image scaling are documented and repeatable.
  • Field performance: Center and outer inspection regions pass at the locked lens position.
  • Operating tolerance: Required object heights and expected warm-up conditions have been checked.
  • Mechanical stability: Removing hand pressure and completing the lock do not change acceptance.
  • Traceability: Final images, lens identification, locking method, and acceptance criteria are saved.

If the lens never reaches a usable focus position within verified safe travel, revisit optical and holder compatibility rather than forcing further movement. Use the lens configurator to narrow suitable optics, or send your working distance, sensor dimensions, holder details, and center-to-corner examples through applications support.

Questions

Should I focus an M12 lens using the center or the corners?

Focus with the target at the intended inspection distance, then compare the center with several outer image regions. Use fixed exposure and repeatable target patterns. The best setting is the one that meets your inspection requirement across the required field, not necessarily the position giving the highest center sharpness score.

How far does an M12 lens move when I rotate it?

Axial movement equals the verified thread pitch multiplied by the rotation in turns. For a documented 0.5 mm pitch, a quarter turn moves the lens 0.125 mm. Confirm the actual thread specification and permitted travel before adjustment; the mount name does not establish rear clearance.

Why is one side sharp while the other side remains blurry?

Possible causes include a tilted target, holder or sensor misalignment, lens decentering, and movement under hand pressure. First verify target flatness and alignment, then repeat the focus sweep. Persistent asymmetry warrants mechanical inspection, but an image alone usually cannot identify which component is misaligned.

Does pointing the camera upward eliminate lens tilt?

No. Orientation can change how loose components seat, but it does not establish parallel optical surfaces or correct a misaligned assembly. Use rigid fixtures, measured alignment references, and repeated image checks. Validate the camera in its intended operating orientation after the lens is locked.

Can I use adhesive to retain the final focus position?

Use only a locking method approved for the lens and holder. If adhesive is permitted, follow the specified material, location, curing process, and precautions. Mechanical locking is not automatically shift-free either. Save comparison images before locking and verify acceptance after the operation is complete.