LightingHow-to

Adding an IR LED and I2C proximity sensor to an embedded camera board

Wire an I2C proximity sensor and a PWM-driven IR LED to an embedded camera board: which connector carries what, the series resistor maths and the checks.

LumaSpec Vision10 min read Share on LinkedIn

On this page 11 sections
  1. 01Which connector carries what
  2. 02What you need
  3. 03Choose the wavelength and aim the beam
  4. 04Size the series resistor
  5. 05Direct drive or transistor: the 8 mA line
  6. 06Wire the I2C sensor
  7. 07Wire it in this order
  8. 08Verify it worked
  9. 09Common mistakes
  10. 10When a discrete LED is not enough
  11. 11Questions

You have an embedded camera module on a carrier board and you want it to sense a part approaching and light it with infrared — without adding a whole second controller. The board already carries what you need: an I2C connector for the sensor and spare GPIO on the main connector for the LED. This guide gives you the pin decision, the series-resistor arithmetic, the 8 mA rule that separates direct drive from a transistor stage, and the checks that catch the two failures that actually happen: an IR-cut filter blocking your own light, and the LED wired to a pin the camera link owns.

Which connector carries what

The I2C connector is a bus header, not a general-purpose port. It brings out SDA, SCL, 3.3 V and ground — often a fifth pin for an interrupt — and nothing else. Put the proximity sensor there and leave it there: it is a milliamp-class load and the bus is its only interface.

The LED needs a PWM-capable GPIO, and those pins live on the module's main board-to-board connector. On a vision-equipped carrier a few of them are given to the camera link; the rest break out to headers or test points per the carrier's pinout. You need one PWM pin for the LED and, for frame-synced strobing, one strobe or frame-start output from the camera side. That split — sensor on I2C, LED on PWM GPIO — is the whole design. Everything after it is values and wire.

What you need

  • An embedded camera module on a carrier that breaks out at least one PWM GPIO, plus the camera's strobe output if you will sync pulses to the frame.
  • An I2C proximity and ambient-light sensor breakout, 3.3 V logic; many carry an onboard regulator and accept a 3–5 V supply.
  • One 850 nm or 940 nm LED with a stated viewing angle: 20° for a spot, 60° for a flood.
  • A series resistor and, for 20 mA drive, a logic-level N-channel MOSFET (or an NPN with a 1 kΩ base resistor).
  • A bus-scan tool on the host and a phone camera for the glow checks.

Choose the wavelength and aim the beam

Pick 940 nm when the LED must be invisible — it is, completely — and 850 nm when you want the higher radiant intensity per milliamp and can live with a faint red glow in the dark. Silicon sensors respond to both; sensitivity falls off gradually toward 1000 nm, so a mono board-level camera sees either without special parts.

The filter trap is the plan-killer on colour modules: an IR-cut filter over the sensor rejects exactly the band you emit. Mono board-level modules are sold without one. The IR projector and IR-cut filter guide shows what that filter does to an illumination plan; the short version is buy mono for IR work. If the module choice is still open, the board camera selection guide covers the sensor, shutter and mount trade-offs first.

Aim with the viewing angle, not hope: spot diameter is 2 × distance × tan(angle/2). At 200 mm a 60° LED floods about 230 mm; a 20° LED puts a 70 mm working spot on the same plane. Then check the glow with a phone camera — the fastest test there is for a board-level IR illuminator, and the board illuminator phone-camera test walks it.

Both sample modules below carry global shutters, which makes frame-synced pulses trivial to time:

Board-level camerasHikrobot MV-CB016-10GM-M-W 1.6 MP GigE board-level camera, IMX296, Mono, M12 lens mount, WTB GigE portMV-CB016-10GM-M-W
Sensor format
1/2.9"
Lens mount
M12
$559.00View part
Board-level cameras3.1 MP USB3 board-level camera, IMX252, 1/1.8" global shutter, 120 fps (LS-BCM-0003)LS-BCM-0003
Sensor format
1/1.8"
Lens mount
C-mount
$690.00View part

The M12-mount GigE board camera suits tight spaces beside the LED; the 120 fps C-mount USB3 module leaves room for a proper lens around your illumination.

Size the series resistor

R = (V_supply − V_f) / I_LED P = I_LED² × R

Forward voltage for 850–940 nm parts sits around 1.2–1.6 V at working current. For the maths, take the lowest Vf you might meet — it gives the highest current.

Round to the nearest E24 value and let the current land 5–10% low. LEDs vary more than that between batches.

Direct drive or transistor: the 8 mA line

Treat 8 mA as the continuous design figure for an ordinary microcontroller pin. Families differ, and a high-drive pin may allow 20 mA, but the per-pin and port-total ratings decide. At 8 mA the resistor maths gives (3.3 − 1.2) / 0.008 = 262 Ω, so 270 Ω lands at 7.8 mA — enough for a near-field fill inside about 100 mm, and for nothing more.

Working illumination at 20 mA goes through a transistor. Logic-level N-MOSFET: gate to the PWM pin, source to ground, and the LED with its series resistor from any rail — 3.3 V, 5 V or up to 12 V — to the drain. The pin now switches instead of sourcing, so the rail supplies the current and the pin's budget stays untouched. Prefer an NPN: base through 1 kΩ gives (3.3 − 0.7) / 1 kΩ = 2.6 mA of base drive, ample for 20 mA at a gain of 100.

Strobe to kill ambient and cut average power. Gate the same pin from the camera module's frame-strobe output through the transistor — the camera GPIO wiring guide covers the protection and fault triage that line deserves — and time the pulse to the exposure window as the camera and emitter synchronisation guide lays out. The duty arithmetic: a 1 ms pulse at 60 fps is 6% duty, so a 50 mA pulse averages 50 mA × 0.06 = 3 mA thermally while delivering 2.5× the continuous intensity. Past a few times continuous the LED's pulse rating governs, and the LED overdrive and current-control guide shows how to hold the current stable there.

Wire the I2C sensor

Four wires: VDD to the connector's 3.3 V pin — this class of sensor is 3.3 V logic, and breakouts with an onboard regulator accept 3–5 V if your rail differs — GND to board ground, SDA and SCL to the connector. Most breakouts carry their own pull-ups, and with them the bus is comfortable at roughly 1 m of cable at 100–400 kHz. A sensor of this class draws a few milliamps, so the connector's supply pin handles it without a second rail.

Scan the bus before your application code runs. A healthy rig answers with the sensor's fixed 7-bit address; an empty scan means wiring, and a NACK mid-scan means an address clash with something already on the bus. When the probe still fails on a wired bus, the I2C communication failure guide walks the physical-link checks in order.

Wire it in this order

  1. Power everything down. Sensor VDD, GND, SDA and SCL to the I2C connector, one wire at a time.
  2. Build the LED branch on the header: rail to 110 Ω to LED anode, LED cathode to MOSFET drain, MOSFET source to ground, gate to the PWM pin.
  3. Tie every ground together — sensor, carrier and LED rail. A floating ground leaves the gate without a return and the LED stuck off or half on.
  4. Power up and scan the bus; the sensor's address should appear.
  5. Run 1 kHz at 50% duty from a PWM test and look with a phone camera: 850 nm shows a faint red-violet dot, 940 nm barely anything.
  6. Read the proximity register while you wave a hand 100–200 mm away; the value should step clearly.
  7. Move to strobed drive: feed the gate from the camera's strobe output, 1 ms per frame at 60 fps to start.
  8. If you moved the LED to a 5 V or 12 V rail, resize the series resistor with the same formula before the first pulse.

Verify it worked

Three observations close the job. The bus scan shows one device at the sensor's address. The PWM bench test lights the LED — seen directly on a phone camera at 850 nm, or inferred at 940 nm from the proximity reading dipping when you cover and uncover the LED. And a strobed frame at a 1 ms exposure shows the scene lit by your LED alone, ambient suppressed, which is the whole point of the transistor stage.

If the frames stay dark while the LED obviously glows, point the phone camera at the module and re-read the IR-cut filter guide with your module in hand: a colour sensor behind that filter is the cause, and the fix is a mono module.

Common mistakes

  • A colour module over IR. The IR-cut filter rejects your emission band; mono modules are the ones sold without it.
  • Expecting GPIO from the I2C connector. It carries SDA, SCL and supply; PWM pins come off the main connector only.
  • Sourcing 20 mA from the pin. It eats the port's total-current budget and sags the rail; the transistor exists for this.
  • PWM under a rolling shutter. The duty changes line by line and bands the frame. Run steady current for rolling-shutter modules and save pulses for global shutters.
  • A second rail without a common ground. The MOSFET's gate-source loop must close through the carrier's ground.
  • Trusting nominal beam angles at close range. The 230 mm flood at 200 mm spills onto background surfaces and lifts your background level; stop it with a 20° LED or a small shield.

When a discrete LED is not enough

Past roughly 300 mm of working distance or a field wider than about 250 mm, a resistor-fed LED stops being illumination and becomes a glint. Move up to a purpose-built light with constant-current drive and a real optic, and keep the same wiring habit: the light's trigger or dimming input takes the place of the MOSFET gate, and the strobe output from the camera still times it.

The strobe light below runs from 48 V and measures 84 x 60 x 60 mm:

Special lightsHigh power strobe light, 84 x 60 x 60 mm (LS-SPC-0129)LS-SPC-0129
Size
50-100 mm
Voltage
48 V
Type
Strobe
$759.00View partBuild a system with it

Browse the special lights for strobe, structured and custom-built options and the board-level cameras for modules that mount beside them, or filter by mount, size and voltage in the camera finder and the light finder. The light step of the configurator pairs a light with its controller and your camera in one pass. For the rest of the lighting technique, the lighting topic page collects it, and the contact page reaches the applications team when a build needs a second opinion.

Questions

Can I power the IR LED from the I2C connector's supply pin?

No. That 3.3 V pin exists to feed the bus and its sensor, and a proximity sensor of this class draws only a few milliamps. A 20 mA LED is a different kind of load and will pull the rail around. Run the LED from the main 3.3 V, 5 V or 12 V rail through the transistor stage, and keep only the sensor on the connector.

Can I hang a small microcontroller on the I2C bus to drive the LED instead?

Yes. Any I2C-capable MCU can sit on the bus as a slave, powered from the same 3.3 V pin, and drive the LED with its own PWM pins; one byte over the bus then sets brightness or strobe mode. For a single LED it is more parts than the job needs — a transistor does the same switching for a fraction of the board area.

How far can the sensor and LED sit from the carrier?

The I2C bus is comfortable at roughly 1 m of cable at 100–400 kHz when the pull-ups are on the breakout. Keep the LED loop short, under about 100 mm, and route it with its ground. The gate or strobe line is a clock, not a power line — tens of centimetres is fine, but keep it away from the LED anode wiring so pulses do not couple into the bus.

Can I pulse the LED above its continuous current rating?

Yes, within two limits: the LED's peak pulse current at your pulse width, and the thermal average, which must stay at or below the continuous rating. The 1 ms pulse at 60 fps in the guide is 6% duty, so a 50 mA pulse averages 3 mA. Past a few times continuous, the current-control practices in the overdrive guide become necessary rather than optional.

Does the proximity sensor interfere with the camera's own control bus?

Not if it stays on the connector. The I2C connector reaches the host's own peripheral bus; the camera module's sensor control runs on separate lines inside the module. Never splice the breakout onto the module's internal lines. A bus scan at power-up proves the separation: you see exactly one device, the proximity sensor, at its fixed 7-bit address.