Hello, I have been working on a remote for a rover I built, and I decided to do this with IR. I built a test program, actually two, one for the Arduino with the transmitter, and one with the receiver. The goal was to have three LEDs on the breadboard with the receiver, each connected to a digital pin, and when the receiver got the HEX code F10001, it would light up the first LED, and if it got the code F10002, it would light up the second LED, etc... So this works, but here is the problem. When I power both the Arduinos ON, and press the first button on the transmitter that sent the code to light up LED 2. LED two would light up, but even after the momentary push button was released, it would stay on. Then if I pressed the button two light up LED 1, nothing would happen, LED 2 would remain lit. So essentially, whichever LED lights up first, stays on until you reset the program. My goal is to not have to reset the arduino each time I send it a new command. I am using the IRremote library made by Ken Shirriff (A Multi-Protocol Infrared Remote Library for the Arduino) I will attach the pictures of both setups and the code for each!
Any help will be greatly appreciated, as I am now frustrated and have no idea where the problem lies.
Code for the Receiver with the 3 LEDs:
#include <IRremote.h>
int RECV_PIN = 9;
int ld1 = 7;
int ld2 = 4;
int ld3 = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(ld1, OUTPUT);
pinMode(ld2, OUTPUT);
pinMode(ld3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
}
if(results.value == 0xF10003){
digitalWrite(ld1, LOW);
digitalWrite(ld2, LOW);
digitalWrite(ld3, HIGH);
irrecv.resume();
}
if(results.value == 0xF10002){
digitalWrite(ld1, LOW);
digitalWrite(ld2, HIGH);
digitalWrite(ld3, LOW);
irrecv.resume();
}
if(results.value == 0xF10001){
digitalWrite(ld1, HIGH);
digitalWrite(ld2, LOW);
digitalWrite(ld3, LOW);
irrecv.resume();
}
}
Code for the transmitter with the IR led and the buttons:
#include <IRremote.h>
IRsend irsend;
void setup()
{
pinMode(INPUT, 5);
pinMode(INPUT, 8);
pinMode(INPUT, 12);
}
void loop() {
digitalRead(5);
digitalRead(8);
digitalRead(12);
int b1 = digitalRead(5);
int b2 = digitalRead(8);
int b3 = digitalRead(12);
if(b1 == HIGH){
irsend.sendNEC(0xF10001, 32); // Send Function 1; Subset 1; 32 bits
delay(10);
}if(b2 == HIGH){
irsend.sendNEC(0xF10002, 32); // Send Function 1; Subset 2; 32 bits
delay(10);
}if(b3 == HIGH){
irsend.sendNEC(0xF10003, 32); // Send Function 1; Subset 3; 32 bits
delay(10);
}
}
Pic of the receiver:
Pic of transmitter:
Thank you great interweb wizards!