control the power output of a IR LED

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Hi guys

What are the options available to control the power output in software of a 38KHz IR LED that sending some codes (NEC code etc...) . Here are what I can come up with:
  • PWM the 38KHz (will that work?)
  • Using a programming able current source/sink?
  • or simply switch in and out different resistor values?
Here are what I want to achieve:
  • The reason I want to do that is so I can control the range (roughly) of the IR signal.
  • There is a 38KHz IR receiver at the other end.
  • Planing to use NEC code (only because that's the one I am familiar with), but better coding is welcome
  • only 4 bytes of data
Capture.PNG
 

dendad

Joined Feb 20, 2016
4,451
That will work fine. I use an FET in place of the transistor but either is ok.
Adjust R1 to set the D1 current to below the max.
R=E/I and E = (Vcc-D1volts). D1Volts will be about 2V.
Then just generate the 38KHz pulse train to drive the transistor.
At the moment, I'm building a laser tag system for my son.
LasertagProto2.jpg

And you don't need different current values, just on and off.
But if you want to alter the power, there are a few ways to do that. How many steps of power are you after?
 
Last edited:

dendad

Joined Feb 20, 2016
4,451
Here is a quick scribble of just one idea..
LED_PowerControl.jpg
For a start, ignore P1 and P2.
When the on/off is LOW, no current flows.
When it it HIGH, for example, 5V, then then transistor will have 5V-about 0.7V on the emitter. So the current for the LED can be set by R1.
Next, 5V to the on/off pin, and 0V on P1 (set P2 as an input) so the base will be at a lower voltage set by the resistive divider on the transistor input so the emitter volts will be lower and therefore the LED current.
By selecting the 3 base resistors (or more if you need them) you can control the LED current with a crude D to A.
The Px pins are either set LOW or as inputs. Not HIGH, so then you only have to drive one pin as the on/off.
 

dendad

Joined Feb 20, 2016
4,451
I am basing it on an open source Arduino Lasertag system but modifying it.
In stead of beeps, it has a sound module , WT588D, mounted on the Arduino mini.
Sound.jpg

The optics are a mix of high powered flashlight bits, a cell phone telescope and 3D printed parts. The LED is a high powered IR one that came mounted on an aluminum disk. All powered by a recycled Li-Ion cell from an old laptop battery and an Ebay charge/discharge controller board.

It is a work in progress but it looking very good so far. The Nerf guns make a good base for it all.

Here is the code header that tells all (almost) ;)
* Giving Credit where Credit Is Due
*
* Portions of this code were derived from code posted in the Arduino forums by Paul Malmsten.
* You can find the original thread here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434
*
* The Audio portion of the code was derived from the Melody tutorial on the Arduino wiki
* You can find the original tutorial here: http://arduino.cc/en/Tutorial/Melody


https://github.com/ojh31/duinotag
 

be80be

Joined Jul 5, 2008
2,072
I can see the idea there in post #4 but that would mess with the turn on time too to toggle a IR you want fast on and off timing.
 

dendad

Joined Feb 20, 2016
4,451
I just breadboarded the circuit and it works ok.
You will have to fiddle the resistor values to your liking.

This is the Arduino code just tossed together.


// PWM_PowerTest2
// This sketch sends a raw signal using the PWM sender every 1 seconds.
// It requires an IR-Led connected to the sending pin
// (3 on Uno/Nano, 9 on Leonardo/Uno, 9 on Mega2560 etc...)

#include <IrSenderPwm.h>

static const frequency_t necFrequency = 38400U;

// NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
static const microseconds_t array[] = {
9024, 4512, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692,
564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 1692,
564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564,
564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564,
564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 1692, 564,
1692, 564, 1692, 564, 39756
};

static const IrSequence irSequence(array, sizeof(array) / sizeof(microseconds_t));

void setup() {
pinMode ( 3,OUTPUT); // the PWM signal as it is a Uno I'm using.
pinMode (10,OUTPUT); // the current Set 1
pinMode (11,OUTPUT); // the current Set 2
digitalWrite( 3,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}

void loop() {
IrSenderPwm::getInstance(true)->send(irSequence, necFrequency);
delay(1000);
pinMode(10,INPUT);
pinMode(11,INPUT);
IrSenderPwm::getInstance(true)->send(irSequence, necFrequency);
delay(1000);
pinMode(10,OUTPUT);
pinMode(11,INPUT);
IrSenderPwm::getInstance(true)->send(irSequence, necFrequency);
delay(1000);
pinMode(10,INPUT);
pinMode(11,OUTPUT);
IrSenderPwm::getInstance(true)->send(irSequence, necFrequency);
delay(1000);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
IrSenderPwm::getInstance(true)->send(irSequence, necFrequency);
delay(1000);
}

IR-PowerTest.JPG
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
I was just looking at it the resistor need be high value figured it mess up timing there better way to do this and have way more control
of the IR power output after all you using a uC.
 

be80be

Joined Jul 5, 2008
2,072
Sensacell You kind of took my ideal all but one thing id use two pins one for 37khZ and one id put a cap on and pwm to feed control voltage.
 

MrAl

Joined Jun 17, 2014
11,389
Hi,

What kind of control do you need?
If you can use a DC signal then it is easy.
If you cant, then you probably need extra i/o pins.
Another option is to try using a second PWM to create DC from which you can use as the control signal.

The idea with the transistor might work better with some feedback to take the Beta out of the equation.

I was also thinking very high frequency PWM, but that might be hard to do with a standard uC chip and do everything else too.
 

be80be

Joined Jul 5, 2008
2,072
MrAl your in the same boat the Attiny 85 is a fast little chip Two PWM Channels

Peripheral Features – 8-bit Timer/Counter with Prescaler and Two PWM Channels – 8-bit High Speed Timer/Counter with Separate Prescaler • 2 High Frequency PWM Outputs with Separate Output Compare Registers • Programmable Dead Time Generator – USI – Universal Serial Interface with Start Condition Detector
 

Sensacell

Joined Jun 19, 2012
3,432
Another option is to try using a second PWM to create DC from which you can use as the control signal.
The idea with the transistor might work better with some feedback to take the Beta out of the equation.
As long as the impedance of the control voltage source is low, the beta is not a factor.
Beta just needs to be high enough so the control voltage is not loaded too much. It's a classic current sink circuit.
 

MrAl

Joined Jun 17, 2014
11,389
MrAl your in the same boat the Attiny 85 is a fast little chip Two PWM Channels
Hi,

Well i am not sure which PWM you are talking about there.
I was talking about two very different types, one high speed like 380kHz or higher like 760kHz, and another the more standard 5kHz or something.
 

MrAl

Joined Jun 17, 2014
11,389
As long as the impedance of the control voltage source is low, the beta is not a factor.
Beta just needs to be high enough so the control voltage is not loaded too much. It's a classic current sink circuit.
Hi,

Yes i was talking about the transistor circuit with the three base resistors.
For that one change in beta may make a difference.
 

be80be

Joined Jul 5, 2008
2,072
Well he's doing 38khz
There 2 on the tiny85 and both are independent and one can run 38 while one runs fast up to 1mhz I think is easy done
 

MrAl

Joined Jun 17, 2014
11,389
Well he's doing 38khz
There 2 on the tiny85 and both are independent and one can run 38 while one runs fast up to 1mhz I think is easy done
Hi,

That sounds like it might work then. I was suggesting that he might high frequency PWM the low frequency PWM and thus vary the low PWM power. If the applications detector doesnt mind the fast PWM, it will only see the slow PWM.

I've worked with the Tiny in the past but it was quite some time ago.
 

be80be

Joined Jul 5, 2008
2,072
MrAl I should of looked at code he's using arduino code He would have to set pwm up with asm or use C without the core
to get full speed.
 
Top