Led blink until IR remote ON/OFF same button

Hai,
Pls help for code,

I got

Led 1 in pin 2
Led 2 in pin 3

To control with ir remote

Led 1 should turn on and off when desired switch pressed
Led 2 should blink and turn off when desired switch presses

Pls help

I know how to turn on and off code, but not aware of blink until i press switch in ir

Show your best attempt and we may try to show you where is problem. This is so simple task someone may write the code for you but

  1. you will learn nothing
  2. noone will do it with more difficult code so you need to learn how to ask for help properly

Hai Smajalf,
Thank you for your response,

My project is to light up all lights fixed on a die cast car model.

i am attaching my code below, its showing error, i think problem is with last two cases for signal lights in my project.

pls help to correct it…

#include <IRremote.h>
int RECV_PIN = 3;
int HL = 6;   // HEAD LIGHTS
int RL = 5;   //REAR LIGHTS + 
int BK = 12;  // BREAK LIGHTS
int RI = 11;  // RIGHT SIGNAL LIGHT
int LI = 10;  // LEFT SIGNAL LIGHT
int FOG = 9;  // FOG LIGHT                                              
int togglestate = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
irrecv.enableIRIn();

  pinMode(HL, OUTPUT);
  pinMode(RL, OUTPUT);
  pinMode(BK, OUTPUT);
  pinMode(RI, OUTPUT);
  pinMode(LI, OUTPUT);
  pinMode(FOG, OUTPUT);                          

}

void loop() {
  if (irrecv.decode(&results)) {
    switch(results.value){
      
case 0xFD807F:  // HEAD LIGHT and REAR LIGHT should light up 100
      if (togglestate==0){
  analogWrite(HL, 100);
  analogWrite(RL, 100);
 togglestate=1;
}
 else{
digitalWrite(HL,LOW);
digitalWrite(RL,LOW);
 togglestate=0;   
 }
   break;
 
 case 0xFD40BF: // FOG LIGHT ON/OFF
      if (togglestate==0){
  digitalWrite(FOG, HIGH);
 togglestate=1;
}
 else{
digitalWrite(FOG,LOW);
 togglestate=0;   
 }
   break;
      
 case 0xFD00FF: // BREAK LIGHT and REAR LIGHT ON/OFF,
      if (togglestate==0){
  digitalWrite(BK, HIGH);
  digitalWrite(RL, HIGH);       
 togglestate=1;
}
 else{
digitalWrite(BK, LOW);
digitalWrite(RL, LOW);
 togglestate=0;   
 }
   break;     
 
      case 0xFD20DF: // LEFT SIGNAL LIGHT BLINK ON/OFF ,
                 
unsigned long previousMillis = 0; 
long interval = 1000;  
int LI = LOW; 
  if (currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;
    if (LI == LOW) {
      LI = HIGH;
    } else {
      LI = LOW;
    }

    digitalWrite(LI, ledState);  
      
     break;      
 
   case 0xFD609F: // RIGHT SIGNAL LIGHT BLINK ON/OFF ,
                 
unsigned long previousMillis = 0; 
long interval = 1000;  
int RI = LOW; if (currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;
    if (RI == LOW) {
      RI = HIGH;
    } else {
      RI = LOW;
    }

    digitalWrite(RI, ledState);  
      
     break;      
                
       
}    
    irrecv.resume();
  }
}

for schematic

its showing error,

Please give us the error. Use code tags for the error message.

Also can you please use ctrl-T in the IDE and re-post your code? It's so badly formatted that it's hard to read.

This is how you post a link:

But your link does not work. It asks for a password. If you want to show a picture, please attach it to your post as described in the forum sticky post.

#include <IRremote.h>
int RECV_PIN = 3;
int HL = 6;   // HEAD LIGHTS
int RL = 5;   //REAR LIGHTS +
int BK = 12;  // BREAK LIGHTS
const int RI = 11;  // RIGHT SIGNAL LIGHT
const int LI = 10;  // LEFT SIGNAL LIGHT
int FOG = 9;  // FOG LIGHT
int togglestate = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;

int ledState = LOW;
unsigned long previousMillis = 0;
unsigned long interval = 500;

void setup() {
  irrecv.enableIRIn();

  pinMode(HL, OUTPUT);
  pinMode(RL, OUTPUT);
  pinMode(BK, OUTPUT);
  pinMode(RI, OUTPUT);
  pinMode(LI, OUTPUT);
  pinMode(FOG, OUTPUT);

}

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value) {

      case 0xFD807F:  // HEAD LIGHT and REAR LIGHT should light up 100
        if (togglestate == 0) {
          analogWrite(HL, 100);
          analogWrite(RL, 100);
          togglestate = 1;
        }
        else {
          digitalWrite(HL, LOW);
          digitalWrite(RL, LOW);
          togglestate = 0;
        }
        break;

      case 0xFD40BF: // FOG LIGHT ON/OFF
        if (togglestate == 0) {
          digitalWrite(FOG, HIGH);
          togglestate = 1;
        }
        else {
          digitalWrite(FOG, LOW);
          togglestate = 0;
        }
        break;

      case 0xFD00FF: // BREAK LIGHT and REAR LIGHT ON/OFF,
        if (togglestate == 0) {
          digitalWrite(BK, HIGH);
          digitalWrite(RL, HIGH);
          togglestate = 1;
        }
        else {
          digitalWrite(BK, LOW);
          digitalWrite(RL, LOW);
          togglestate = 0;
        }
        break;

      case 0xFD20DF: // LEFT SIGNAL LIGHT BLINK ON/OFF ,
        unsigned long currentMillis = millis();
        if (togglestate == 0) {
          if (currentMillis - previousMillis > interval) {
            previousMillis = currentMillis;
            if (ledState == LOW)
              ledState = HIGH;
            togglestate = 1;
          }
          else
            ledState = LOW;
          digitalWrite(LI, ledState);
          togglestate = 0;
        }
    }

  }
  irrecv.resume();
}

Thankyou for the picture.

I asked for several other things in my last post but I do not think you understand. What is your first language? Perhaps there is a forum section where you can better understand.

Nilfar:
Hai,
how r u brother,

my project, is to light up a die cast model car, like youtube link below

Diecast car 1/18 scale model car LED collection 1/24 - YouTube

pls help me by checking my code

i am a beginner :cry:

Please do not send personal message asking for help. I will try to help you here on the forum, but you must try to understand and do what we ask. If you cannot understand something that we ask for, please tell us. Are there some requests from previous posts that you could not understand?

Yes, error is that

Lights not bilnking in last case code

This is clearly hopeless. Good luck with your project, I hope you find someone to help you who shares your language.

I see two problems in your code:

  1. You need separate togglestate variable for each light
  2. The blinking part of the code should be directly in loop, not in the if.

still LED not blinking , :frowning:

#include <IRremote.h>
int RECV_PIN = 3;
int HL = 6;   // HEAD LIGHTS
int RL = 5;   //REAR LIGHTS +
int BK = 12;  // BREAK LIGHTS
const int RI = 11;  // RIGHT SIGNAL LIGHT
const int LI = 10;  // LEFT SIGNAL LIGHT
int FOG = 9;  // FOG LIGHT
int togglestate = 0;
int togglestate1 = 0;
int togglestate2 = 0;
int togglestate3 = 0;


IRrecv irrecv(RECV_PIN);
decode_results results;

int ledState = LOW;
unsigned long previousMillis = 0;
unsigned long interval = 500;

void setup() {
  irrecv.enableIRIn();

  pinMode(HL, OUTPUT);
  pinMode(RL, OUTPUT);
  pinMode(BK, OUTPUT);
  pinMode(RI, OUTPUT);
  pinMode(LI, OUTPUT);
  pinMode(FOG, OUTPUT);

}

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value) {

      case 0xFD807F:  // HEAD LIGHT and REAR LIGHT should light up 100
        if (togglestate == 0) {
          analogWrite(HL, 100);
          analogWrite(RL, 100);
          togglestate = 1;
        }
        else {
          digitalWrite(HL, LOW);
          digitalWrite(RL, LOW);
          togglestate = 0;
        }
        break;

      case 0xFD40BF: // FOG LIGHT ON/OFF
        if (togglestate1 == 0) {
          digitalWrite(FOG, HIGH);
          togglestate1 = 1;
        }
        else {
          digitalWrite(FOG, LOW);
          togglestate1 = 0;
        }
        break;

      case 0xFD00FF: // BREAK LIGHT and REAR LIGHT ON/OFF,
        if (togglestate2 == 0) {
          digitalWrite(BK, HIGH);
          digitalWrite(RL, HIGH);
          togglestate2 = 1;
        }
        else {
          digitalWrite(BK, LOW);
          digitalWrite(RL, LOW);
          togglestate2 = 0;
        }
        break;

    
      case 0xFD20DF: // LEFT SIGNAL LIGHT BLINK ON/OFF ,
        
        if (togglestate3 == 0) {
         unsigned long currentMillis = millis();
          (currentMillis - previousMillis > interval);
            previousMillis = currentMillis;
        (ledState == LOW);
              ledState = HIGH;
            togglestate3 = 1;
          }
          else
            ledState = LOW;
          digitalWrite(LI, ledState);
          togglestate3 = 0;
        }
  
  irrecv.resume();

}
}