IR receiver to control some LEDs not working

Hello. I'm trying to build an array of LEDs that light up when i press some buttons with a remote. I was referring to mytectutor so that i can learn how it works. When I have connected in and run the code, there is a response ie. the RX led lights when i press the button on the remote but the LED itself doesnt light up. Anyone know why? (yes i pressed the correct button)

#include <IRremote.h>

int RECV_PIN = 11;
int led1 = 2;
int led2 = 3;
int led3 = 4;
int itsONled[] = {0,0,0,0};

#define code1 16724175 
#define code2 16718055 
#define code3 16743045 

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600); 
irrecv.enableIRIn(); 
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { 
digitalWrite(led1, LOW); 
itsONled[1] = 0; 
} else { 
digitalWrite(led1, HIGH); 
itsONled[1] = 1; 
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
}
Serial.println(value); // you can ommit this line
irrecv.resume(); 
}
}

thats the code and there's the fritzing diagram
image

I don't see a ground for the LEDs.

What version of the IRremote library do you have installed?

Hello
what is the logic for

?

Also, these pin assignments don’t appear to correspond with the “schematic”

An implementation of toggle for the leds ?

oop, sorry, i have changed that beforehand

yes, its an array that stores the state of the led

@groundFungus what do you mean?

i have added ground wire but no differnce...

If you remove say the yellow wire (based on the "schematic" in post #1) from the Arduino pin and connect that end instead to the +5v, does the led switch on ?

hey there, ive tried but the only thing that happens is the RX led lighting up

@6v6gt

That I can't explain.
Anyway, if you are having difficulty getting a LED to switch on by some direct means, then starting with an IR sketch is a bit ambitious.
I suggest then the blink sketch in the examples section in the Arduino main window (IDE).
You are aware that LEDs are polarity sensitive and cannot be reversed ?

I detest people who find nitpicky details to argue about, but as an electronics instructor, this drives me howling:

You are aware that LEDs are polarity sensitive and cannot be reversed ?

more accurately: they are polarity sensitive, and can only light up when wired in one direction. if they are wired up backwards they do nothing. no damage, but no illumination.

OK. I made the assumption, as I usually do, unless I see evidence to the contrary, that the OP is not a complete idiot and would not, therefore, require the additional elaboration you have suggested. I do, however, use repetition, in some form, as in this case, where it may benefit users whose first language may not be English. But, anyway, thank you for contribution to this thread.

Hi @sujenvonmusk ,
let's do a basic test;
Use the blink example and run to the 1st. LED of your project,
Then rotate to 2nd, then to 3rd.
This will make sure the LEDs are OK and turned on correctly.
Load your sketch .
Then inform what is printed on this line 58 " Serial.println(value);

RV mineirin

The result.value variable is defined as (see IRremote.h):

uint32_t value; ///< Decoded value / command [max 32-bits]
but you are stuffing it into the value variable which is declared as unsigned int (16 bits). So the results.value that you get from the remote is truncated (as the warnings show if compile warnings are enabled in File, Preferences).

Changing
unsigned int value = results.value;
To
unsigned long value = results.value;
Allows the code to compile without warnings. Try it.

Edit: FYI, I wired up an Uno with IR decoder to pin 11 and 3 LEDs to pins 2,3 and 4 and uploaded the code in the OP with only changing the codex values to match my remote and making the value variable unsigned long. Library version 2.80. I can toggle the state of each LED with the corresponding remote button.

If the code from the OP and with the correction from post #17 is compiled with the latest version of the IRremote library this warning will appear (if compile warnings are enabled).

C:\Users\DaD\Documents\Arduino\ir_3_led_toggle\ir_3_led_toggle.ino: In function 'void loop()':
C:\Users\DaD\Documents\Arduino\ir_3_led_toggle\ir_3_led_toggle.ino:28:30: warning: 'bool IRrecv::decode(decode_results*)' is deprecated: Please use IrReceiver.decode() without a parameter and IrReceiver.decodedIRData. . [-Wdeprecated-declarations]
if (irrecv.decode(&results))
^
In file included from C:\Users\DaD\Documents\Arduino\libraries\IRremote\src/IRremote.h:188:0,
from C:\Users\DaD\Documents\Arduino\ir_3_led_toggle\ir_3_led_toggle.ino:1:
C:\Users\DaD\Documents\Arduino\libraries\IRremote\src/IRReceive.cpp.h:1373:6: note: declared here

bool IRrecv::decode(decode_results *aResults) {

  ^~~~~~

The warning shows because the IRremote library was recently updated and older code (written for versions < 3.0) may not work right if compiled with the new library. See the IRremote library documentation to see how to make the code compatible with the new library. Or delete the newer version from the sketchbook\libraries folder and install an older (<3.0) version using the IDE library manager.

yep

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.