Relay is being high at starting, Can we make it Low at start up until input matches

Here is the code, Please make the output pins to be low until a input case matches.
'

#include <IRremote.h>

#define IR_RECEIVE_PIN 8

#define IR_BUTTON_1 1
#define IR_BUTTON_2 2
#define IR_BUTTON_3 3
#define IR_BUTTON_4 4

#define RELAY1_PIN 9
#define RELAY2_PIN 10
#define RELAY3_PIN 11
#define RELAY4_PIN 12
#define DEFULT_PIN 3

byte relay1State = LOW;
byte relay2State = LOW;
byte relay3State = LOW;
byte relay4State = LOW;

void setup() {

IrReceiver.begin(IR_RECEIVE_PIN);
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(RELAY3_PIN, OUTPUT);
pinMode(RELAY4_PIN, OUTPUT);

}

void loop() {
if (IrReceiver.decode()) {
delay(2000);
IrReceiver.resume();
int command = IrReceiver.decodedIRData.command;
switch (command) {
case IR_BUTTON_1: {
relay1State = (relay1State == LOW) ? HIGH : LOW;
digitalWrite(RELAY1_PIN, relay1State);
// delay(3000);
break;
}
case IR_BUTTON_2: {
relay2State = (relay2State == LOW) ? HIGH: LOW;
digitalWrite(RELAY2_PIN, relay2State);
// delay(3000);
break;
}
case IR_BUTTON_3: {
relay3State = (relay3State == LOW) ? HIGH: LOW;
digitalWrite(RELAY3_PIN, relay3State);
// delay(3000);
break;
}
case IR_BUTTON_4: {
relay4State = (relay4State == LOW) ? HIGH: LOW;
digitalWrite(RELAY4_PIN, relay4State);
break;
}
default: {
}
}
}
}

'

Hi @harshavenkatasai321 welcome to the forum.

You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.

However, there is nothing in your code that you can do about this. The answer is to put a 1K pull down resistor on the pin. That is a resistor from the pin to ground. That will stop it floating.

1 Like

Hi @Grumpy_Mike , Thanks for reply, But

I think you , didn't got the clear point. When i given VCC to Arduino UNO , the output relays should be low, But actually they are High at starting. They is responding after case match.

The output
IR_BUTTON_1 1
IR_BUTTON_2 2
IR_BUTTON_3 3
IR_BUTTON_4 4`
These should be low until switch case match.

How are the relays connected to the Arduino?

through jumpers to digital pins as below

#define RELAY1_PIN 9
#define RELAY2_PIN 10
#define RELAY3_PIN 11
#define RELAY4_PIN 12

Please review this, especially the part about posting code

Try this modified setup():

`void setup() {

  IrReceiver.begin(IR_RECEIVE_PIN);
  digitalWrite(RELAY1_PIN,HIGH);
  digitalWrite(RELAY2_PIN,HIGH);
  digitalWrite(RELAY3_PIN,HIGH);
  digitalWrite(RELAY4_PIN,HIGH);
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);

}`

There are two types of relays. NO (Normally Open) and NC (Normally Closed). Which do you have? Some have both type outputs on one relay.

Post an annotated schematic showing all connections. Show power sources. Put a link to technical information on the relays and any other hardware.

This worked, Thanks @JCA34F , I tried this before at that it didn't, Now i just copied your code and it is working fine.

Thanks again. :smiling_face_with_three_hearts:

My first post contained errors, I just caught and fixed it, sorry 'bout that. :grimacing:
I think the problem was your relays are LOW activated, which is the more common way it's done with digital logic.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.