Code readingHow-to

Trigger a fixed code reader from a GPIO pin instead of free-run

Wire a GPIO pin through an optocoupler to a code reader's trigger input, replace free-run with one decode per part, with resistor and pulse-timing maths.

LumaSpec Vision10 min read Share on LinkedIn

On this page 9 sections
  1. 01Why does free-run scanning miss codes at a fixed station?
  2. 02Which pins close the trigger circuit on a fixed code reader?
  3. 03How much voltage and current does a trigger input need?
  4. 04How do you wire a 3.3 V GPIO pin to the reader?
  5. 05How do you switch the reader from free-run to external trigger?
  6. 06How long should the trigger pulse stay closed?
  7. 07How do you prove the wiring works before it goes on the line?
  8. 08When is a GPIO trigger the wrong answer?
  9. 09Questions

A code reader left in free-run decides for itself when to scan. It fires on any motion in front of the lens, so it can decode the previous part's label, the empty belt between parts, or nothing at all when a part arrives mid-decode. If your controller — a PLC output or a GPIO pin on an embedded Linux board — already knows the moment the part sits under the reader, that moment should be the trigger. This guide wires that signal end to end: the reader's input pair, the optocoupler and its resistor arithmetic, a 50 ms pulse budget, and the bench test that proves one pulse yields exactly one decode.

Why does free-run scanning miss codes at a fixed station?

Free-run fires whenever the image changes, so a capture can belong to the previous part's label, to a shadow, or to no part at all; a GPIO trigger fires one capture at the instant your controller knows the part is in position, so every decode has an owner.

The failure is quiet. A free-run reader cycles aim, capture and decode as fast as its decoder allows, and a part that crosses the field during a decode waits for the next cycle — by then it has moved. Background motion decodes as phantom scans with no part attached. Because nothing in the data path records what caused a capture, the script cannot tell a real read from noise. A hardware input removes all three at once: the capture lands at a known instant, the decode fits inside a budget you chose, and the log can carry the trigger timestamp beside the payload.

If the open question is which trigger source to use at all — part sensor, serial command or free-run — the trigger modes for fixed barcode readers guide compares them before you cut cable. More wiring-level guides sit on the code-reading topic page.

Which pins close the trigger circuit on a fixed code reader?

Two: a trigger input and its common, brought out on an I/O connector or loom beside the power pair, coupled through an optocoupler so that you are closing a small LED circuit, never switching the reader's supply.

The pinout table in the reader's manual names them. On industrial fixed-mount units the I/O sits on its own connector or a pre-made cable: trigger in, trigger common, one or more outputs, sometimes an auxiliary voltage pin. The code reader accessories page gathers the looms, mounts and covers that go with these readers, and the fixed code readers category is where the reader list lives.

Buying into the right hardware is half the job: a reader whose listing shows the I/O loom is ready for this build. The LS-CRD-0052's listing shows dual aviation plugs and a 12 mm lens on its 1.2 MP sensor — the connector style this class uses for a power-and-trigger loom.

Fixed code readersDual aviation plug fixed industrial barcode reader, 1.2 MP, focal length 12 mm (LS-CRD-0052)LS-CRD-0052
Resolution
Up to 3 MP
Shutter
Global
Interface
Ethernet
$559.00View part

How much voltage and current does a trigger input need?

Opto-coupled trigger inputs on industrial readers are typically built for the 5–24 V control domain at a few milliamps through the coupler's LED; that envelope is exactly why a 3.3 V logic pin must not be wired straight across the input.

Industrial inputs exist to accept PLC transistor outputs, which swing 24 V, not logic levels. The coupler's LED inside the reader drops roughly 1.2 V of the applied voltage; the rest burns in a series resistor, in the reader or in your wiring, according to where the pinout table puts it. The current is milliamps, not amps: a trigger is a signal, and treating it as one is what keeps the logic side alive. The numbers here are the envelope you can plan the wiring around; your reader's own rating sits on its pinout page.

How do you wire a 3.3 V GPIO pin to the reader?

Through a general-purpose 4-pin transistor-output optocoupler (the PC817 class): the GPIO pin drives the coupler's LED through a 220 Ω resistor at about 9.5 mA, and the coupler's transistor closes the reader's input pair, so board ground and reader ground never touch.

R = (V_drive − V_LED) / I_LED R = (3.3 V − 1.2 V) / 10 mA = 210 Ω → nearest standard value above: 220 Ω I_LED = (3.3 V − 1.2 V) / 220 Ω = 9.5 mA

You need one 4-pin transistor-output optocoupler, one 220 Ω resistor (a 390 Ω if your pin is 5 V), the reader's I/O connector or loom, and a multimeter.

  1. Wire the GPIO pin to a 220 Ω resistor, the resistor to the coupler's LED anode, and the LED cathode to logic ground.
  2. Wire the coupler's collector to the reader's trigger-in positive pin and the emitter to its common; the pinout table names them, and on readers that bias their own input the pair is input and ground.
  3. Bridge nothing else between the two ground domains. Isolation is the point: a 24 V fault on the reader loom has no path into the logic board.
  4. For a 5 V pin, recompute first: (5 V − 1.2 V) / 10 mA = 380 Ω, so fit 390 Ω.
  5. Run the trigger pair as twisted pair and keep it away from contactor and motor cable.

The pulse itself is four lines in a script:

from gpiozero import DigitalOutputDevice  # documented GPIO class on Linux single-board libraries
from time import sleep

trigger = DigitalOutputDevice(17)  # int pin number; initial state False (low)
trigger.on()                       # True: coupler LED lit, reader input closed
sleep(0.05)                        # float hold: 0.05 s = 50 ms
trigger.off()                      # False: input released, reader returns to ready

The test that proves the wiring: a multimeter across the reader's input pair shows the open-circuit voltage collapse for 50 ms, once per pulse, never at any other time.

How do you switch the reader from free-run to external trigger?

In the reader's configuration menu or host command set, change the read mode from continuous to external (hardware) trigger, leave the USB interface in keyboard (HID) mode so decodes still arrive as text, then power-cycle and confirm it scans only when the input closes.

Mode names move between families — external trigger, hardware trigger, level versus pulse-edge — but the setting lives in the configuration tool and survives a power cycle. Choose level triggering where the tool offers it: a held level tolerates contact bounce and cable noise in a way a fast edge does not. Keep the data interface untouched; keyboard mode is why this build needs no vendor SDK and no serial parser — the decode arrives as plain text, and the USB data capture guide shows a script reading it. The free-run-by-default trap exists on the camera side too, which is why the hardware trigger configuration guide starts at acquisition mode.

For a bench build, the LS-CRD-0047 is the compact shape of this set-up: USB 2.0, 1.2 MP, and a 60–120 mm reading distance that suits hand-placed labels.

Fixed code readersCompact fixed industrial barcode reader, 1.2 MP, USB 2.0, 60-120 mm reading distance (LS-CRD-0047)LS-CRD-0047
Resolution
Up to 3 MP
Shutter
Global
Interface
USB
$559.00View part

If the reader has no trigger input at all, the software-trigger route in the trigger-modes guide fires a serial or network command at the same instant — same timing maths, different transport.

How long should the trigger pulse stay closed?

Hold the input closed for 50 ms. The budget: 33.3 ms worst-case frame wait at 30 fps plus 16.7 ms decode at 60 codes/s (1 ÷ 60 s) totals 50 ms, and a 50 ms hold still permits 20 triggers per second (1 ÷ 0.05 s).

t_hold ≥ t_frame + t_decode = 1/30 s + 1/60 s = 33.3 ms + 16.7 ms ≈ 50 ms max trigger rate = 1 / 50 ms = 20 per second

Worked example, a moving belt: parts pass at 150 mm/s on 200 mm pitch, and the label sits 40 mm past the part sensor.

trigger delay = distance / speed = 40 mm / 150 mm/s = 0.267 s ≈ 270 ms

The controller waits 270 ms after the sensor edge, then holds the input for 50 ms. During the hold the part travels 150 mm/s × 50 ms = 7.5 mm, and the next part is 200 mm away, so holds never overlap.

Motion blur is the other constraint. A 10 mm QR code with 25 modules across has 0.4 mm modules; a third of a module is 0.13 mm, and 0.13 mm ÷ 150 mm/s ≈ 0.9 ms of exposure headroom. Set 0.5 ms and the blur is 150 mm/s × 0.5 ms = 0.075 mm — one fifth of a module, comfortably inside budget. The LS-CRD-0028 quotes 30 fps and 60 codes/s on a global shutter, the two printed numbers this budget is built on.

Fixed code readers2560 x 2048 fixed code reader, 30 fps, 60 codes/s, 8 mm lens (LS-CRD-0028)LS-CRD-0028
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.7"
Shutter
Global
$920.00View part

For moving labels, filter by global shutter in the code reader finder: a rolling-shutter reader smears that same 0.075 mm of travel across rows and the decode rate falls before the image looks wrong. The camera-side cadence maths is identical — external pulses and camera frame rate works the same budget.

How do you prove the wiring works before it goes on the line?

Four bench checks settle it: meter the pulse, fire one trigger at a known-good code, log 100 pulses against 100 decodes, and repeat the count on the machine's own 24 V supply before the reader leaves the bench.

  1. Idle state: measure across the reader's input pair and write the open-circuit value down.
  2. Pulse shape: run one 50 ms pulse; the meter value collapses for the hold time and no longer.
  3. Single decode: aim at a known-good test code, fire one pulse, expect one beep and one line of text.
  4. Acceptance count: log 100 pulses and count the decodes — 100 is the pass mark.
  5. Line power: repeat the count with the reader fed from the machine's 24 V supply, not the bench supply.
  6. Data path: confirm the text lands inside your program. A keyboard-mode reader types into whatever holds input focus, so the receiving window must be the one that owns it; the USB setup and readback checklist covers first-connection checks, and two listeners fighting over one scanner is the two listeners on one screen failure.

When is a GPIO trigger the wrong answer?

Move up to a PLC transistor output or a networked reader when the cable run passes a couple of metres through a noisy cabinet, or when the decode result must land in a PLC's memory rather than inside one script's input stream.

A PLC output drives the 5–24 V input domain natively, so the coupler moves to the reader's side or drops out entirely once the input's bias type matches the output. Past a couple of metres, the long run belongs on the 24 V side with shielded cable, not on a logic pin. And when the result has to reach a controller, network the reader: the MV-ID3013PM-12M-WBN is a compact 1.3 MP reader with a 12 mm lens on Fast Ethernet, and the TCP server wiring guide turns its decodes into messages a PLC reads; the PLC communication planning guide covers the handshake and retry around them.

Fixed code readersHikrobot MV-ID3013PM-12M-WBN 12mm focal length 1.3 MP Compact Industrial Code ReaderMV-ID3013PM-12M-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
Shutter
Global
Lens mount
M12
$1,979.00View part

One pin can also serve several devices: one coupler per reader with the LED branches in parallel, or a serializer board's GPIO routing fanning one trigger out to six cameras on the same principle. If the station must also archive images of failed codes, that is a vision reader with on-board image storage — the requirements change, not the wiring.

For a station you are specifying now, start the system configurator at the trigger step, or send the conveyor drawing through the contact page and we will size the reader, the loom and the timing together.

Questions

Can I use a small relay instead of an optocoupler?

Yes, for slow stations. A 5 V reed relay coil draws roughly 10–20 mA, within many logic pins' budget, and its contacts close the reader's input as a true dry contact. But it switches in about 1–5 ms, the coil needs a flyback diode, and contacts wear. The optocoupler stays the default: sub-millisecond switching, silent, and nothing to wear out.

Does the GPIO method need a vendor SDK on an ARM board?

No. The trigger is a contact closure and the data path is the reader's USB keyboard mode, so any operating system that exposes GPIO and reads HID input works — the script toggles a pin and receives plain text. Vendor SDKs matter only for binary serial protocols or for pulling the scan image off the reader.

How do I trigger two readers from one pin?

Wire one optocoupler per reader and put the LED branches in parallel on the logic side. Two couplers at 9.5 mA each draw 19 mA total, still inside a typical pin's few-tens-of-mA budget; each reader keeps its own isolated ground domain, so a fault on one loom cannot drag the other input down.

Why does my reader decode before I pulse the input?

That is a continuous sub-mode left on alongside the trigger input: some readers keep illumination or presentation behavior live between pulses. In the configuration tool, tie aiming and illumination to the trigger event too, or the optics read whatever passes the lens. It is a menu item, not a wiring fault.

Which trigger polarity do I need?

With your own optocoupler the question disappears: the transistor simply shorts the two input pins, and the pinout table tells you which pin is the positive one. Polarity only matters when a PLC transistor output drives the input directly — then match sinking (NPN) or sourcing (PNP) to the input's bias.