ESP8266 multi DS18B20

Hi community !

I run sketch for read DS18B20 on esp8266. It’s ok all good, chart, value on app.

Now i want add another DS18B20. What’s the way for this ?
I’ve to plug both to D4 with onewire ? In this case i need to finds DS18B20 adress ?
Or there’s other method ?

Maybe i can add :

  • int outdoorTemperature
  • Blynk.virtualWrite(2, outdoorTemperature);

But how to know wich is wich ?

my sketch :

    #define BLYNK_PRINT Serial
    #include <SimpleTimer.h>           // Allows us to call functions without putting them in loop()
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <OneWire.h>
    #include <DallasTemperature.h> 
    #define ONE_WIRE_BUS 2          // Your ESP8266 pin (ESP8266 GPIO 2 = WeMos D1 Mini pin D4)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);

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

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

    SimpleTimer timer;

    int roomTemperature;            // Room temperature in F

    void setup()
    {
      // Debug console
      Serial.begin(9600);

      //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,xx), 8080);

        while (Blynk.connect() == false) {
        // Wait until connected
    }

    sensors.begin();                        // Starts the DS18B20 sensor(s).
      sensors.setResolution(10);              // More on resolution: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/

      timer.setInterval(1000L, sendTemps);    // Temperature sensor read interval. 1000 (ms) = 1 seconds.
    }

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

    // Notice how there are no delays in the function below? Blynk works best that way.
    void sendTemps()
    {
      sensors.requestTemperatures();                  // Polls the sensors.
      roomTemperature = sensors.getTempCByIndex(0);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
      Blynk.virtualWrite(1, roomTemperature);         // Send temperature to Blynk app virtual pin 1.
    }

void loop()

Thakns

Google is your friend…

Pete.

Ok i’ve it but for :

I’ve to write

  • int sensor 1 : 0x28, 0xFF, 0x87, 0xCB, 0x89, 0x16, 0x03, 0x37
  • int sensor 2 : 0x28, 0xFF, 0x0F, 0x6E, 0xA2, 0x16, 0x04, 0x3C

and

  • Blynk.virtualWrite(2, sensor 1 : 0x28, 0xFF, 0x87, 0xCB, 0x89, 0x16, 0x03, 0x37 );
  •  Blynk.virtualWrite(3, sensor 2 : 0x28, 0xFF, 0x0F, 0x6E, 0xA2, 0x16, 0x04, 0x3C
           );
    

?

This don’t work.

Arduino : 1.8.9 (Windows 10), Carte : "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled (new can abort), All SSL ciphers (most compatible), 4MB (FS:none OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

DS18B20_TEST_MULTI_sketch:56:1: error: 'x3Cvoid' does not name a type

 int sensor 1 : 0x28, 0xFF, 0x87, 0xCB, 0x89, 0x16, 0x03, 0x37

 ^

DS18B20_TEST_MULTI_sketch:56:12: error: expected initializer before numeric constant

 int sensor 1 : 0x28, 0xFF, 0x87, 0xCB, 0x89, 0x16, 0x03, 0x37

            ^

exit status 1
'x3Cvoid' does not name a type

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

In C++ you cannot use variable names like “Sensor 1”

You should use something like “Sensor1”, “Sensor_1” or “Sensor_1” although standard variable naming convention dictates that these variable names should really begin with a lower case letter, so “sensor1”, “sensor_1” or “sensor_1” are better.

Pete.

Don’t forget the awesome power of the Blynk Forum Search Function! :wink:

Of course not! :stuck_out_tongue:

I’ve posted a lot about the DS18B20 over the years. This one might give you a better sense on how to use multiple sensors (ignore the stuff I wrote about EEPROM, the statement is wrong in this context):

Do you get decimal reading in your app?!

So, i start propely with this tutorial : https://www.instructables.com/Blynk-Arduino-Multiple-DS18B20-Thermometer-Display/

I’ve problem :

  • 1 same temperature on both ( no changing, if i start to 20° it’s stay to 20° )
  • 2 alltime changing since ( for exemple ) 16 to 85
  • 3 i unplegged one the other work but same like problem number 2

I don’t understand what happened. It’s same code than tutorial

Thanks

No it’s with one DS18B20 not for multiple :stuck_out_tongue:

That code is stupid - don’t use it! I actually cant understand how the author got that code to work!?

The void loop() contains two delays that basically halts everything for 1,25 seconds, and all of the Blynk.virtualWrite() commands. Both are a big NO NO if you read the Blynk documentation!

Also, his approach to fetch the readings from the sensors are very awkward. There is much easier ways to do it.

Search the forum and you will probably find all the answers to your questions.

If you want to access your sensors by their unique ID, use a simple program to first identify them and write down their individual ID. Something like this:

You misunderstood me! :slight_smile:

roomTemperature should be declared as a float datatype because <DallasTemperature.h> returns a floating-point number i.e. one with decimals (like 27,35). When you declare it as an int you loose the decimals (27,35 will be just 27).

Good luck!

Ok, thank’s for this precious information ! :slight_smile:

I find another one we work with 2 sensor but not 3 :

#include <SimpleTimer.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor001 = { 0x28, 0xFF, 0x3A, 0xD4, 0x89, 0x16, 0x03, 0x36 };
DeviceAddress tempSensor002 = { 0x28, 0xFF, 0xD7, 0x22, 0x8A, 0x16, 0x03, 0x9C };
DeviceAddress tempSensor003 = { 0x28, 0xFF, 0x0F, 0x6E, 0xA2, 0x16, 0x04, 0x3C };


char auth[] = "4nzu0s_J-6xz4t9bFVWmMGmERx7OaryA";
char ssid[] = "Livebox-83CB";
char pass[] = "azeqsd123";

SimpleTimer timer;

int temperature001;
int temperature002;  // Variables for storing temperatures
int temperature003;

void setup()
{
  // Debug console
  Serial.begin(9600);

  //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,52), 8080);

    while (Blynk.connect() == false) {
    // Wait until connected
}

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);
  timer.setInterval(500L, sendSensor001);
  timer.setInterval(500L, sendSensor002);
  timer.setInterval(500L, sendSensor003); // Temperature sensor read interval. 1000 (ms) = 1 seconds.
}

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


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

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

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

It give me :

\\192.168.1.3\public\stockage\Utilitaire Raspberry\Arduino\DS18B20_MULTI_v2\DS18B20_MULTI_v2.ino: In function 'void setup()':

DS18B20_MULTI_v2:47:27: error: 'sendSensor003' was not declared in this scope

   timer.setInterval(500L, sendSensor003); // Temperature sensor read interval. 1000 (ms) = 1 seconds.

                           ^

\\192.168.1.3\public\stockage\Utilitaire Raspberry\Arduino\DS18B20_MULTI_v2\DS18B20_MULTI_v2.ino: At global scope:

DS18B20_MULTI_v2:74:6: error: variable or field 'sendSensor003' declared void

 void sendSensor003

      ^

DS18B20_MULTI_v2:76:32: error: expected '}' before ';' token

   sensors.requestTemperatures();                  // Polls the sensors.

                                ^

DS18B20_MULTI_v2:77:3: error: 'temperature003' does not name a type

   temperature003 = sensors.getTempC(tempSensor003);   // Stores temperature. Change to getTempCByIndex(0) for celcius.

   ^

DS18B20_MULTI_v2:78:3: error: 'Blynk' does not name a type

   Blynk.virtualWrite(6, temperature003);         // Send temperature to Blynk app virtual pin 1.

   ^

DS18B20_MULTI_v2:79:1: error: expected declaration before '}' token

 }

 ^

exit status 1
'sendSensor003' was not declared in this scope

It’s my first time with this code, and i’m happy to learn and do, it’s better ! And i’m also looking for coding with TSL2561 and esp8266.

Thanks a lot ! :slight_smile:

Spot the difference between the names of your functions…

Arduino doesn’t treat it as a function without the (), hence the error message.

Pete.

Ho, i’m stupid… thanks @PeteKnight

1 Like