Bridge between 2 devices

hello ,
I am creating a motion detector with a PIR module connected to an ESP8266. And I would like my lamp also controller with an ESP8266 to be activated when a movement is detected. Only when a movement is detected nothing happens on the second device yet the movement is detected on the first device

here is the motion sensor code:


  You’ll need:
   - Blynk IoT app (download from App Store or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "--"
#define BLYNK_DEVICE_NAME           "--"
#define BLYNK_AUTH_TOKEN            "Auth Token A"

const int pirPin  = D0;
bool pirStatus  = false;
int timerr = 0;


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "---";
char pass[] = "---";

WidgetBridge bridge1(V0); 

BlynkTimer timer;


void setup()
{
  // Debug console
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimer);
  bridge1.setAuthToken("Auth Token B");
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

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!
  timer.run();
  Blynk.virtualWrite(V2, pirStatus);
  Blynk.virtualWrite(V5, timerr);
  
  pirStatus = digitalRead(pirPin);
}

void myTimer() 
{
  timerr = timerr+1;

  if(pirStatus == 0 && timerr >= 20){
     bridge1.virtualWrite(V24, 1);
     Blynk.virtualWrite(V1, 1);
  }
  else
  {
    bridge1.virtualWrite(V24, 0);
     Blynk.virtualWrite(V1, 0);
     
  }
  if(pirStatus == 1){timerr = 0;}
    
}

and here is the lamp sensor code :

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "---"
#define BLYNK_DEVICE_NAME "---"
#define BLYNK_AUTH_TOKEN "---"

#include <FastLED.h>
#define NUM_LEDS 80

int R;
int G;
int B;
int STATE;
int bright;

CRGBArray<NUM_LEDS> leds;

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "---";
char pass[] = "--";

void setup()
{
  // Debug console
  Serial.begin(9600);
  FastLED.addLeds<WS2811,D0,RGB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  
  bright = 255;
  Blynk.begin(auth, ssid, pass);

  
}
WidgetBridge bridge1(V0);

BLYNK_WRITE(V1){STATE = param.asInt();if(STATE==1){FastLED.setBrightness(bright);}else{FastLED.setBrightness(0);}FastLED.show();}
BLYNK_WRITE(V5){bright = param.asInt();if(STATE==1){FastLED.setBrightness(bright);}FastLED.show();}
BLYNK_WRITE(V9){ R = param[0].asInt(); G = param[1].asInt(); B = param[2].asInt();for(int i = 0  ; i <= NUM_LEDS ; i++){leds[i] = CRGB(R,G,B);FastLED.show();}}


BLYNK_WRITE(V24){
int pinData = param.asInt();
  Serial.print(pinData);
}


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

I modified the code so that it sends the information by serial port and not that it turns on the light

Thanks to anyone who takes the time to respond.

Bride is not supported in Blynk IoT.
Have you looked at using Automations to send data from one device to another?

Pete.

Thank you for your answer, yes I had looked for automations but you need a pro subscription, right?

No, they work with the free subscription.

You probably skipped over this bit of the documentation…

There are also other solutions, such as using the HTTP(S) API or Node-Red…

Pete.

Indeed I had not seen it, sorry for the inconvenience, everything works thank you very much have a nice day.

1 Like