How to decode a IR remote with arduino..??

I want to decode a simple remote like this with arduino

and then make each button make each LEDs connected to the arduino digital pins...

How do I do that..??

How do I do that..??

I don't suppose you bothered with a search first, did you?

Joy: I want to decode a simple remote like this with arduino

and then make each button make each LEDs connected to the arduino digital pins...

How do I do that..??

Use ken sheriff's IR library, it can decode any IR remote.

http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

OK now from here

I have downloaded the library IRremote.h

Now with this code

#include <IRremote.h>

int RECV_PIN = 11;
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);
    irrecv.resume(); // Receive the next value
  }
}

I am able to read the hex value of a SONY remote…

like if I press the PWR button it shows A90
if I press 1 it shows 10
if I press 2 it shows 810
if I press 3 it shows 410

now how do i do this like

if A90 then do x
if 10 then do y
if 810 then do z
etc…

I figured that out now…

#include <IRremote.h>

int pin1 = 3;
int pin2 = 4;
int pin3 = 5;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    
    if(results.value == 0x10){
      digitalWrite(pin1, HIGH);
    }
    if(results.value == 0x410){
      digitalWrite(pin2, HIGH);
    }
    if(results.value == 0x810){
      digitalWrite(pin3, HIGH);
    }
    irrecv.resume(); 
  }
}

but now how do I use the same button to switch on and off the led

like if I press the button 1 on remote the led on pin 3 glows and I want to press the same button 1 on the remote to switch off the led on pin 3…

if I press the button 1 on remote the led on pin 3 glows and I want to press the same button 1 on the remote to switch off the led on pin 3…

You need to keep track of whether the pin is HIGH or LOW. If it’s HIGH, set it LOW. If it’s LOW, set it HIGH.

int pin1State = LOW;

void loop()
{
   // Get the remote code

   if((results.value == 0x10)
   {
      pin1State = !pin1State;
      digitalWrite(pin1, pin1State);
   }
}

Wow.. that was so easy to understand and so short... :)

Thanks PaulS.. :)

I will just post another thing i am trying to do with it..

I will try my brains first.. :) if cannot find out will post here.. :)

I have written this code

#include <IRremote.h>

int pin1 = 3;
int pin2 = 4;
int pin3 = 5;
int RECV_PIN = 11;
int fadered = 5;
int pin1State = LOW;
int pin2State = LOW;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    
    if(results.value == 0x10){
      pin1State = !pin1State;
      digitalWrite(pin1, pin1State);
      delay(500);
    }
    
    if(results.value == 0x490 && fadered <=250){
      fadered = fadered + 5;
      analogWrite(pin3, fadered);
     delay(100); 
    }
    
    if(results.value == 0xc90 && fadered >=5){
      fadered = fadered - 5;
      analogWrite(pin3, fadered);
      delay(100);
    }
   
    irrecv.resume(); 
  }
}

I am using button 1 on remote to switch on and off a led on pin 3

and using volume UP and DOWN buttons to control the brightness of a LED connected to pin 5…

How do I assign another button (eg. button 2) to turn on and off the led on pin 5 of which I am controlling the brightness…??
But I do not want to disturb the bright position if the led is turned off at half brightness and it should be half only if it is turned on again…??

How do I assign another button (eg. button 2) to turn on and off the led on pin 5 of which I am controlling the brightness..??

I think you already know how to do this. Figure out what the results.value value is for the button you want to use.

Then, make that button do a an analogWrite() to the PWM pin with a value of 0. The next time the button is pressed, do a an analogWrite() to the PWM pin with a value of fadered.

:frowning:

thought a lot…
just not able to figure out how do i assemble the code to do this… :frowning:

int btnCnt = 0;

void loop()
{
   // Get remote data

   if(results.value == 0xXX) // Whichever value is appropriate for the button
   {
      btnCnt++;
      if(btnCnt % 2 == 0) // If count is even
         analogWrite(pinN, 0); // Turn pin N off
      else
         analogWrite(pinN, fadered); // Set pin N back where it was
   }
}

Something like this will turn the LED off abruptly when a button on the remote is pressed, and resume it at its previous brightness level on the next press.

That just worked like a charm... :P Did not just come to my mind...:(

Now it is that I would like to write the current state of all output pins and save it to the EEPROM and read it when I start up the arduino again...

to do that will I now have to change all the codes to Case..??

or it will just fit in the current code...??

Reading all the values, in setup, and restoring all the pins to that state is easy.

Writing will be a bit more of a challenge. Not because the task is hard. It isn't. But, you need to decide WHEN to write the current values.

EEPROM has a limited number of write cycles. Its a large number, but then loop executes millions of times per second.

Perhaps best, for now, would be to enable one more button on the remote. When that button is pressed, save the data.

Keep in mind that while digitalRead returns an int, the value that it returns (0 or 1) fits in a byte, so don't write two bytes (an int) to EEPROM to hold that value.

that is correct…

but the problem is I am building this to switch on and off house hold appliances…
So it is necessary to save the data automatically…

else if I had light ! ON and the FAN ON and the electricity goes off and the time it comes back all the lights and fan will stay of until I switch them ON again…

so will have to think of something… :frowning:

Give me some idea…

will it be of any better if I am using an external eeprom like 24cxx

Your long term goal - household automation - and your short term goal - learn how to write to/read from EEPROM - should not be the same goal.

Learn how to read from/write to EEPROM. Then, figure out when to write to EEPROM at the appropriate time.