Pages: [1]   Go Down
Author Topic: 38khz IR LED  (Read 1757 times)
0 Members and 1 Guest are viewing this topic.
Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31472
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31472
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:
/* 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
    pulse++;
  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(){
  setIrModOutput();
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
}

void loop(){
// do something here
}

Logged

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31472
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: