0

I have an arduino uno connected to a 8 channel relay board. I want to use it with Vixen 3. When I upload the code all the relays turn on. So, when i send a signal in Vixen the relay turns off. I need a way to invert this so when I send the signal from Vixen it turns on the relay. The coding side isn't really my strong point, so please go easy on me.

With love xx

int C1 = 2;
int C2 = 3;
int C3 = 4;
int C4 = 5;
int C5 = 6;
int C6 = 7;
int C7 = 8;
int C8 = 9;
int i = 0;
int incomingByte[8];

void setup()
{
  Serial.begin(9600);
  pinMode(C1, OUTPUT);
  pinMode(C2, OUTPUT);
  pinMode(C3, OUTPUT);
  pinMode(C4, OUTPUT);
  pinMode(C5, OUTPUT);
  pinMode(C6, OUTPUT);
  pinMode(C7, OUTPUT);
  pinMode(C8, OUTPUT);
}

void loop()
{
  if (Serial.available() >= 8) {
    for (int i=0; i<=8; i++)
    {
      incomingByte[i] = Serial.read();
    }
    analogWrite(C1, incomingByte[0]);
    analogWrite(C2, incomingByte[1]);
    analogWrite(C3, incomingByte[2]);
    analogWrite(C4, incomingByte[3]);
    analogWrite(C5, incomingByte[4]);
    analogWrite(C6, incomingByte[5]);
    analogWrite(C7, incomingByte[6]);
    analogWrite(C8, incomingByte[7]);
  }
}
  • 1
    Can you add the schematic also of your circuit and a link to the relay board you're using? Right now I can see a couple problems: You can only use analogWrite with pins that have a pwm function (3, 5, 6, 9, 10, 11). The ones with the ~ next to the number. Also the end condition on your for loop should be "i < 8" since incomingByte only has 8 members (0 through 7). – Sam Dec 10 '16 at 00:36
  • Why are you using PWM to control the relays? Why aren't you using an array for pin numbers? – gre_gor Dec 12 '16 at 14:29

1 Answers1

0

Try this code:

    int C1 = 2;
    int C2 = 3;
    int C3 = 4;
    int C4 = 5;
    int C5 = 6;
    int C6 = 7;
    int C7 = 8;
    int C8 = 9;
    int i = 0;
    int incomingByte[8];

    void setup()
    {
      Serial.begin(9600);
      pinMode(C1, OUTPUT);
      pinMode(C2, OUTPUT);
      pinMode(C3, OUTPUT);
      pinMode(C4, OUTPUT);
      pinMode(C5, OUTPUT);
      pinMode(C6, OUTPUT);
      pinMode(C7, OUTPUT);
      pinMode(C8, OUTPUT);
      digitalWrite(C1, LOW);
      digitalWrite(C2, LOW);
      digitalWrite(C3, LOW);
      digitalWrite(C4, LOW);
      digitalWrite(C5, LOW);
      digitalWrite(C6, LOW);
      digitalWrite(C7, LOW);
      digitalWrite(C8, LOW);
    }

    void loop()
    {
      if (Serial.available() >= 8) {
        for (int i = 0; i <= 8; i++)
        {
          incomingByte[i] = Serial.read();
        }
        analogWrite(C1, incomingByte[0]);
        analogWrite(C2, incomingByte[1]);
        analogWrite(C3, incomingByte[2]);
        analogWrite(C4, incomingByte[3]);
        analogWrite(C5, incomingByte[4]);
        analogWrite(C6, incomingByte[5]);
        analogWrite(C7, incomingByte[6]);
        analogWrite(C8, incomingByte[7]);
      }
    }
Dileep
  • 65
  • 1
  • 1
  • 8