Help with this code please :)

Please help me with this code :slight_smile: I can't figure out how to make the arduino turn on a relay instead of displaying the button name, when a button on a IR remote is pressed!
What am i doing wrong? I want to replace the case 0xFF9867: Serial.println("Replay"); break; //replay line with ex. case 0xFF9867: digitalWrite(RELAY1, LOW); break; //replay
The code:

/*
 "RELAY GND" <-> "Arduino GND"
 "RELAY VCC" <-> "Arduino 5v"
 "RELAY IN2" <-> "Arduino pin 6"
 "IR pin 1" <-> "Arduino 5v"
 "IR pin 2" <-> "Arduino GND"
 "IR pin 3" <-> "Arduino pin 11
*/

#define RELAY1  6
#include <IRremote.h>
int receiver = 11;
IRrecv irrecv(receiver);
decode_results results;

void setup()
{
  Serial.begin(9600);
  digitalWrite(RELAY1, HIGH);
  pinMode(RELAY1, OUTPUT);
  irrecv.enableIRIn();
  delay(4000);
}
void translateIR()
{
  switch(results.value)
  {
    case 0xFFA25D: Serial.println("Power"); break; //power
    case 0xFF629D: Serial.println("Mode"); break; //mode
    case 0xFFE21D: Serial.println("Silent"); break; //silent
    case 0xFF22DD: Serial.println("Play/Pause"); break; //play/pause
    case 0xFF02FD: Serial.println("Previous"); break; //previous
    case 0xFFC23D: Serial.println("Next"); break; //next
    case 0xFFE01F: Serial.println("Equalizer"); break; //equalizer
    case 0xFFA857: Serial.println("Minus"); break; //minus
    case 0xFF906F: Serial.println("Plus"); break; //plus
    case 0xFF6897: Serial.println("0"); break; //0
    case 0xFF9867: Serial.println("Replay"); break; //replay
    case 0xFFB04F: Serial.println("U/SD"); break; //u/sd
    case 0xFF30CF: Serial.println("1"); break; //1
    case 0xFF18E7: Serial.println("2"); break; //2
    case 0xFF7A85: Serial.println("3"); break; //3
    case 0xFF10EF: Serial.println("4"); break; //4
    case 0xFF38C7: Serial.println("5"); break; //5
    case 0xFF5AA5: Serial.println("6"); break; //6
    case 0xFF42BD: Serial.println("7"); break; //7
    case 0xFF4AB5: Serial.println("8"); break; //8
    case 0xFF52AD: Serial.println("9"); break; //9
    default: Serial.println("ERROR"); //default
  }
  delay(500);
}
void loop()
{
  if (irrecv.decode(&results))
  {
    translateIR();
    for (int z=0; z<2; z++)
    {
      irrecv.resume();
    }
  }
}

Thanks :slight_smile:

Moderator edit: CODE TAGS.

TED.ino (1.83 KB)

I can't figure out how to make the arduino turn on a relay instead of displaying the button name,

I would have thought turning the relay on is trivial.
Deciding when to turn it off may be less trivial.

    for (int z=0; z<2; z++)
    {
      irrecv.resume();
    }

What? You don't call resume() in a loop!

What am i doing wrong?

You aren't telling us what happened when you made the code change.

I am a newbie.. just got my arduino and i aren't familiar with C.. I just edited the script to fit my arduino settings. I didn't make the resume(). If you know how, can you please post the edited script? Thanks for the fast replies! :slight_smile:

PaulS:

    for (int z=0; z<2; z++)

{
      irrecv.resume();
    }



What? You don't call resume() in a loop!