Multi devices eventor

I don’t see why you’d need a different solution in this situation, as it’s simple enough to change two digitalWrite commands.

If you’re writing a sketch that might be used for active HIGH or active LOW relays and you have lots of DigitalWrite commands that would need to be changed then there are a few tricks you could use. The simplest is to do the following:

#define relay_on = 0  // set to 0 for Active LOW, 1 for Active HIGH
#define realy_off = 1  // set to 1 for Active LOW, 0 for Active HIGH

void my_function()
}
  if (h > 70)
  {
    digitalWrite(2, realy_off);
  }

  else
  {
    digitalWrite(2, relay_on);
  }
}

Or, if you have a Boolean variable that is being used to do the switching you can use the logical NOT operator (the exclamation mark - !) to do the inverse of the variable value,

The other thing to think about is that if your measured temperature is very close to the switching value of 70 it will almost certainly fluctuate very slightly - especially if you’re using a Float variable type where it could be 69.999 on one reading and 70.001 on the next - then your relay will switch on and off quite rapidly. This isn’t great if its switching a heavy load as it will cause contact arcing, and the device they you’re switching may not like being cycled this quickly. it can also be annoying if something like a boiler ort fan is constantly starting-up and switching off again as it hovers around the target temperature.

The solution is to use hysteresis, which de-sensitises the process by building-in a latitude to t6he temperature switching logic.
This isn’t really a Blynk related thing, but there are are a few examples on the forum, and many more on the internet if you want to go down that route.

Pete.

No matter, for is more easy to say HIGH = ON.

You read my mind ! I gonna see for this !

Another question, in my project y use 3 esp8266 and mulitple sensor. Wich is best way for proper wiring between esp and sensor. I’ve solder esp8266 and USB female on PCB, my sensor is USB male. But USB cables are stiff and difficult to put in place. Do you have better solution ?

I generally tend to design a custom PCB using the EasyEDA software and have it made by JLCPCB.com
I’ll usually use JST XH connectors, but if the items I’m connecting to the board have their own style of connector (RJ11, RJ45, USB-A etc) then I’ll sometimes stick with that and place suitable sockets on the PCB.
I also tend to design my PCBs to fit the type of housing that I want to use.
Its also a rule of mine never to solder MCUs Relays etc directly onto the PCB, I always use 0.1" header sockets to that I can quickly swap them out for replacements, or for bench testing.
I also tend to use Wemos D1 Minis rather than NodeMCU’s, as they are smaller form factor without any loss of useable pins.

Pete.

Gonna look for JST

I’ve problem wiht code i think. Blynk app all time notified me for deconnection and connection from ESP8266, but it look like runing correctly ( send me temperature and lux from sensor )
It’s also sometines blue LED speed blinking and not strong. Can you see if something was wrong on my code ? Thanks

//------------------------------------------------------------------------------------------------//DS18B20//
#include <SimpleTimer.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define BLYNK_PRINT Serial
#define ONE_WIRE_BUS 2 // Pin for ds18b20
//------------------------------------------------------------------------------------------------//DS18B20//

//------------------------------------------------------------------------------------------------//BRIDGE//
WidgetBridge bridge1(V0);
BLYNK_CONNECTED() {
  bridge1.setAuthToken("ZXNyOmxGYuFkReodok-DRIPaaYASbCE-"); // Token of the hardware B
}
//------------------------------------------------------------------------------------------------//BRIDGE//

//------------------------------------------------------------------------------------------------//DHT11//
#include <DHT.h>
#define DHTPIN 0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//------------------------------------------------------------------------------------------------//DHT11//

//------------------------------------------------------------------------------------------------//TSL2561//
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
//------------------------------------------------------------------------------------------------//TSL2561//

//------------------------------------------------------------------------------------------------//Blynk//
char auth[] = "eZxMQzut0LFnRRfEcSP5767RIScmlZlU";
char ssid[] = "xx";
char pass[] = "xxx";
//------------------------------------------------------------------------------------------------//Blynk//


//------------------------------------------------------------------------------------------------//DS18B20//
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
SimpleTimer timer;

DeviceAddress tempSensor001 = { 0x28, 0xFF, 0x3A, 0xD4, 0x89, 0x16, 0x3, 0x36 };
DeviceAddress tempSensor002 = { 0x28, 0xFF, 0xF, 0x6E, 0xA2, 0x16, 0x4, 0x3C };
DeviceAddress tempSensor003 = { 0x28, 0xFF, 0xD7, 0x22, 0x8A, 0x16, 0x3, 0x9C };
DeviceAddress tempSensor004 = {  };

int temperature001;
int temperature002;
int temperature003;
int temperature004;
//------------------------------------------------------------------------------------------------//DS18B20//



void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  while (Blynk.connect() == false) {

  }
//------------------------------------------------------------------------------------------------//DS18B20//
  sensors.begin();                           // Starts the DS18B20 sensor(s).
  sensors.setResolution(tempSensor001, 10);   // More on resolution: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
  sensors.setResolution(tempSensor002, 10);
  sensors.setResolution(tempSensor003, 10);
  sensors.setResolution(tempSensor004, 10);
  timer.setInterval(500L, sendTempSensor001);
  timer.setInterval(500L, sendTempSensor002);
  timer.setInterval(500L, sendTempSensor003);
  timer.setInterval(500L, sendTempSensor004);
//------------------------------------------------------------------------------------------------//DS18B20//


//------------------------------------------------------------------------------------------------//DHT11//
  dht.begin();
  timer.setInterval(1000L, sendDHTSensor);
//------------------------------------------------------------------------------------------------//DHT11//


//------------------------------------------------------------------------------------------------//TSL2561//
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);

Serial.println("");
  if(!tsl.begin())
  {
    Serial.print("No TSL2561 detected");
    while(1);
  }
//------------------------------------------------------------------------------------------------//TSL2561//



}

void loop()
{
//------------------------------------------------------------------------------------------------//Blynk//
  Blynk.run();
  timer.run();
//------------------------------------------------------------------------------------------------//Blynk//

//------------------------------------------------------------------------------------------------//TSL2561//
  sensors_event_t event;
  tsl.getEvent(&event);

  if (event.light)
  {
    Blynk.virtualWrite(V20, event.light);
  }
//------------------------------------------------------------------------------------------------//TSL2561//
}

//------------------------------------------------------------------------------------------------//DS18B20//
void sendTempSensor001()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  temperature001 = sensors.getTempC(tempSensor001);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(V10, temperature001);         // Send temperature to Blynk app virtual pin 1.
}

void sendTempSensor002()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  temperature002 = sensors.getTempC(tempSensor002);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(V11, temperature002);         // Send temperature to Blynk app virtual pin 1.
}

void sendTempSensor003()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  temperature003 = sensors.getTempC(tempSensor003);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(V12, temperature003); // Send temperature to Blynk app virtual pin 1
  bridge1.virtualWrite(V0, temperature003); 
  
}

void sendTempSensor004()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  temperature003 = sensors.getTempC(tempSensor003);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(V13, temperature003);         // Send temperature to Blynk app virtual pin 1.
}
//------------------------------------------------------------------------------------------------//DS18B20//

//------------------------------------------------------------------------------------------------//DHT11//
void sendDHTSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V21, h);
  Blynk.virtualWrite(V22, t);
}
//------------------------------------------------------------------------------------------------//DHT11//

Probably because you’re doing Blynk.virtualWrites in your void loop and spamming your local server.

Pete

Ok i’ve to create void only for virtualm write for fix it ?

As I’m sure you already know, your void loop should contain just…

Blynk.run();
timer.run();

Everything else should be in functions called with timers, and those timers should be a sensible frequency and not overlapping.

Pete.

Ok, best place is in setup i think

What do you mean exactly ?

My bad, there’s wrong ground… Sorry

I gonna try to explain…

I’ve my to devices : 1 - relay / 2 - sensor , with bridge between them. Dependent wich i strart first i’ve problem with them.

Exemple : if i restart relay devices i’ve blue led ( on devices 2 ) which is blinking quickly and no lot of power ( little blinking ) and no value on my sensor.

To fix it i’ve to change ground postition of DS18B20 on devices 2… Really i don’t understand at all…

I’m wondering if it would be better if you wrote in your own language and let us use Google translate or deepl, as I can’t understand what your problem is.
You clearly need to use many more words to explain the issue in much greater depth, but maybe it’s your lack of English that’s holding you back in this area?

Pete.

I will try to explain,

I have two devices which I call devices master (receiver) and diveces slave (sender). With a blynk bridge in between.

Depending on which one I start first I have a problem.

For example, if I restart the master device, the blue led of the second flashes quickly and shines little and I have no value from my temperature probes

To avoid this I noticed that if I change the pin ground of my temperature probes it fixes the problem.

I really do not understand

Sorry i will use the translator more often

Try taking a step back and looking at the questions and comments that you’ve asked and made within this topic.

Is it possible for anyone to look at the information available and make any sense of it?
Your latest example has no code relating to an LED, but you are using your OneWire bus on GPIO2, which is the pin that the onboard physical LED of a NodeMCU is connected to (poor choice of OneWire pin).
However, there is no reason to be running OneWire on the receiving device, as your sensors are connected to your sending device.

BTW, the sending device is usually referred to as the master, and the receiving device as the slave.

Then you have 4 timers all running every 500ms (far to fast in my opinion) and the timers will all try to execute at exactly the same time, rather than you staggering the timers so that they execute one after another.
But why are you using 4 timers at all? Why not have one function which reads each sensor in turn and pushes that sensor’s result to Blynk?

Then, you ask random questions about code dumped in your void loop, and when you’re told that the code should also be called with a time per you respond with a random statement about void setup, then don’t clarify that, then jump to a different question.

Your communication is all over the place, and written in a language that is almost incomprehensible.

I’m happy to try to help you, but I’m not going to keep asking you what your comments mean, and asking for clarification and receiving random comments in return.
If you wnat my help, your communication needs to be far more structured, comprehensive and explanatory than what I’m seeing from you at present - hence my suggestion to be more verbose in your native language.

I’ll take a step back from your questions until you start communicating in a way that I can understand.

Pete.

I totally understand. I am by nature quite confused and will try to remedy it because you are a great help to me.

With each of your answers I learn a little more. You don’t try to teach me, you teach me.
Without you I would still be in my infancy. AND I have come a long way from then this first post Blynk-client invalid token

These projects are important to me, it’s my only activity because of my health.

I spent my day restructuring and simplifying my codes so that they were readable and easy to study.

so from this problem I just changed the pins of my relay to avoid using the one wire.
All my project is working well so far.

Now that my probes are working and that the sensors divisions (MASTER) send the values ​​to the relay devices (SLAVE) your term of hysteresis interests me. Because indeed when the temperature varies between max and max - 0.5 the order and relight, sometimes every three seconds.
It is true that for some system the number of engagement can wear out the contactors prematurely.

I did some research on the internet without really finding an answer. From what I understand the hysteresis is just a value that represents n - x. But I can’t find how to implement it in my code

and here is my new code which is cleaner and more functional (well I think, if there is something to improve don’t hesitate to tell me!)

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
WidgetBridge bridge1(V0);
BLYNK_CONNECTED() {
  bridge1.setAuthToken("ZXNyOmxGYuFkReodok-DRIPaaYASbCE-");
}

//DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
DeviceAddress tempSensor1 = { 0x28, 0xFF, 0x3A, 0xD4, 0x89, 0x16, 0x3, 0x36 };
DeviceAddress tempSensor2 = { 0x28, 0xFF, 0xF, 0x6E, 0xA2, 0x16, 0x4, 0x3C };
DeviceAddress tempSensor3 = { 0x28, 0xFF, 0xD7, 0x22, 0x8A, 0x16, 0x3, 0x9C };
DeviceAddress tempSensor4 = {0x28,  0xFF,  0x87,  0xCB,  0x89,  0x16,  0x3,  0x37  };
int temperature1;
int temperature2;
int temperature3;
int temperature4;

//DHT11

#include <DHT.h>
#define DHTPIN 14
#define DHTTYPE DHT11  // DHT TYPE ( 21 / 22 )
DHT dht(DHTPIN, DHTTYPE);

//TSL

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  while (Blynk.connect() == false) {
  }
  //DS18B20
  sensors.begin();
  sensors.setResolution(tempSensor1, 10);
  sensors.setResolution(tempSensor2, 10);
  sensors.setResolution(tempSensor3, 10);
  sensors.setResolution(tempSensor4, 10);
  timer.setInterval(1000L, sendDS18B20);
  //DHT11
  dht.begin();
  timer.setInterval(1000L, sendDHT);
  //TSL2561
  timer.setInterval(1000L, sendTSL);
}

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

void sendDS18B20 ()

{
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  Serial.print("Temperature is: ");
  Serial.println(sensors.getTempC(tempSensor1));

  temperature1 = sensors.getTempC(tempSensor1);
  Blynk.virtualWrite(V10, temperature1);

  temperature2 = sensors.getTempC(tempSensor2);
  Blynk.virtualWrite(V11, temperature2);

  temperature3 = sensors.getTempC(tempSensor3);
  Blynk.virtualWrite(V12, temperature3);
  bridge1.virtualWrite(V0, temperature3);

  temperature4 = sensors.getTempC(tempSensor4);
  Blynk.virtualWrite(V13, temperature4);
}

void sendDHT()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  }

  else {
    Serial.println("DHT sensor OK");
  }

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V21, h);
  Blynk.virtualWrite(V22, t);
}

void sendTSL()
{

  sensors_event_t event;
  tsl.getEvent(&event);
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);

  Serial.println("");
  if (!tsl.begin())
  {
    Serial.print("No TSL2561 detected");
  }

  if (event.light)
  {
    Serial.print(event.light);
    Serial.println(" lux");
  }
  else
  {
    Serial.println("Sensor overload");
  }

  {
    Blynk.virtualWrite(V20, event.light);
  }
}

So the 50+ instances where it’s discussed in this forum didn’t help?…

https://community.blynk.cc/search?q=hysteresis%20

I’ve already mentioned the fact that you are reading your sensors to often, your timers are coinciding and that you don’t really need 3 timers anyway. Plus the fact that GPIO2 isn’t a great OneWire pin choice.

Pete.

That’s settled

Tomorrow I will continue to find out about the hysterise

   void relaisTemp()   //boucle temperature

{
  Serial.print(TempSom);
  Serial.println("°C");


  if (TempSom >= (MaxTemp + 1))
  {

    digitalWrite(relais1, LOW);
  }

  if else (TempSom <= (MaxTemp - 1))
  {
    digitalWrite(relais1, HIGH);
  }
}

Sound good? Seems like that just shifts the problem. The variations that existed between 29.9 and 30 are the same between 28.9 and 29

My system managing the cooling of a small volume when the extraction turns on I quickly fall below MaxTemp. Sometimes even several times in one minute. Wouldn’t be a good idea to add a delay of X seconds to avoid several starts in a row

I don’t understand where these numbers are coming from.

In you code snippet, if the target temperature (MaxTemp) is set to 30 degrees then the relay will go LOW at 31 degrees and HIGH at 29 degrees, giving a two degree latitude.

Pete.

So this is ok

I got confused… Sorry

For the rest I would like to make a programmer, is it a good idea to replace a mechanical programmer with one coded on an esp8266?