Help me I want to use the value read from Node MCU 2 to program on Node MCU 1

My project use 2 Node MCU ( Node MCU 1 and Node MCU 2).Node MCU 2 revieved the sensor value from Photoresister(@A0 Pin).But If don’not edit code and run code following below

///I uploaded this code to Node MCU 1 and Node MCU 2///

     #define   BLYNK_PRINT Serial  
     #include  <ESP8266WiFi.h>
     #include   <BlynkSimpleEsp8266.h>
    char auth[] = "cc0e05e8371e4a858e07c69c611116dd";

    void setup()
    {
      Serial.begin(9600);
      Blynk.begin(auth, ":)", "lovebandmod");
    }

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

the result is

But if I uploaded code following

   //For Node MCU 2 GET sensor value//
    #define BLYNK_PRINT Serial    
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>


    char auth[] = "cc0e05e8371e4a858e07c69c611116dd";
    int sensorPin = A0;
     int sensorValue =0;
    void setup()
     {
      Serial.begin(9600);
      Blynk.begin(auth, ":)", "lovebangmod");
     }


    BLYNK_READ(V0)
     {
      int sensorValue = analogRead(sensorPin);
      Blynk.virtualWrite(V0, sensorValue);
      Serial.println(sensorValue);

     }


    void loop()
     {

  Blynk.run();
 }

And

    //For Node MCU 1 I want to use Node MCU 1 controll PWM @D2 Pin //
    #define   BLYNK_PRINT Serial  
    #include  <ESP8266WiFi.h>
    #include   <BlynkSimpleEsp8266.h>
    char auth[] = "cc0e05e8371e4a858e07c69c611116dd";

    void setup()
    {
      Serial.begin(9600);
      Blynk.begin(auth, ":)", "lovebandmod");
    }

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

the result is

Yes I can fix the error.
Next I want to use the sensor value from Node Mcu 2 @A0(V0) pin for controll PWM on Node MCU 1(programing follow below)

What should I do my code on Node MCU 1and NOde MCU?

Please Guide for me. :cry::cry:

@ap10127700 nice graphics and normally they say a picture is worth a thousand words but I don’t understand what your problem is.

Quick sentence, what is wrong?

Haha I’m weak in English I want to use sensor value @A0 pin form Node MCU 2 to controll PWM @ D2 pin in Node MCU 1 But I dob’t Know to Edit my code? what should I do.

That’s mean in this project have 2 Node MCUs are Nosd MCU 1 and Node MCU 2.

Look into Bridge widget at http://docs.blynk.cc/#widgets-other-bridge

1 Like

Or use the same auth token on both devices and use virtual pins. It’ll save you a dashboard too :slight_smile:

Now I want to use the value from V5 pin to program in void loop .In this case I use V4 pin to connect between 2 loop BLYNK_WRITE(V5){…} loop and void loop{…} loop. But when slide V5 in app to 255 V4 does not respond .
What should I do.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cc0e05e8371e4a858e07c69c611116dd";
int sensorPin = A0;
int sensorValue =0;
WidgetBridge bridge1(V1);

void setup()
 {
  Serial.begin(9600);
  Blynk.begin(auth, "Connectify-", "ap1234567");
  
 }
 
BLYNK_CONNECTED() {
  bridge1.setAuthToken("2a97e454d9de4fd791844b92bae8a7e9"); // Token of the hardware B
}

BLYNK_WRITE(V5)
   {   
   int value = param.asInt();
   Serial.print("V5  value  in loop ;");
   Serial.println(value);
   Blynk.virtualWrite(V4, value);
   }

void loop()
 {
  
  int sensorValue = analogRead(sensorPin);
  Serial.println("sensorValue MAIN loop ;");
  Serial.println(sensorValue);
  bridge1.analogWrite(4,sensorValue);
  int value1=analogRead(V4);
  Serial.println("V4  value  OUT loop ;");
  Serial.println(value1);
 
  Blynk.run();
 }

@ap10127700 before I look at your code can you please confirm you have the Bridge widget in each of the projects on the Smartphone.

Also:

Why have you got more than 2 lines in the loop() when almost all the Blynk examples only have 2?
Do you know what SimpleTimer is, i.e. one of the 4 libraries that you must install (manually) if you want to use Blynk for anything more than blinking an LED?
Why is you sketch so badly commented, what is V4 , V5, hardware A, hardware B?

Try to make it easier for us to help you.

1.Get sensor (Analog input) value and sent this value to device B to dimming RED LED(@D2 PIn)--------complete
2.Get the value from BLYNK_WRITE(V5) and promgram for automatic dimming and command automatic dimming to DEVICE B to BLUE LED (@D3 Pin) I will add BLUE LED in future
-------------------------------------------------------------------------------------------------------------------------------------------not complete!!!
(I want to program automatic dimming in void loop use the value from V5 Pin in DEVICE A)

Blynk for DEVICE A

Code DEVICE A

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cc0e05e8371e4a858e07c69c611116dd";
int sensorPin = A0;
int sensorValue =0;
WidgetBridge bridge1(V1);

void setup()
 {
  Serial.begin(9600);
  Blynk.begin(auth, "Connectify-", "ap1234567");
  
 }
 
BLYNK_CONNECTED() {
  bridge1.setAuthToken("2a97e454d9de4fd791844b92bae8a7e9"); // Token of the hardware B
}

BLYNK_WRITE(V5)
   {   
   int value = param.asInt();
   Serial.print("V5  value  in loop ;");
   Serial.println(value);
   Blynk.virtualWrite(V4, value);
   }

void loop()
 {
  
  int sensorValue = analogRead(sensorPin);
  Serial.println("sensorValue MAIN loop ;");
  Serial.println(sensorValue);
  bridge1.analogWrite(4,sensorValue);
  int value1=analogRead(V4);
  Serial.println("V4  value  OUT loop ;");
  Serial.println(value1);
 
  Blynk.run();
 }

DEVICE B
1.GET value from DEVIE A to dimming RED and BLUE LED

Blynk for DEVICE A

Code DEVICE B

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


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


void setup()
 {
  Serial.begin(9600);
  Blynk.begin(auth, "Connectify-", "ap1234567");
 }

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

automatic dimming diagram

result

As per the example at https://github.com/blynkkk/blynk-library/blob/master/examples/Widgets/Bridge/Bridge.ino#L33 the value is obtained from a virtual pin (bridged or regular) in the following way:

   BLYNK_WRITE(V5){
       int pinData = param.asInt(); // pinData variable will store value that came via Bridge
       if(pinData == 1){
           // do something
       }
      else{
          // do something different
      }
   }

You can pass integers, double, floats and strings.
Do not consider putting any of this, or anything else in loop().

With SimpleTimer and an interval of say 500ms call a function such as this:

void checkV5(){
   Blynk.syncVirtualV5);  // this "refreshes" V5
}

If you are physically connecting device A with device B you don’t actually need bridge but it is probably useful for you to learn how it works.