Apple remote control 16 relays

Hello!

First post and I’m new to all this so bare with me.

I want to remote control 16 relays with the help of two buttons on an Apple remote. The 16 relays will open one winding each on an autoformer volume control. I want to use one button as volume up and another as volume down.

When I press volume up the next relay up (x+1) should open and the one that was opened (x) should close. If I press volume down the next relay down (x-1) should open. The same thing should happen on both boards at the same time (same volume on both channels).

I have a MEGA 2560 board and two 8 relay (12v) boards. I thought this would be a fairly simple first project but I need more basics first. I have come so far as I have used the remote library and the gotten the hex codes for all buttons.

I’ve also played around with some examples I found and made relays on the board toggle on and off. I’ve searched for a solution because I want to solve it myself but I need someone to point me in the right direction. What is the best method for doing something like this?

//Johan

so bare with me.

I'll keep my clothes on. But, you go ahead. I'll turn away if necessary.

What is the best method for doing something like this?

I'm not sure I understand what the problem is. If you can read data from the remote, you know which button was pressed. If the up button was pressed, increment a counter. If the down button was pressed, decrement the counter. You probably want to constrain() the value of the counter.

On any pass through loop(), when a change to counter happens, turn the current relay off and the next relay on. Storing the relay pins in an array makes this very easy. Otherwise, a switch statement and a bunch of cases will be needed, possibly in if/else blocks to handle going up vs going down (since next means something different depending on direction).

[

I'm not sure I understand what the problem is. If you can read data from the remote, you know which button was pressed. If the up button was pressed, increment a counter. If the down button was pressed, decrement the counter. You probably want to constrain() the value of the counter.

On any pass through loop(), when a change to counter happens, turn the current relay off and the next relay on. Storing the relay pins in an array makes this very easy. Otherwise, a switch statement and a bunch of cases will be needed, possibly in if/else blocks to handle going up vs going down (since next means something different depending on direction).

Thank you for your answer. I like the feeling of freedom you know? :)

My problem is that I don't know enough to understand your answer completely. Would a relay pin array look this?

int RelayPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 22, 24, 26, 28, 30, 31, 32, 33};
int pinCount = 16

Next question is how to set them up as output pins and as a counter?

As you see I have limited basics but am willing to learn.

Would a relay pin array look this?

Yes (though the next line needs a ; ). (Edit: Stupid smiley faces…)

Next question is how to set them up as output pins and as a counter?

You set them as output pins using a for loop:

   for(byte p=0; p<pinCount; p++)
   {
      pinMode(RelayPins[p], OUTPUT);
   }

You create a counter variable:

   byte counter = 0;  // global

Then, when the up button is pressed:

   counter++;

When the down button is pressed:

   counter--;

Find the place in the array with the next relay pin:

   digitalWrite(RelayPins[counter], HIGH);

You’d want to do that last one before and after incrementing/decrementing counter, turning the current pin off and then the next one on.

Here’s what I have so far. Have I got this part right?

//Volymkontroll med fjärr 1.0

#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 11; //Pin for IR sensor
int RelayPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
int pinCount = 16;

byte counter = 0;  // global

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  // put your setup code here, to run once:
 for(byte p=0; p<pinCount; p++)
   {
      pinMode(RelayPins[p], OUTPUT);
   }
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
 }
int RelayPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
int pinCount = 16;

Really?

Have I got this part right?

Except that you read beyond the end of the array, because the number of values in the array does not match the size you have defined, yes, the code is correct, so far.

PaulS: Really?

Oops... :blush:

I thought of two relay boards. Gonna try with one board first.

Not sure I know how to proceed but I will give it a go.

Thank you so far. I bet you feel like I do when I'm trying to help my 70 year old mom understand how her wifi works.

//Johan

This is not right. There is something I'm not getting/missed.

void loop(){
      if (irrecv.decode(&results)){
      if (results.value == 0x77E1D0AC)
        counter++;
        digitalWrite(RelayPins[counter], HIGH);
      }     
   }