I am suing this code to control relays with Arduino and remote. This code is working fine for my requirements. Only problem is that when electricity goes and come after some time all appliance turned ON automatically but I want initially all appliances turn OFF and it only turn on ON when remote key pressed.

#include <IRremoteInt.h>

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

void setup()
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);


void loop()
  if (irrecv.decode(&results)) // have we received an IR signal?

    irrecv.resume(); // receive the next value
}/* --(end main loop )-- */

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes

  switch (results.value)
    case 0xE0E020DF:
      static int m = HIGH;
      m = !m;
      digitalWrite(8, m);

    case 0xE0E0609F:
      static int n = HIGH;
      n = !n;
      digitalWrite(9, n);

    case 0xE0E0A05F:
      static int op = HIGH;
      op = !op;
      digitalWrite(10, op);

    case 0xE0E010EF:
      static int p = LOW;
      p = !p;
      digitalWrite(4, p);

    case 0xE0E0906F:
      static int q = LOW;
      q = !q;
      digitalWrite(5, q);

    case 0xE0E040BF:
    static int v = HIGH;
    v = !v;
    digitalWrite(8, v);
    digitalWrite(4, v);
    digitalWrite(5, v);
    digitalWrite(9, v);
    digitalWrite(10, v);

  }// End Case

  delay(500); // to not get immediate repeat

  • \$\begingroup\$ without seeing circuit, how can we see what is wrong \$\endgroup\$ – Mitu Raj Sep 30 at 9:21
  • 1
    \$\begingroup\$ @faisal97 - Hi (a) You cannot change your question to something different, especially not after you have already received and accepted an answer to the original question. That will confuse future readers about which answer is to which question. Therefore I will undo ("rollback") your change to the question. (b) The new question you tried to ask is unclear. You talk about "light gone" but you don't explain how that is different from "electricity goes" from your first question. (c) If you really have a new question, then ask it as a new question - you can link to this question for context. \$\endgroup\$ – SamGibson Oct 2 at 13:37

Add this code within void Setup() function after initializing all pinMode().

digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);

And within the void translate() function add a default case statement.

static int v = LOW;
digitalWrite(8, v);
digitalWrite(4, v);
digitalWrite(5, v);
digitalWrite(9, v);
digitalWrite(10, v);
  • \$\begingroup\$ When I add this code, all keys (defined and not defined in program) switching all relays at once. \$\endgroup\$ – faisal97 Oct 3 at 11:48
  • \$\begingroup\$ I didn't get you clearly. Please explain the problem in detail. \$\endgroup\$ – Prayuktibid Oct 4 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.