I have integrated Bolt with Razorpay. When razorpay is triggred then bolt pin 0 is set High and then Low. I have connected pin 0 of Bolt with Arduino pin 2. Its working fine. But when the power is disconected and then reconnected in Arduino then its pin connected to relay is High all the time. I have used 10k resister but the issue not resolved. I want after power ON the Arduino, the pin connected to relay should be Low. Please help.
const int iot=2;
const int relay=7;
int I =0;
void setup() {
pinMode(iot, INPUT);
Serial.begin(9600);
pinMode(relay, OUTPUT);
// put your setup code here, to run once:
}
void loop() {
int I=digitalRead(iot);
if (I== HIGH)
{
digitalWrite(relay,HIGH);
delay(3000);
digitalWrite(relay,LOW);
delay(1000);
}
else
{
digitalWrite(relay,LOW);
}
delay(1000);
}
Hi @588ahmadsajjad,
The issue you’re facing, where the pin connected to the relay is set to HIGH when you power on the Arduino, can be resolved by adjusting the initial state of the pin. In Arduino, when the board is powered on, all pins default to INPUT mode and can briefly read as HIGH due to the internal pull-up resistors. To ensure that the relay pin is set to LOW at startup, you should explicitly set the pin mode and state during setup.
const int iot = 2;
const int relay = 7;
void setup() {
pinMode(iot, INPUT);
Serial.begin(9600);
pinMode(relay, OUTPUT);
// Ensure the relay pin is initially LOW
digitalWrite(relay, LOW);
// Add a short delay to ensure stability
delay(100);
}
void loop() {
int I = digitalRead(iot);
if (I == HIGH) {
digitalWrite(relay, HIGH);
delay(3000);
digitalWrite(relay, LOW);
delay(1000);
} else {
digitalWrite(relay, LOW);
}
delay(1000);
}
In this updated code:
- In the
setup
function, we set the relay
pin to LOW
explicitly to ensure the relay is in the OFF state when the Arduino powers up.
- Additionally, a short delay is added after setting the initial relay state to provide stability.
By setting the relay pin to LOW
during setup, you’ll ensure that the relay is initially turned off when the Arduino is powered on or restarted.