Using IO pins to PWM IR Leds

Discussion related to "under the hood" OpenMV topics.
Posts: 1
Joined: Thu Nov 01, 2018 12:58 pm

Using IO pins to PWM IR Leds

Postby maybites » Thu Nov 01, 2018 1:12 pm


For my project I try to create a finger tracking solution, where IR leds attached to a Plexi-screen highlights the finger and the position is tracked by the camera. In our first solution we used a webcam for this purpose: ( in the next iteration we would like to us openMV, and first tests already look promising, but the IR Leds get very hot if we keep them running continuously.

So I thought it would be a good idea to sync them with the image capture frequency, but while it is clear to me how to control an IO pin to drive a relay or a transistor, its not clear how my python code should look like in order to make this work. My naive idea in pseudo code:

Switch on LED
capture image
Switch off LED

any suggestions are welcome.


User avatar
Posts: 595
Joined: Sun May 24, 2015 3:53 pm

Re: Using IO pins to PWM IR Leds

Postby iabdalkader » Thu Nov 01, 2018 6:15 pm

Hi, your code will work, but the LEDs will be on a long time before the frame actually starts. Try this instead, this will sync the LED pin to the frame start interrupt:

Code: Select all

import sensor, image
from pyb import Pin

sensor.skip_frames(time = 2000)

ir_led_pin = Pin('LED_IR', Pin.OUT_PP, Pin.PULL_NONE)

    img = sensor.snapshot()

Interesting project, please keep us updated on your progress.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests