Button in two separate projects

Hi, is it possible to insert a button in two projects and separate circuits?

example:
relay in the lock project (physically)

but I have to control it from the boiler project

To avoid switching from one project to another with the swipe

Add the device and button in the second project too. There is no restriction that a device has to be part of one project only.

I did not understand how to do it. If I put new device does not make me add that one already done in the project but only a new device

This is not yet supported. We will do that soon, however.

2 Likes

@eddie no, you can not take two functional devices/projects and merge them, if that is what you mean (not without manualy rebuilding one into the other).

But you can add a 2nd, 3rd, etc… device to an existing project and account for it in the App with either Device Selector / Device Tiles

You can also have a button in one project control a vPin, and thus a relay etc. in another project… using Bridge

1 Like

I would like to be able to control a relay in project 1 also project 2

Yep

ok, but the bridge I have to write in the project code where there is no physical relay, correct ???

With bridge you would have sending code on the sending device and receiving code on the receiving device.

https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FBridge

I now have a bidirectional Bridge demo at this link - C++ Blynk - Code Examples for Basic Tasks (Work in Progress)

Code Device A

//Device A:

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


char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
 
char ssid[] = "xxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxx";

WidgetBridge bridge1(V2); //Initiating Bridge Widget on V1 of other Device
 
void setup() {
  Serial.begin(115200);
  
  pinMode(5, OUTPUT); //D1 is GPIO 5 (Relay ACS RELE IN3)
  pinMode(4, OUTPUT); //D2 is GPIO 4 (VUOTO RELE IN4) this is the relay on which to bridge
  digitalWrite(5, HIGH); //Set GPIO 14 LOW
  digitalWrite(4, HIGH); // Set GPIO 13 LOW

pinMode(14, OUTPUT); //D5 is GPIO 4 (Cancello Piccolo RELE IN2)
  pinMode(13, OUTPUT); //D7 is GPIO 13 (Cancello Grande RELE IN1)
  digitalWrite(14, HIGH); //Set GPIO 14 LOW
  digitalWrite(13, HIGH); // Set GPIO 13 LOW
 
  Blynk.begin(auth, ssid, pass);
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("bbbbbbbbbb"); // Token of the Device B
 
}

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

Code Device B

//Device B:

#include <OneWire.h>
#include <DallasTemperature.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

WidgetBridge bridge1(V2); //Initiating Bridge Widget on V1 of other Device

#define ONE_WIRE_BUS 2 //pin connected to DS18B20 Sensor(s) D4 on NodeMCU

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor; //pin SCL (D1)---SDA (D2)



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

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

BlynkTimer timer;

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.


  

sensors.requestTemperatures(); // Send the command to get temperatures

float temp1 = sensors.getTempCByIndex(0);
  Serial.print("Temperatura Sonda Caldaia °C: ");
  Serial.println(temp1);
 
  Blynk.virtualWrite(V10, temp1); //BLYNK Value Display set to Virtual Pin 10


  Serial.print("Livello Serbatoio in Cm: ");
  Serial.print(sensor.readRangeContinuousMillimeters()/10); // /10 serve per fare convertire in cm 
  delay(3000);

  Serial.println();

  float serb = (sensor.readRangeContinuousMillimeters()/10);

  int y = map(serb, 8, 87, 100, 0); // valori di percentuale Min 6 - Max 82 , 100 Max 0 Min

  //unsigned long temp = (sensor.readRangeContinuousMillimeters()); //per errore 6553

  //if(temp!=65535) serb=temp/10.0;


  

  Blynk.virtualWrite(V0, y); //Virtual Pin Label 
  Blynk.virtualWrite(V1, serb);    //Virtual Pin Level H
}




void setup()
{
Serial.begin(115200);

  pinMode(13, OUTPUT); //D7 is GPIO 13 
  
  digitalWrite(13, LOW); // Set GPIO 13 LOW
  
Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  
  timer.setInterval(10000L, myTimerEvent); //Ritardo di lettura in millisecondi di tutti i sensori (10s)




  Serial.begin(115200);
  Wire.begin();

  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous(3000); //Ritardo di lettura del sensore in ms (3s)
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("aaaaaaaaaa"); // Token of the Device A
}

BLYNK_WRITE(V2) { // Remote LED
  bridge1.virtualWrite(4, HIGH); // take the state of the Button and send it to the Remote LED
}

void loop()
{
  

  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  
}

how would you like my code ??? Can it work ???

probably not…

You have setup DeviceA as if you want to control something on DeviceB… but then never do.

And on DeviceB you are setup with virtual button(V2) to control a V4 pin on DeviceA… but two problems with it…

  1. it will only ever set V4 HIGH, never LOW

  2. but since you don’t even have a Blynk Function for V4 on DeviceA… nothing will happen anyhow.