Arduino Uno Pin state changes on blynk startup

Arduino Uno+ ethernet shield
Android appver. 2.27.10
Blynk server with blink library 0.6.1

Every time I start or my arduino and blynk starts it changes my d7 and d8 pins(which is what I am wanting to use to control a relay) to high state for a second then is goes back to low. The problem is I want to use the relay for a garage door opener and by it going high my relay opens the doors. I am new to coding so I slightly modified the generic sketch. I did try this code

BLYNK_CONNECTED()
{
Blynk.syncAll();
}
and I did not resolve the problem.

TLDR: Pinstate changes to high on blynk startup briefly and I need it to stay low.

#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*****************************";

#define W5100_CS  10
#define SDCARD_CS 4

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  pinMode(7, LOW);
  pinMode(8, LOW);
  
  Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 80);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
   pinMode(7, LOW);
   pinMode(8, LOW);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Do you have a high level relay to try? Haven’t used the uno much are there some pins that don’t go high at boot. A very quick search https://forum.arduino.cc/index.php?topic=216544.0

Good luck!

The pinMode statement should be used to declare a pin for use as input or output, and to specify whether the pin is pulled up (HIGH) by default.
I’m surprised that the pinMode statement you’re using compiles correctly.

The standard way to overcome the issue that you’re having is to declare the pin as being an output, then immediately doing a digitalWrite to that pin.

Also, you may continue to have issues with this problem if you use direct pin manipulation in the app (assigning widgets to digital rather than virtual pins).

Pete.

Thanks daveblynk,
your web search was better than mine. I fixed it using this method. Once again not a coder but it is working. Now if I can get my ifttt working I am all set thanks to the both of you.

pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);

Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, “blynk-cloud.com”, 80);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);

I really don’t understand why you’re re-defining the same pins as input, then output.
What’s the reason for this?

Pete.

From what I read on the forum.arduino site by changing it to input first it prevents the pin from floating. Otherwise the only other workaround is to use a pull down resistor. I honestly don’t know but that was my understanding and it has been working.

What happens if you do this?:

pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);

Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, “[blynk-cloud.com](http://blynk-cloud.com)”, 80);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8080);

digitalWrite(7, HIGH);
digitalWrite(8, HIGH);

Pete.

1 Like

Some of my devices this works but some flicker on startup and with a garage door it might be enough to open or close it.

2 Likes

Just a word of caution, I would suggest you put some limit switch’s and some flags in your code so you know if it is open or closed. Very important in my country. Gets to -40°C in the winter. Could even set notifications to notify you when it opens or closes. Feel free to post pics of your circuit board or PM me with it.

I assume that’s Canada rather than Ethiopia :slightly_smiling_face:

Pete.

Ya no garage doors here :rofl:. Looking forward to getting back to Canada :canada: in a year and a half…

1 Like

I had the same result as daveBlynk. It blips(not as bad as when I first posted) but as I don’t have it installed on the garage door I don’t know if it is enough to open it. I am willing to try it.

I currently have a webcam setup on it but will probably invest in the resistors and limit switches in the near future

Update: After running some ethernet to the garage and some port forwarding SUCCESS!! Though it does blip for a fraction of a second my door openers are not sensitive enough for that to matter. They stayed closed after 10 manual resets. Thank you to you both for your time and ideas. Not sure if I need to edit title to be solved or not.

2 Likes

Always use NodeMCU secure pins to avoid flicker on startup :wink: