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);
}
}