Module Relay OFF on start

Good day

I have a question how to start the relay module in OFF state when starting the Arduino?

because every time I start the Arduino the relay module is all ON state.

Thanks

Hello,

Please provide your sketch and logs of hardware.

And what Arduino model are you using?

setup() { 

pinMode(relaypin, output);
digitalWrite(relaypin, LOW); 

}

Just a snippet to turn off the relay at boot.

If you’re using a digital datastream to control the GPIO that your relay is attached to then this is one of the things that happens.
You can get around the issue easily by switching to Using virtual pins…

If you’re already using virtual pins then the pinMode and virtualWrite solution described above is what you should do.

Also, it depends on your hardware. If you’re using an Uno for example the pin 13 always seems to do odd stuff on startup.

Pete.

Hi Pete!
I’m still struggling on my test project still my question is Module relay OFF on start?
this is my code below and I’m using arduino with ethernet shield.
Already connected on Blynk and working the problem is when I start the arduino all the relays are switch on.

Code:

#define BLYNK_TEMPLATE_ID "TMPL6bABmnB5r"
#define BLYNK_TEMPLATE_NAME "Garage Gate Automation"
#define BLYNK_AUTH_TOKEN "*******"
#define BLYNK_PRINT Serial
// Adding the required libraries
#include <SPI.h>
#include <Ethernet.h> // You need to add it by searching "Ethernet" in libraries and install it
#include <BlynkSimpleEthernet.h> // You need to add it by searching "Blynk" in libraries and install it
#define LED_PIN_1 4
#define LED_PIN_2 5
#define LED_PIN_3 6
#define LED_PIN_4 7
void setup()
{
  pinMode(LED_PIN_1, OUTPUT);
  pinMode(LED_PIN_2, OUTPUT);
  pinMode(LED_PIN_3, OUTPUT);
  pinMode(LED_PIN_4, OUTPUT);
  // Debug console
  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN);
}
void loop()
{
  Blynk.run();
}
BLYNK_WRITE(V0)
{
  int value = param.asInt();
  if (value == 1)
  {
    digitalWrite(LED_PIN_1, LOW);
  }
  else
  {
    digitalWrite(LED_PIN_1, HIGH);
  }
}
  BLYNK_WRITE(V1)
{
  int value = param.asInt();
  if (value == 1)
  {
    digitalWrite(LED_PIN_2, LOW);
  }
  else
  {
    digitalWrite(LED_PIN_2, HIGH);
  }
}
/* Open Button */
  BLYNK_WRITE(V2)
{
  int value = param.asInt();
  if (value == 1)
  {
    digitalWrite(LED_PIN_3, LOW);
  }
  else
  {
    digitalWrite(LED_PIN_3, HIGH);
  }
}
/* Close Button */
  BLYNK_WRITE(V3)
{
  int value = param.asInt();
  if (value == 1)
  {
    digitalWrite(LED_PIN_4, LOW);
  }
  else
  {
    digitalWrite(LED_PIN_4, HIGH);
  }
}

@mramilo Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

https://docs.blynk.io/en/blynk-library-firmware-api/state-syncing

Please read this :point_up_2:t2:

First of all, you can’t use GPIO4 (or GPIO 10, which you aren’t currently using) with the Ethernet shield, because these are special pins that are used by the shield.

If your relays are Active LOW, then you need to do a digitaWrite(pin, HIGH) to each of the relay pins, immediately after the pinMode statements for the relays.

It would also be far better if you chose much more sensible alias names for your relays, something like Relay_1 instead of LED_PIN_1

Pete.