Repeating (Looping) in Ir remote

Hello
I am making an Led strip type Led I am using an IR Remote to control it .

Now, what is happening I have written function the code which I have written in void loop to repeat the function is written as under -

delay(1000);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
  delay(1000);
digitalWrite(YELLOW,LOW);
  digitalWrite(BLUE,HIGH);

  delay(1000);
digitalWrite(BLUE,LOW);

So now what is happening my code is just running only one time and it is not looping

Pls help
Thx in advance

I am writing my Full code here

#include <IRremote.h>
int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int RED = 5;
const int YELLOW = 6;
const int BLUE = 7;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
  pinMode(RED,OUTPUT);
pinMode(YELLOW,OUTPUT);
pinMode(BLUE,OUTPUT);
  }




void loop()
{
if (irrecv.decode(&results))
{
switch (results.value)
{
  
  
  
  
  case 0xFD00FF :
digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);
  Serial.println("ALL LED OFF");
  break;
 
  case 0xFD08F7:
digitalWrite(RED,HIGH);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);
  Serial.println("RED ON");
  break;
  
  case 0xFD8877 :
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
digitalWrite(BLUE,LOW);
 Serial.println("YELLOW ON");
  break;
 
  
  case 0xFD48B7 :
digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,HIGH);
  Serial.println("BLUE ON");
  break;
  
 case 0xFD28D7 :
digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);

  
  digitalWrite(RED,HIGH);
    delay(1000);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
  delay(1000);
digitalWrite(YELLOW,LOW);
  digitalWrite(BLUE,HIGH);

  delay(1000);
digitalWrite(BLUE,LOW);

  Serial.println("BLINKING FASTLY 1 SEC");
  break;
  
  
 case 0xFDA857  :
digitalWrite(RED,HIGH);
    delay(3000);
digitalWrite(RED,LOW);
    delay(3000);
digitalWrite(YELLOW,HIGH);
    delay(3000);
digitalWrite(YELLOW,LOW);
    delay(3000);
  digitalWrite(BLUE,HIGH);
    delay(3000);
digitalWrite(BLUE,LOW);
    delay(3000);

  Serial.println("BLINKING FASTLY 3 SEC");
  break;
 
  
  
 case 0xFD6897   :
digitalWrite(RED,HIGH);
    delay(5000);
digitalWrite(RED,LOW);
    delay(5000);
digitalWrite(YELLOW,HIGH);
    delay(5000);
digitalWrite(YELLOW,LOW);
    delay(5000);
  digitalWrite(BLUE,HIGH);
    delay(5000);
digitalWrite(BLUE,LOW);
    delay(5000);

  Serial.println("BLINKING FASTLY 5 SEC");
  break;
 
 case 0xFD18E7    :
digitalWrite(RED,HIGH);
    digitalWrite(YELLOW,HIGH);

digitalWrite(BLUE,HIGH);
    Serial.println("ALL ON ");
  break;

  
  default:
Serial.print("Undefined code received: 0x");
Serial.println(results.value, HEX);
break;
}
irrecv.resume();
}
}
  

Pls help

I assume that you are holding down the button on the IR Remote and expecting the code for that case to be repeated. However, it is common for IR Remotes to send a code only once when a button is pressed and if it is held down to continuously transmit a different code

Try printing the value received before testing it in the switch/case to see what is actually being received

No Currently I am doing this project on Tinkercad there this problem occur.

And I have only press button one time

Can you pls tell my mistake in my code or any solution for this problem any Special Code???

Get back to us when you're working in the real world.

The fact that you are using Tinkercad does not prevent you doing what I suggested

Ok I understand, Can you pls tell me that is my code is correct for Looping after pressing button Will my code will repeat or Not can you pls tell me that.:disappointed:

I'd take the delays out - they're going to affect responsiveness.

If you press the button once and don't hold it down then it will not loop because a new code will not be received

If you press the button and hold it down then it is very likely that a different code will be transmitted whilst the button is held down

Either way, print results.value to see what is going on

Thankyou I got it means it is the problem of Tinkercad and if I will done it practical then it will repeat correct

I don't know whether it is a Tinkercad problem. What I am describing is what happens in the real World

Try printing the value as suggested before posting again

OK I will do it

Try to use if instead of case.

Care to explain that particular train of thought?

That will not solve the fundamental problems

Really I don't know what happened in my code when I used the Case statement, but when I changed to If I got better result.
I think have to do with the size of data ( case statement support char and int while if support byte, char, int, long... You name it.

Not so. All that is needed is that the value used can be converted to an integral value

Please post your revised sketch

Hi
As you all said me to do the project in real world our practically. I have done that, but now the same issue occur when I am pressing IR Remote button the program starts working but it only loop 1 time not again and again looping my code is

#include <IRremote.h>
#include<LiquidCrystal.h>
int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int RED = 5;
const int YELLOW = 6;
const int BLUE = 7;
int counter;
LiquidCrystal lcd(11, 10, 4, 3, 2, 8);

int Random = 0;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
lcd.begin(16, 2);
  pinMode(RED,OUTPUT);
pinMode(YELLOW,OUTPUT);
pinMode(BLUE,OUTPUT);
  lcd.begin(16,2);
  lcd.print("Starting System");
    delay(1500);
    lcd.clear();
    lcd.print("System On");
    delay(2500);  
  lcd.clear();
  }




void loop()
{
if (irrecv.decode(&results))
{
switch (results.value)
{
  
  
  
  
  case 0xFD00FF :
lcd.setCursor(0,0);
  lcd.print("All of");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);
  Serial.println("ALL LED OFF");
  break;
 
  case 0xFD08F7:
  
digitalWrite(RED,HIGH);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);
  Serial.println("RED ON");
  break;
  
  case 0xFD8877 :
lcd.setCursor(0,0);
  lcd.print("Yellow On");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
digitalWrite(BLUE,LOW);
 Serial.println("YELLOW ON");
  break;
 
  
  case 0xFD48B7 :
lcd.setCursor(0,0);
  lcd.print("Blue On");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,HIGH);
  Serial.println("BLUE ON");
  break;
  
 case 0xFD28D7 :
lcd.setCursor(0,0);
  lcd.print("Blink 1 Sec");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);

  
  digitalWrite(RED,HIGH);
    delay(1000);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
  delay(1000);
digitalWrite(YELLOW,LOW);
  digitalWrite(BLUE,HIGH);

 delay(1000);
digitalWrite(BLUE,LOW);

  Serial.println("BLINKING FASTLY 1 SEC");
  
  break;
  
  
 case 0xFDA857  :
lcd.setCursor(0,0);
  lcd.print("Blink 3 Sec");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);

  
  digitalWrite(RED,HIGH);
    delay(3000);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
  delay(3000);
digitalWrite(YELLOW,LOW);
  digitalWrite(BLUE,HIGH);

  delay(3000);
digitalWrite(BLUE,LOW);

  Serial.println("BLINKING FASTLY 3 SEC");
  
  break;
 
  
  
 case 0xFD6897   :
lcd.setCursor(0,0);
  lcd.print("Blink 5 Sec");
  
  digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
digitalWrite(BLUE,LOW);

  
  digitalWrite(RED,HIGH);
    delay(5000);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,HIGH);
  delay(5000);
digitalWrite(YELLOW,LOW);
  digitalWrite(BLUE,HIGH);

  delay(5000);
digitalWrite(BLUE,LOW);

  Serial.println("BLINKING FASTLY 5 SEC");
  
  break;
 
 case 0xFD18E7    :
lcd.setCursor(0,0);
  lcd.print("All On");
  
  digitalWrite(RED,HIGH);
    digitalWrite(YELLOW,HIGH);

digitalWrite(BLUE,HIGH);
    Serial.println("ALL ON ");
  
  break;
  
   case 0xFD58A7     :
lcd.setCursor(0,0);
  lcd.print("Random");
  
  digitalWrite(5, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(7,HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(7,LOW);
  digitalWrite(5, HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(7,HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(7,LOW);
  digitalWrite(5, HIGH);
  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  digitalWrite(7,HIGH);
  delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
  digitalWrite(7,LOW);
  delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
  digitalWrite(6, LOW);
  delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
  digitalWrite(5, LOW);
  digitalWrite(5, HIGH);
  delay(200); // Wait for 200 millisecond(s)
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  delay(200); // Wait for 200 millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(7,HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(5, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7,LOW);

  delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
  digitalWrite(7,LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);

  delay(1000 * random(0.2, 2 + 1)); // Wait for 1000 * random(0.2, 2 + 1) millisecond(s)
  for (counter = 0; counter < 10; ++counter) {
    delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
    digitalWrite(7,LOW);
    delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
    digitalWrite(6, LOW);
    delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
    digitalWrite(5, LOW);
    digitalWrite(5, HIGH);
    delay(200); // Wait for 200 millisecond(s)
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    delay(200); // Wait for 200 millisecond(s)
    digitalWrite(6, LOW);
    digitalWrite(7,HIGH);
  }
  digitalWrite(6, HIGH);
  digitalWrite(5, HIGH);
  delay(1000 * random(0.1, 2 + 1)); // Wait for 1000 * random(0.1, 2 + 1) millisecond(s)
  digitalWrite(7,LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);
  digitalWrite(7,HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(7,LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);

  break;

 

  
    
  
  default:
Serial.print("Undefined code received: 0x");
Serial.println(results.value, HEX);
  lcd.begin(16, 2);
    lcd.print("Undefined Button");
  lcd.setCursor(0, 1);
  	lcd.print(results.value, HEX);
break;
}
irrecv.resume();
}
}
  

Can anyone pls tell mistake in my code that why led is not blinking again and again it stop's blinking only 1 time Why my code which is written in Loop function is not executing again and again

Thanks in Advance
Krishna

What do you see in the Serial monitor when you press a button and do you see something different if you hold the button down ?

Hi @UKHeliBob thanks for Replying
As you asked me what is showing on Serial Monitor it is Showing Undefined code received as I have set down this function in the code if any other button is pressed or any other code is passed by Remote Show this and then it Signal Code.

When I hold it Down it Is not working the same it again and again sending different Code.

Secondly My program is not switching to different case when current function is running.

Pls help me to solve this I will too grateful to You

Thanks

Try this with the code that you have

  • Upload it so that you know exactly what is running
  • open the Serial monitor and clear the output
  • uncheck Autoscroll in the Serial monitor
  • press and hold the "Yellow on" button for say 5 seconds
  • copy the contents of the single screen of output that is showing in the Serial monitor by selecting it all and pressing Ctrl+C. I do not mean take a screen shot of the Serial monitor
  • paste what you copied here in code tags

What we are trying to do is to see what is initially sent when you press a button and what is sent when you hold the button down. By starting with a clear screen and turning off Autoscroll you will see both