Go Down

Topic: 38khz IR LED (Read 4313 times) previous topic - next topic


I need to pulse a IR led with 38 khz. I thought it would be very easy. It's been a bit tricky. My question is their a standard method/chip circuit arrangement for this? I've been using a 555 it seems ok. I'd like to have maybe an arduino that sweeps from 18khz to 40khz and lets me control the duty cycle would that be doable using interupts so i could right info to the serial  monitor at  the same time?


What is this planned for ... appears to be for an IR remote? If so then the IRremote library for Arduino has everything you need. If not you could likely modify some of the code from the library to do what you want.


Are you sure you want to control the duty cycle? This is normally set at 50% for an IR remote. What you control is the number of pulses on and off.


Wouldn't it be much simpler to use a module like this? Becasue even once you have the led pulsing at the correct rate, you still (presumably) need to superimpose your signal over that.

@rickso234, I didn't realise the IRremote library was for transmitting IR, I've only ever used it to decode received pulses by an IR sensor from a TV remote.


Wouldn't it be much simpler to use a module like this?

No that is just a LED there is no driver and no modulator.
One way to modulate it is with a software routine like this:-
Code: [Select]
/* Code to pulse pin 3 with a modulated signal
* Can be used to drive an IR LED to keep a TSOP IR reciever happy
* This allows you to use a modulated reciever and a continious beam detector
* By Mike Cook Nov 2011 - Released under the Open Source licence
volatile byte pulse = 0;

ISR(TIMER2_COMPB_vect){  // Interrupt service routine to pulse the modulated pin 3
  if(pulse >= 8) { // change number for number of modulation cycles in a pulse
    pulse =0;
    TCCR2A ^= _BV(COM2B1); // toggle pin 3 enable, turning the pin on and off

void setIrModOutput(){  // sets pin 3 going at the IR modulation rate
  pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
  OCR2B = 26;  // deines the duty cycle - Half the OCR2A value for 50%
  TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock

void setup(){
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable

void loop(){
// do something here


No that is just a LED there is no driver and no modulator.

It says it delivers a 38kHz signal..... otherwise wouldn't they just call it an LED? But whatever, that was just the first on Google found for me, so even if it is just an LED, I'm pretty sure there must be some that do the trick.

But that said, if it's easy enough to do it in code as your sample suggests, then that's the way to go.


Thanks Mike/Jimboz. Mike i was thinking might want to control it because i will potentially have 64 IR led's and i was thinking about the power consumption and sensitivity calibration of my sensors (proximity). Getting the right frequency is more important for now though.
Jimboz i like that if it really foes give 38khz i will have a closer look.
Mike that code looks good as well i'll have a look. After posting the  original comment i had a go using a timerone library. After reading a web post on another board about using timerone i set it up like they said (26 micro seconds). Strangely this gives 19.4khz. Whats more odd is when i did get it working with the 555 that was at 19.4khz as well. I'm going to do some more experiments today.
Thanks for the input guys cheers.


THe IRremote library is quite useful (although I've yet to use it myself). It can read IR pulse streams from something like an TV remote and can also transmit IR pulses in several of the standard protocols. You pass the pattern to a function and it handles everything else, giving you a modulated signal on a digital pin that you can connect to an IR transmitting LED.


Strangely this gives 19.4khz. Whats more odd is when i did get it working with the 555 that was at 19.4khz as well

Yes it will. To get 38KHz you have to go up and down in 26uS, if you just set a period of 26uS then that gives you 19.4KHz.
So that is a high period of 12uS and a low period of the same giving a total period of 26uS or 38KHz.


Yes i figured out what was happening eventually. Since moved to the code you posted it works great thanks. I have figured out what does what just need to pick through it might as well use this to learn about timers. Cheers.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131