IR Remote button Push "ON" release "OFF"

hello friends i need the digital 7 pin white led,IR remote control Button press "ON" button release "OFF" switching.how to edit the sketch

int IR_Recv = 3; //IR Receiver Pin 3
#define BluePin 4
int bluePin = LOW;
int greenPin = 5;
int yellowPin = 6;
int whitePin = 7;

IRrecv irrecv(IR_Recv);
decode_results results;

void setup(){
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(BluePin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(yellowPin, OUTPUT); // sets the digital pin as output
pinMode(whitePin, OUTPUT); // sets the digital pin as output

}

void loop(){
//decodes the infrared input
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(results.value);
//switch case to use the selected remote control button
switch (results.value){

   case 16724175: /////////////////////////////// Toggle button system
    digitalWrite(greenPin, HIGH);
    delay(250);
    digitalWrite(greenPin, LOW);
    break;          
       
   case 16718055: /////////////////////////////// Toggle button system
    digitalWrite(yellowPin, HIGH);
    delay(250);
    digitalWrite(yellowPin, LOW);
    break;
          
    case 16743045: ////////////////////////////// Push ON & Push OFF
     bluePin = ~ bluePin;
     digitalWrite(BluePin,bluePin);
     break;

     
}
irrecv.resume(); // Receives the next value from the button you press

}

}Toggle_Switch_Sketch.ino (1.5 KB)

Please use code tags.

What library are you using? What does your remote look like? Your code is a mess.

Clean up your post, and then I might be able to help you.

Read the forum guidelines to see how to properly post code. You can edit your original post to include code tags.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

What does the improperly posted code do? What is it supposed to do?

There is no way to know when the button on a remote is released with the IRremote library.

What version of the IRremote library are you using? The above code is written for an older version (<3.0) and may not work right with the newest version of the IRremote library.

You have two blue pins? Better to name this properly:

#define BluePin 4
int bluePinState = LOW;

Then

digitalWrite(BluePin,bluePinState);

Easier to understand, no?

1 Like

I think he is presetting it to LOW before the code starts.

I used to do this. For some reason I thought that if you didn't define a pin state before void loop(), it would be "undefined" and "act weird".

Most IR Remote buttons don't signal both Press and Release. Some, like Volume Up and Volume Down, will either send the same message repeating as long as the button is pressed or send the button once and a 'Repeat' code as long as the button is pressed.
To detect a button release you have to use a button that sends repeated codes and use a timer to detect when the repeats have stopped.

1 Like

For good reason - imagine what happens if a Release is missed due to weak signals.

1 Like

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