Simple 2 Outputs and 3 inputs

Noob here and trying my hand at a home project. Old ladder logic guy. I want to open and close the gate and garage door from an app. This part works.
When I test the inputs to let me know the status of each, is not working and showing on the app.

Will someone look at my code, please? This is my first Arduino-type code so be kind…
Thanks
Trell

#define BLYNK_TEMPLATE_ID "TMPLk2UKFHId"
#define BLYNK_DEVICE_NAME "Gate"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT

#include "BlynkEdgent.h"
BLYNK_READ(V5)
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, digitalRead(5));
}
BLYNK_READ(V4)
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V4, digitalRead(4));
}
BLYNK_READ(V2)
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, digitalRead(2));
}

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assinging incoving value from pin V1 to a variable
  digitalWrite(15,pinValue);
  // process recived value
}
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assinging incoving value from pin V1 to a variable
  digitalWrite(13,pinValue);
  // process recived value
}
void setup()
{
  pinMode(15,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(5,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(2,INPUT_PULLUP);
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
}```

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: ```

1 Like

You can update the state of the widget from the hardware side using this command.

Blynk.virtualWrite(vPin, value);

For example, to update the state of a button widget with a min value of 0 and a max value of 1 attached to virtual pin 0, you can use

Blynk.virtualWrite(V0, 1);

To change the button state to on, and

Blynk.virtualWrite(V0, 0);

To change the state to off.

You’ll need to provide some information about the functionality of each widget that is attached to each of the virtual datastreams,as well as provide some info on what isn’t working, for this to make any sense to us.

Pete.

This is GATE open or closed.

{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, digitalRead(5));
}```

*This is Garage Door OPEN*
```BLYNK_READ(V4)
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V4, digitalRead(4));
}```

*This is Garage Door CLOSED*
```BLYNK_READ(V2)
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, digitalRead(2));
}```

This is GATE CYCLE, open or close Output
```BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assinging incoving value from pin V1 to a variable
  digitalWrite(15,pinValue);
  // process recived value
}```

This is GarageDoorCycle output
```{
  int pinValue = param.asInt(); // assinging incoving value from pin V1 to a variable
  digitalWrite(13,pinValue);
  // process recived value
}```

Is this want you wanted? THe outputs work great but the input don't show on the app.
Thanks

Widget types connected to these datastreams?

Pete.

Thanks for the reply.
So would I write it like

{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, 1);
  Blynk.virtualWrite(V5, 0);
}

Here’s an example

BLYNK_WRITE(V1) // this command is listening when something is written to V1
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  
  if (pinValue == 1){
   digitalWrite(15, HIGH);
   Blynk.virtualWrite(V5, 1);
  } else if (pinValue == 0) {
   digitalWrite(15, LOW);
   Blynk.virtualWrite(V5, 0);
  }
}

Wish you were here to see the light go off over my head. This makes sense.
Thanks for taking the time to teach me something new.
I will try it and get back to you

1 Like