IR remote control audio source selector with relays

Hi Guys. This is my first posting :smiley:
I been doing some programming on the Uno this weekend. I really enjoy it!!
I managed to assign a single button on my tv remote to switch an Led on/off.
I would like to know how to switch multiple led's/relays, each assigned to their own button, say 1-0 on the remote keypad.
Only one relay is allowed to be on at any given time, and pressing a button more than once shouldn't switch relay off.
Can anyone share some code please.

Welcome....

Presumably in your code (which you ought to post, btw :P) you must have a something like this:

if (incomingIRCode == 123435)
{
   if (ledState== off)
     {
        digitalWrite(ledPin, HIGH);
     }
else
   {
       digitalWrite(ledPin, LOW);
    }
}

?

Thank you for the help. Will give it a shot.
OOPS. I only realised afterwards I MUST post some code..

That wasn't so much help, as asking how you're doing it. If it's something along those lines, it would be easy to duplicate for each led/relay, just taking care to re-name the pins in a meaningful way.

But with many, you would presumably remove the toggling aspect, and make sure that any led going on, explicitly turns the others off.

Also just noticed in my snippet I didn't change the status each time the led was bounced:

if (incomingIRCode == 123435)
{
   if (ledOn== false)
     {
        digitalWrite(ledPin, HIGH);
       ledOn=true;
     }
else
   {
       digitalWrite(ledPin, LOW);
      ledOn=false;
    }
}
#include <IRremote.h>
#define irPin 11
IRrecv irrecv(irPin);
decode_results results;
 
#define diodePin 13
int diodeStatus = LOW;
 
void setup() {
   Serial.begin(9600);
    irrecv.enableIRIn();
 
    pinMode(diodePin, OUTPUT);
}
 
void loop() {
   if (irrecv.decode(&results)) {
 
      switch (results.value) {
         case 0x77E15001:
            Serial.println("middle");
            diodeStatus = ~diodeStatus;
            digitalWrite(diodePin, diodeStatus);
            delay(250);
            break;
         }
 
   irrecv.resume();
   }
}

This is what I have thus far.Switching a single led on/off with the same button. How do I modify and insert your code?

You don't need to insert my code, you're doing essentially the same thing.

But I've never seen the use of the ~ as negation in Arduino before:

diodeStatus = ~diodeStatus;

It compiles but does it actually work?

I think for your other buttons you just need to add other cases, and inside each you just switch the appropriate LED on and explicitly turn the others off:

case 0x9999999:
            Serial.println("whatever");
            digitalWrite(diodePinX, LOW);
            digitalWrite(diodePinY, LOW);
            digitalWrite(diodePinX, HIGH);
            delay(250);
            break;

Strange, but it actually works. :smiley:

#include <IRremote.h>
#define irPin 11
IRrecv irrecv(irPin);
decode_results results;
 
#define diodePin 13
#define diodePin 12
int diodeStatus = LOW;
 
void setup() {
   Serial.begin(9600);
    irrecv.enableIRIn();
 
    pinMode(diodePin, OUTPUT);
}
 
void loop() {
      switch (results.value)
        case 0x77E15001:
            Serial.println("red");
            digitalWrite(diodePin12, LOW);
            digitalWrite(diodePin13, HIGH);
            delay(250);
            break;if (irrecv.decode(&results)) 
 
      switch (results.value) {
         case 0x77E13001:
            Serial.println("green");
            digitalWrite(diodePin13, LOW);
            digitalWrite(diodePin12, HIGH);
            delay(250);
            break;
      
         }
 
   irrecv.resume();
   }
}

AAAHrgh. What am I doing wrong? Wont verify =(

How many relays did you want to use?
http://www.lightobject.com/RF-Controller-C8.aspx

diydidi:
AAAHrgh. What am I doing wrong? Wont verify =(

Somehow in your editing, you bumped this.....

if (irrecv.decode(&results))

.... to here:

void loop() {
      switch (results.value)
        case 0x77E15001:
            Serial.println("red");
            digitalWrite(diodePin12, LOW);
            digitalWrite(diodePin13, HIGH);
            delay(250);
            break;if (irrecv.decode(&results)) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,
 
      switch (results.value) {
         case 0x77E13001:

CrossRoads:
How many relays did you want to use?
http://www.lightobject.com/RF-Controller-C8.aspx

Not helping a lot. I want to program arduino. I have plenty of relays. Electronics is not my problem. Problem is coding.

Phew. Finally got it working. Thanx for all help guys!!