Hey Everyone,
I need some help with my project. All I need to do is have one Arduino Uno transmit an IR signal and then another Arduino Uno receive that code and then cause an LED to turn on for 2 seconds. (my full project is much much larger but this is the part that I'm having an issue with.)
My IR transmitter circuit transmits the correct NEC value that I want it to because the LED lights up. The issue is that the light keeps blinking even when nothing is being transmitted. This is very perplexing to me because when I use Sparkfun's IR Remote: shttps://www.sparkfun.com/products/11759 from the IR Control Kit: https://www.sparkfun.com/products/11761, the LED turns on for 2 seconds and then turns off like it is supposed to.
Here is my code for the IR Transmitter. It is essentially straight from the sparkfun code but tweaked to work to my needs:
#include <IRremote.h> // Include the IRremote library
IRsend irsend; // Enables IR transmit on pin 3
const int buttonPin = 12; // Button pin. Pulled up. Triggered when connected to ground.
// setup() initializes serial and the Infrared receiver.
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
}
// loop() checks for either a button press or a received IR code.
void loop()
{
// If the button is pressed, and we've received a code...
if (digitalRead(buttonPin) == LOW)
{
sendCode(); // Sends out our code. (See bottom of sketch).
delay(1000);
}
}
void sendCode()
{
irsend.sendNEC(0x10EFD827, 32);
Serial.println("Sent NEC Power");
}
Here is my code for the IR Receiver:
#include <IRremote.h>
int IRpin = 11; // pin for the IR sensor
int LEDb = 12; // blue LED pin
int LEDg = 8; // green LED pin
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(LEDb, OUTPUT);
pinMode(LEDg, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
}
if (results.value == 0x10EFD827) // NEC value to be recieved (Power Button)
{
digitalWrite(LEDb, HIGH);
delay(2000); // wait 1 second
digitalWrite(LEDb, LOW);
delay(100); // keeps the transistion smooth
}
if (results.value == 0x10EFF807) // NEC value to be recieved (A Button)
{
digitalWrite(LEDg, HIGH);
delay(2000); // wait 1 second
digitalWrite(LEDg, LOW);
delay(100); // keeps the transistion smooth
}
else
{
Serial.println("done");
}
}
Any help would be greatly appreciated!