[ask] IR Remote code

hello master… i want to ask code for IR remote

#include <IRremote.h>

int RECV_PIN = 11;
int code;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    code = results.value;
   switch(code)
   { 
    case 16582903://1
    analogWrite(A0, 255);
    break;
    irrecv.resume(); // Receive the next value
  }
}

if i press and hold number 1 in remote (case 16582903) pin A0 is HIGH
i want to, if i release number 1 after i press and hold , pin A0 is LOW
so what code should i use?

if i press and hold number 1 in remote (case 16582903) pin A0 is HIGH

When you hold a remote key down, typically the remote sends a different signal, called a repeat signal. That signal is the same, regardless of which key is pressed, so, holding the key is not what makes the Arduino pin stay HIGH.

i want to, if i release number 1 after i press and hold , pin A0 is LOW so what code should i use?

It's not a matter of code. You need different hardware.

Think about it. You aim the remote at the TV, and press the power button. You don't want the TV to turn off when you release that button, do you? You change the channel. You don't want it to change back when you release the button, do you? You turn up (or down) the volume. You don't want it to change back when you release the button, do you?

First of all a couple of things - you are missing a closing bracket at the end, but I presume that is just a typo - your statement 'irrecv.resume(); // Receive the next value' may best be placed before the switch statement.

Secondly: - did you get any output on your serial port or window? if so what was it. - what receiver are you using? what is connected to pin 11 and what else is this component connected to? - you might put a default case in the switch to toggle the LED, which will show that the IR code is not a match

Other wise you code seems OK, but need more info to assist further.


For anyone interested in IR protocols - we have just launched a project for AnalysIR - IR Decoder & Analyzer GUI (Arduino & Raspberry Pi). Currently we support 17 IR protocols and are looking for more to add as part of the campaign. Suggestions Welcome!

You can find out more and support the Project by visiting http://igg.me/at/AnalysIR/x/3752156 or Screenshot via www.AnalysIR.com

Hello, I want to ask that what is the code for IR remote in Arduino uno kit