Remotely Control a Relay with Arduino UNO

Control Two Relays

 

We can easily modify the previous example in order to control two relays. To do that, we have just to connect another Arduino’s digital output to a second Relay and change a few lines of code:

  • we change the panel definition in order to add the second control channel and to make the panel nicer:

D!g11;/5T*25fb:Arduino Relay;=*16/30{mL1G:0;|*12W1:0;|T:Relay 1;}/{mL2G:0;|*12W2:0;|T:Relay 2;}/30*20T#FF0ht3,000:&#956Panel;

 Serial.println("$P:Dg11;/5T*25fb:Arduino Relay;=*16/30{mL1G:0;|*12W1:0;|T:Relay 1;}/{mL2G:0;|*12W2:0;|T:Relay 2;}/30*20T#FF0ht3,000:μ");
we add four lines of code in order to manage the second switch:
  ...
  digitalWrite(9, 1);
  pinMode(9,OUTPUT);
  ...
  if (Msg.equals("#W20")) {digitalWrite(9,1); Serial.println("#L20");}    // Turn OFF LED 2 and Relay if switch is OFF
  if (Msg.equals("#W21")) {digitalWrite(9,0); Serial.println("#L21");}    // Turn ON LED 2 and Relay if switch is ON
  ...

Watch the video of this example: