IR LED Brightness control

Active 2 days ago
Viewed 66 times

I’m using this circuit for my project, which I referred from https://www.sparkfun.com/news/1396.

enter image description here

enter image description here

I don’t really understand how current works in GPIO pins, so the question is: instead of connecting them to pin 4, 6, 7, can I connect them to pin 4, 6, 12? as I need control over the brightness of LED and it seems I can only do that through the PCM_CLK pin.


2 Answers



The OP’s board question can be narrowed downed to 5 smaller questions:

(1) What is the maximum current of the IR LED Ring?

(2) Which transistor should be used to PWM adjust the LED ring brightness?

(3) Which PWM signal should be used to control the transistor switch?

(4) Which Rpi GPIO pin should be used?

(5) How to write the python program?


Update 2019oct2401

(3) Now I need to find a PWM signal to drive the power MOSFET.

(2) I read Electronics Tutorials on power MOSFET and found it a good idea to use it as a PWM switch to control IR LED ring lamp.

power MOSFET

(1) I checked my 12V LED ring lamp and found the max current about 500mA. The lamp is a bit too weak. I am thinking of adding two more rings, white/yellow for day vision, another IR for night vision.

led ring current

/ to continue, …

npn switch

led pwm

I would suggest to quickly skim through the newbie tutorials to get a very rough idea of GPIO, PWM, and transistor switches: Refs 1 to 3 are particularly related to your IR LED circuit.

(1) Rpi GPIO baiscs

(2) Transistor operation basics

(3) PWM basics

The OP’s question can be summarized as below:

(a) How much current is needed from the GPIO pin to drive the NPN transistor switch which in turn drives the 13 IR LEDs?

(b) Which GPIO pins to do PWM to control brightness of the LEDs?

I will be using ordinary (around 450 nm) and IR (850/940nm) LED to do the basic calculations.

/ to continue, …


(1) [NPN] Transistor as a Switch – Electronics Tutorials

(2) NPN Transistor – Electronics Tutorials

(3) Electronics Tutorial 4 Transistor Tutorial – YouTube

(4) Using A Rpi GPIO PWM NPN Transistor Switch Controlled IR LED Ring Lamp For Rpi NoIR Camera Photography – SparkFun

(5) LED Strip Wiring, Current, And Battery Life Calculation – ee.stackexchange

(6) Flexible LED strip light basics – lednique

(7) [Power] MOSFET As A Switch – Electronics Tutorials

End of answer

deleted by goldilocks yesterday

Why was your post deleted? See the help center.


Yes you probably could. I’ve not heard of anyone controlling the brightness of infra red IRs before, but that might just be my ignorance.

However PWM signals can be generated on all the GPIO. The only advantage of using GPIO 18 (pin 12) is that like GPIOs 12, 13, and 19 it can be connected to the Pi’s hardware PWM peripheral.

See https://pinout.xyz/ for a diagram showing the mapping of GPIO to pins on the extension header.

As I say PWM can be generated on all GPIO.

My pigpio library has this feature. To generate PWM on GPIO 4 (pin 7) do

sudo pigpiod

pigs p 4 64 # 1/4 dutycycle
pigs p 4 128 # 1/2 dutycycle
pigs p 4 192 # 3/4 dutycycle
pigs p 4 255 # full on

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: