logo elektroda
logo elektroda
X
logo elektroda

How to connect two independent DS18B20 probes?

zkz-zg 486 2
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19948910
    zkz-zg
    Level 9  
    Hello.
    I have a problem with connecting 2 independent DS18B20 probes.
    The whole thing is on the plugs and the LCD.
    When there are two, it's ok, when I unplug one, the top one remains on the LCD, when I unplug the second one and plug in the first one, the top one also remains on the LCD.
    So I can swap sensors and the LCD will show the opposite.
    Is there an option to connect them separately, each in a different port and how to define this in the code?

    #define D1 5
    #define D2 4
    #define D3 0
    OneWire oneWire(0);
    DallasTemperature sensors(&oneWire);
    void loop() {

    sensors.requestTemperatures();
    float TEMP1 = sensors.getTempCByIndex(0);
    float TEMP2 = sensors.getTempCByIndex(1);

    Thank you for your help
  • ADVERTISEMENT
  • #2 19949086
    sigwa18
    Level 43  
    Give the whole code and not a fragment.
  • #3 19949168
    zkz-zg
    Level 9  
    sigwa18 wrote:
    Give the whole code, not a fragment.

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <ESP8266WiFi.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <BlynkSimpleEsp8266.h>
    #include <Timers.h>
    
    #define BLYNK_PRINT Serial
    #define D1 5 
    #define D2 4 
    #define D3 0 
    #define D4 2 
    #define treconnect 30 
    
    float tempC = 0;
    int liczreconnect = 10;
    
    char auth[] = "xxx"; //Blynk
    char ssid[] = "xxx"; //Sieć
    char pass[] = "xxx"; //Hasło
    
    
    LiquidCrystal_I2C lcd(0x27, 20, 2);
    OneWire oneWire(0);
    DallasTemperature sensors(&oneWire); 
    Timers <3> akcja;
    
    BlynkTimer timer;
    
    int stanLED_ok=0;
    int LED;
    
    
    void setup()
    {
    
    //akcja.attach(0, 1000, testconnect); //timer 1 sek
    WiFi.begin(ssid, pass);
    Blynk.config(auth, "blynk-cloud.com", 8442);
    
    Blynk.connect();
    if (Blynk.connected()) Blynk.run(); else Blynk.connect();
    
      
    Serial.begin(9600);
    lcd.backlight();
    sensors.begin();
    lcd.init();
    lcd.clear();
    Serial.println(LED);
    timer.setInterval(1000L, temp);
    
    }
    
    void temp()
    {
    stanLED_ok = !stanLED_ok;
    if (stanLED_ok == 0) {
    Blynk.virtualWrite(10,255);Blynk.setProperty(V10,"color","#D3435C");
    }
    else {
    Blynk.virtualWrite(10,255);Blynk.setProperty(V10,"color","#04C0F8");
    }
    //Blynk.syncAll();
    }
    
    void loop() {
    
    sensors.requestTemperatures();
    float TEMP1 = sensors.getTempCByIndex(0);
    float TEMP2 = sensors.getTempCByIndex(1);
    
    lcd.setCursor(0, 0);
    lcd.print("Pokoj 1");
    lcd.setCursor (10, 0);
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print((char)223);
    lcd.print("C");
     
    lcd.setCursor(0,1);
    lcd.print("Lazienka");
    lcd.setCursor (10, 1);
    lcd.print(sensors.getTempCByIndex(1));
    lcd.print((char)223);
    lcd.print("C");
    
    
    Blynk.run();
    Blynk.virtualWrite(V1, TEMP1);
    Blynk.virtualWrite(V2, TEMP2);
    
    
    delay(30);
    
    akcja.process(); //timer Timers.h
    if (Blynk.connected()) {
    Blynk.run();
    }
    timer.run();
    }
    void testconnect()
    {
    if (Blynk.connected()) {
    liczreconnect = treconnect;
    } else {
    liczreconnect--;
    if (liczreconnect==0) {
    Blynk.connect();
    liczreconnect = treconnect;
    .
ADVERTISEMENT