Universal IR Remote using Arduino

6v6gt:
This is extreme:

delay(1000) ; // crude de-bounce

You have not answered the question about the button pull down resistors and your problem appears to be one of floating pins.

Anyway, good is that it appears to work.

Forgot to mention the resistors. it's 1K pull down resistor

about that delay(1000), maybe cause the button when I press (my finger timing) could be the cause ? I don't know I am just glad it's working :slight_smile:
Thank you so much, I really owe you one.

hanynaeem:
One last thing, is there a possible way to add LEDs to mark the modes which one is selected?

Help Please

pinMode some pins (two should do it) as outputs and digitalWrite them inside each case as you need.

runaway_pancake:
pinMode some pins (two should do it) as outputs and digitalWrite them inside each case as you need.

I did that but didn’t work

#include <IRremote.h>

IRsend irsend;

const int b1  = 4;  //Power
const int b2  = 5;  //mode
int g  = 14;  //red
int r  = 15;  //Green

int timer;
int modeCounter = 0;
int modeChange = 0 ;   // global
const int NUMBEROFMODES = 1;


void wakeUp() {
  timer = 0;
}

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(r, OUTPUT);
  pinMode(g, OUTPUT);


}

void loop() {


    if (digitalRead(b2) == HIGH) {
    modeChange++; // increment
    if (modeChange > NUMBEROFMODES) modeChange = 0;
    delay(1000) ;  // crude de-bounce

    }

  if (digitalRead(b1) == HIGH) {
    timer = 0;
    delay(100);

    switch ( modeChange ) {

      case 0 : {
    digitalWrite(r, HIGH);
     irsend.sendNEC(0x20DFC03F, 32); //voldown LGTV
                timer = 0;
                delay(100);
          break ;
        }
        
      case 1 : {
   digitalWrite(g, HIGH);
         irsend.sendNEC(0x20DF40BF, 32); //volup LGTV
                timer = 0;
                delay(100);
          break ;
               }
    delay(1);
    timer = timer + 1; 
  }
 }
}

Any other suggestions?

Looks like you need to include, in each case, the state of (what is to be done with) both Red and Green.

runaway_pancake:
Looks like you need to include, in each case, the state of (what is to be done with) both Red and Green.

Can you give a code example?

You add the two lines here so it is always clear what the current mode is.
With your 2 leds, you can represent 0 through to 3.
Add another led and you could represent 0 through to 7.

if (digitalRead(b2) == HIGH) {
    modeChange++; // increment
    if (modeChange > NUMBEROFMODES) modeChange = 0;
    delay(1000) ;  // crude de-bounce
    digitalWrite ( r , modeChange & 2 ) ;  // new
    digitalWrite ( g , modeChange & 1 ) ;  // new
}

6v6gt:
You add the two lines here so it is always clear what the current mode is.
With your 2 leds, you can represent 0 through to 3.
Add another led and you could represent 0 through to 7.

if (digitalRead(b2) == HIGH) {

modeChange++; // increment
   if (modeChange > NUMBEROFMODES) modeChange = 0;
   delay(1000) ;  // crude de-bounce
   digitalWrite ( r , modeChange & 2 ) ;  // new
   digitalWrite ( g , modeChange & 1 ) ;  // new
}




I changed the idea to use the built in led to blink so would case 0 blinks once and keeps blinking, case 1 blinks twice and keeps blinking, so I wrote it like this but still not working.


#include <IRremote.h>

IRsend irsend;

const int b1  = 4;  //Power
const int b2  = 5;  //mode

int timer;
int modeCounter = 0;
int modeChange = 0 ;   // global
const int NUMBEROFMODES = 1;

void wakeUp() {
 timer = 0;
}

void setup() {
 Serial.begin(9600);
 pinMode(LED_BUILTIN, OUTPUT);
 pinMode(b1, INPUT);
 pinMode(b2, INPUT);

}

void loop() {

if (digitalRead(b2) == HIGH) {
   modeChange++; // increment
   if (modeChange > NUMBEROFMODES) modeChange = 0;
   delay(1000) ;  // crude de-bounce
   digitalWrite ( LED_BUILTIN , modeChange & 2 ) ;  // new
   digitalWrite ( LED_BUILTIN , modeChange & 1 ) ;  // new
   }

if (digitalRead(b1) == HIGH) {
   timer = 0;
   delay(100);

switch ( modeChange ) {

case 0 : {
   digitalWrite(LED_BUILTIN, HIGH);
   delay(100);
   // turn LED off:
   digitalWrite(LED_BUILTIN, LOW);
   delay(1000);
   irsend.sendNEC(0x20DFC03F, 32); //voldown LGTV
               timer = 0;
               delay(100);
         break ;
       }
       
     case 1 : {
   digitalWrite(LED_BUILTIN, HIGH);
   delay(100);
   // turn LED off:
   digitalWrite(LED_BUILTIN, LOW);
   delay(100);
   digitalWrite(LED_BUILTIN, HIGH);
   delay(100);
   digitalWrite(LED_BUILTIN, LOW);
   delay(100);
        irsend.sendNEC(0x20DF40BF, 32); //volup LGTV
               timer = 0;
               delay(100);
         break ;
              }
   delay(1);
   timer = timer + 1;
 }
}
}




Any suggestions?

Any suggestions ?

Ok. If you now want to use only a single built in led to represent up to your maximum number of modes, you have to specify a blink cycle which makes it clear to the user what the current mode is.

For example, if the current mode is 2, maybe 2 short pulses each 100ms with a space of 150 ms between, then a 2 second pause and repeat.

Incidentally, if you are running short of pins, a 16 button matrix can use only 8 pins. I've used one here also, incidentally, an IR remote control: https://forum.arduino.cc/index.php?topic=717762.0 (however, that is not a project for beginners)

6v6gt:

Any suggestions ?

Ok. If you now want to use only a single built in led to represent up to your maximum number of modes, you have to specify a blink cycle which makes it clear to the user what the current mode is.

For example, if the current mode is 2, maybe 2 short pulses each 100ms with a space of 150 ms between, then a 2 second pause and repeat.

Incidentally, if you are running short of pins, a 16 button matrix can use only 8 pins. I've used one here also, incidentally, an IR remote control: https://forum.arduino.cc/index.php?topic=717762.0 (however, that is not a project for beginners)

Woow, that's huge :slight_smile:
I just need a simple blinking modes :wink:

so in my case it's kinda difficult to achieve such a blinking routine?