void IRsend::sendNEC(unsigned long data, int nbits)
{
enableIROut(38);
mark(NEC_HDR_MARK);
space(NEC_HDR_SPACE);
for (int i = 0; i < nbits; i++) {
if (data & TOPBIT) {
mark(NEC_BIT_MARK);
space(NEC_ONE_SPACE);
}
else {
mark(NEC_BIT_MARK);
space(NEC_ZERO_SPACE);
}
data <<= 1;
}
mark(NEC_BIT_MARK);
space(0);
}
void IRsend::enableIROut(int khz) {
// Enables IR output. The khz value controls the modulation frequency in kilohertz.
// The IR output will be on pin 3 (OC2B).
// This routine is designed for 36-40KHz; if you use it for other values, it's up to you
// to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.)
// TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B
// controlling the duty cycle.
// There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A)
// To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin.
// A few hours staring at the ATmega documentation and this will all make sense.
// See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details.
// Disable the Timer2 Interrupt (which is used for receiving IR)
TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
pinMode(TIMER_PWM_PIN, OUTPUT);
digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
// COM2A = 00: disconnect OC2A
// COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
// WGM2 = 101: phase-correct PWM with OCRA as top
// CS2 = 000: no prescaling
// The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A.
TIMER_CONFIG_KHZ(khz);
}
I don't see anywhere in the code you included that would send any data to Serial, so I don't understand the "0" you're seeing. You should include the code that prints to Serial, or people won't know what the "0" means.
When you say "PIN 3 sends out "1" all the time", does that mean that you measure 5v on pin 3 or what?
Does the IR LED not light? And you know that you can't see an IR LED with your bare eyes? Can you replace the IR LED with a regular LED and check to see if it lights up?
Did you remember the 100 ohm resistor on the LED? Without that, you could mess up Pin 3.
Your send command says to send 32 bits, but only defines a 16 bit value.
I don't think he is sending anything to Serial, I think he is trying to use the serial input to monitor pin 3, which won't work for a variety of reasons.
Yeah Sorry about that I will try to make this post as right as I can.
#include <IRemoteInt.h> #include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
void loop() {
irsend.sendNEC(0x10EF, 32); // LG TV power code
delay(40);
}
With just this small code I try to see if the tv is working with the led.
What I meant with "0" and "1" is as you said, I was checking to see if my PIN 3 was able to send out data.
3.I replaced the IR LED with an regular LED on PIN 3 and it worked just fine. So PIN 3 is working just fine.
4.I connected the 100 ohm resistor as it was shown on one of his examples(Ken)
32 bit value? You mean irsend.sendNEC(0x10EF, 32)?...Should I change 0x10EF,32 to 0x10EF,16? I Believe I've done that in earlier tests, and it didn't work out, but I will do this. But I am wondering if I am using the right pin.. Cause in his lib he is defining alot of cards, meaning depending on the card(microcontroller) the OUTPUT PIN changes..In this library, I can't seem to find a
#define that specifies my microcontroller(Arduino UNO)
UPDATE: It seems that my IR LED is working(Checked trough my phone) but it still won't activate my TV. Not really sure why..cause in people say in other example that this is how you do it.
OK, so it sounds like the circuit is "working", just not the right code. Where did you get "irsend.sendNEC(0x10EF, 32)" for your TV. A friend of mine has an LG TV also (from your comment), and the code we got from IR Receive was completely different, although it was the NEC protocol. BTW, we never got it to work right.
IR LEDs take a lot of current. I added a transistor to mine. Or you probably need to make sure that you're close to the TV's receiver.
And looking at the code again, you're sending the code to the TV continuously. This may overwhelm the TV's input, cause you basically telling the TV to turn on and off many times a second. Try sending the command just once.
A friend of mine has an LG TV also (from your comment), and the code we got from IR Receive was completely different, although it was the NEC protocol. BTW, we never got it to work right.
I just checked an LG remote & it is the same as NEC, but with one important difference.
The first mark (Header or lead-in) is 4500 uSecs long vs 9000 uSecs long for the standard NEC protocol.
3 options:
Change the NEC header definition in the library from 9000 to 4500 uSecs
Use RAW mode to send the signals
Use the NECx protocol in the IRLib library, instead