BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Send Water Level value from Device A to Device B using Blynk Bridge

I have an Ultrasonic Water level sensor on a Nodemcu which is working fine using the blynk app for interface (Called Device A).

I would like to add another Nodemcu device (Device B) and send the level info to Device B from Device A using Blynk Bridge widget for displaying the water level on a LCD display through an I2C device attached to the Digital pins of Device B

I need help in getting the correct code in Device A (or Device B) for this application. Can anyone help please?

You can look at the bridge example up top of this page. Start with the basic example and add on from there.

Thanks daveblynk, I could get the code on Device A to assign the variable to Virtual pin 6 using the “Bridge.digitalwrite” command. But I am unable to get the code on Device B to print the Value of Virtual pin 6 to the lcd.

As i can imagine I am a novice just starting out on Blynk

I’d guess that the problem is with the code you are running on “device B”.
Probably not using a global variable, or not handling the LCL side of things correctly, but it’s impossible to say for sure as you haven’t shared your code.

Printing data to the serial monitor within your BLYNK_WRITE(V6) callback is the best starting point.

Pete.

Hi Pete,

Here is my code for Device B:

V5 and V6 are virtual pins with data from Device A. In the Blynk app I can see data of V5 and V6 using the value display widget. But i am not able to store it as a parameter and send it to the Lcd display

I get an error ““Level” is not declared in scope” at the lcd.print(Level) line of code

/**************************************************************
   Blynk Bridge - Communication between ESP8266
   Sketch code for the receiver module (module which is controlled)
   www.geekstips.com
 **************************************************************/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> //includes outside library allowing communication over i2c devices
#include <LiquidCrystal_I2C.h> //includes outside library allowing interfacing with LCD 

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


char auth[] = "xxxxxxxxxxxxxxxx";

char ssid[] = "xxxxxxx";
char pass[] = "xxxxxx";

BLYNK_WRITE(V5) {
  int pinData = param.asInt();
}

BLYNK_WRITE(V6) {
  int Level = param.asInt();
}
void setup(){
  Wire.begin(12,13);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0,0); 
  lcd.print("DWS level: ");  
  lcd.print(Level); 
  lcd.print("  %");

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

Pete.

Thanks Steve. I have added the backticks and the code looks fine now.

Further to my earlier message with some trial and error I could get the code for Device B working. For that I had to move some of the code lines associated with the ‘lcd print’ out of Void Setup and under “Blynk Write (V6)”. Here is the code which is now working. Please suggest any changes that you may see as appropriate to improve it further.

/**************************************************************
   Blynk Bridge - Communication between ESP8266
   Sketch code for the receiver module (module which is controlled)
   www.geekstips.com
 **************************************************************/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> //includes outside library allowing communication over i2c devices
#include <LiquidCrystal_I2C.h> //includes outside library allowing interfacing with LCD 

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


char auth[] = "kic6LqPHgbGqfgT0XhZJ0tWCnK4uasEQ";

char ssid[] = "Srivelop";
char pass[] = "1PineA2!";
//char ssid[] = "JioFi3_742597";
//char pass[] = "u8953uwcr4";
//char ssid[] = "Elements24";
//char pass[] = "elements1";

BLYNK_WRITE(V5) {
  int pinData = param.asInt();
}

BLYNK_WRITE(V6) {
  int Level = param.asInt();
   
  lcd.print("DWS level: ");  
  lcd.print(Level); 
  lcd.print("%");
  delay(1000);
  lcd.clear();
}
void setup(){
  Wire.begin(12,13);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0,0); 
 }

void loop(){
  Blynk.run();
}

I’d suggest that you do some reading about variable scope in C++

When you do this:

The int at the beginning is declaring the variable Level as an integer, but because this is being done within the BLYNK_WRITE(V6) function, that variable is local to that function only.
Declaring the variable at the top of the code, outside of a function, would make it global and provided you take care not to re-declare a variable with the same name locally you will be able to use that variable within any function.

Pete.

Thanks a lot Pete, will do.

sri_c