Blynk defined pins are not defined until button is pressed?

I have three LEDs on Pins 14, 15, & 16.
I created three buttons in Blynk to turn them on individually.
I also have a virtual pin that blinks the three bulbs in unison by blinking pins 14, 15, 16.

If I press the Blynk buttons and light the LEDs first, everything works fine afterwards.
If I run the virtual pin function first before I ever press the Blynk buttons, the lights only light dimly.
This is because the pins were never defined in the sketch as outputs.

It seems the pins dont get defined until they are activated by a Blynk button press.
Is there a way that Blynk can define pins on startup…so I dont need to do it manually?

Or am I doing something wrong?

this is already happens when you press start button on dashboard. Please share your code so we could check it is ok. Also hardware restart may help. It could be a hardware issues itself.

Definitely not happening with me.
iOS, Arduino Uno, SeeedStudio Ethernet Shield V2.0

// Libraries
#include <SPI.h>
#include <EthernetV2_0.h> //SeeedStudio Ethernet Shield
#include <BlynkSimpleEthernetV2_0.h> //Blynk Library for Seeed Shield
#include <SimpleTimer.h> //Timer
#include <dht.h> //DHT11 Temp/Humidity Sensor Library


// Define Ethernet Shield Pin and SD Card Pin
#define W5200_CS  10
#define SDCARD_CS 4


// Initiate DHT11 Temperature/Humidity Sensor on Pin 17
dht DHT;
#define DHT11_PIN 17


// BLYNK Authorization Code
char auth[] = " ";


// SimpleTimer
SimpleTimer timer;


// Celcius to Farenheit Conversion
double Fahrenheit(double celsius)
{
	return 1.8 * celsius + 32;
}


//Temp to Virtual Pin 4 - Humidity to Virtual Pin 3
void sendDHT()
{
	DHT.read11(DHT11_PIN);
	Blynk.virtualWrite(V4, Fahrenheit(DHT.temperature));
	Blynk.virtualWrite(V3, DHT.humidity);
}


//Uptime to Virtual Pin 5 - Milliseconds/1000 = 1 sec
void sendUptime()
{
	Blynk.virtualWrite(V5, millis() / 1000);
}


//ALL LEDs - ON & OFF
BLYNK_WRITE(V1)
{
	if (param.asInt())
	{
		digitalWrite(14, HIGH);
		digitalWrite(15, HIGH);
		digitalWrite(16, HIGH);
		digitalWrite(9, HIGH);
		digitalWrite(3, HIGH);
	}
	else
	{
		digitalWrite(14, LOW);
		digitalWrite(15, LOW);
		digitalWrite(16, LOW);
		digitalWrite(9, LOW);
		digitalWrite(3, LOW);
	}
}


void doorBell()
{
	int dbPressed = digitalRead(19);
	if (dbPressed == HIGH)
	{
		digitalWrite(14, HIGH);
		delay(500);
		digitalWrite(14, LOW);
		Blynk.notify("Ding-Dong! Someone is at the door!");
		
		// Blynk.email("email@gmail.com", "Ding-Dong!", "Ding-Dong! Someone is at the door!");
		// Blynk.tweet("My Arduino project is tweeting using @blynk_app and it’s awesome!\n #arduino #IoT #blynk");
		delay(2500);
	}
} //End doorBell


void setup()
{
	Serial.begin(9600);
	pinMode(SDCARD_CS, OUTPUT); //Define SDCard Pin as Output
	digitalWrite(SDCARD_CS, HIGH); // Deselect the SDCard
	Blynk.begin(auth);
	while (!Blynk.connect())
	{
		// Wait until connected
	}

    timer.setInterval(1000L, sendUptime);
	timer.setInterval(1000L, sendDHT);
	timer.setInterval(1000L, doorBell);
} //End Setup


void loop()
{
	Blynk.run(); //Loop Blynk
	timer.run(); //Loop SimpleTimer Commands

} //End Loop

Did you see anything in my code?

Code seems ok.
@vshymanskyy do you have any ideas?

it looks like you just forgot to set the pinModes in the setup() for your digital pins.
It’s always better to do so if you are calling digitalWrite from the virtual Pin

I thought one of the benefits of Blynk was that I didn’t need to define and setup pins within the sketch. I may as well define everything if I plan to call the pin functions from anything other than the Blynk app.

Can’t your app define pins used in the app when play is pressed?

it really does so (i.e setups pins).
But it really doesn’t matter as you use also a virtual pin handler (so you already modify code).
Why should it be hard to set pinModes in this case?

It really doesn’t matter in this case as it’s just a test of your system. And it’s not hard to define a pin as an output and set it to low in my setup. But I was under the impression that your app was supposed to do that for me.

I could add 12 buttons in your app to control 12 LEDs (or other devices). But if I want to create a virtual pin that creates an option to light two LEDs at once…I need to define my pins. Complicate that further and suddenly the advertised 5 minute simplicity of your app isn’t 5 minutes anymore.

A possible solution could be that your app defines any digital or analog pin, that is controlled by a button in the app, as an OUTPUT…after pressing play.

Oh yeah…I forgot a :smiley: to indicate I come in peace.

1 Like

It should work. We will investigate it, for sure… Pretty weird since all pinmodes should be set up by Play button

@nickcornaglia please give me your email so I could check your profile on Blynk server. You are using cloud, right?

My username at gmail.com

Hey Nick,

I think I have witnessed on my project what you were seeing. It seems like the output state can be defined but not necessarily in sync with the APP. After one cycle though, everything seems to be in order.

I know this didn’t really answer the question but perhaps verified what you are seeing.

R

Not at all. :smile: :slight_smile: :slight_smile:

1 Like

Duplicating the same issue…

I am using a 8 relay board and want to know exactly when those relays are energized because obviously they will be controlling real world things around my home. As I understand it, the attached code should immediately look at the D2 pin and copy that to V22. It does not. As an example using the attached code, set button V2 high and everything goes high. Hit the reset button and everything goes low, yet V2 remains high, V22 remains high. Blynk does not look at V22 to update. Button V2 has to cycle to LOW and then HIGH again before everything is in sync. State change requires some Event, related or unrelated.

char auth[] = "X"; // Put your Auth Token here. (see Step 3 above)

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
  
  //  Reset all Arduino outputs to HIGH
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);

  int pinState2 = digitalRead(2);
  Blynk.virtualWrite(22, pinState2);


}

BLYNK_WRITE(2)
{
  int pinState2 = digitalRead(2);
  Blynk.virtualWrite(22, pinState2);
  
  if (param.asInt()) {
    digitalWrite(2, LOW);
  } else {
    digitalWrite(2, HIGH);
  }
}

BLYNK_WRITE(3)
{
  if (param.asInt()) {
    digitalWrite(3, LOW);
    Blynk.virtualWrite(13, HIGH);
  } else {
    digitalWrite(3, HIGH);
    Blynk.virtualWrite(13, LOW);
  }
}

BLYNK_WRITE(4)
{
  if (param.asInt()) {
    digitalWrite(4, LOW);
    Blynk.virtualWrite(14, HIGH);
  } else {
    digitalWrite(4, HIGH);
    Blynk.virtualWrite(14, LOW);
  }
}

BLYNK_WRITE(5)
{
  if (param.asInt()) {
    digitalWrite(5, LOW);
    Blynk.virtualWrite(15, HIGH);
  } else {
    digitalWrite(5, HIGH);
    Blynk.virtualWrite(15, LOW);
  }
}


void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...
}