Ds18b20 blynk edge

Good, I need help with a problem using Blynk.edge. (Blynk iot Pro with the latest updated version, I use ESP 32, Arduino IDE 1.8.16. Here’s the situation: I use several ds18b20 sensors connected parasites to pin 16 of esp 32, measuring the temperature and sending it to several virtual pins on Blink IOT .
My problem is to associate by code, each sensor separately by the hexadecimal code that I have already identified to a virtual pin of blyn iot.
The code that I will put below is an example that I use, but the sensors enter without identification, that is, when one takes the place of the other, for a connected sensor it works, but when you place many sensors I have many problems.
Anyone who can help would be greatly appreciated!
example associate these addresses to virtual pins , by blynk.edge
Printing Address
Sensor 1: 0x28, 0x5E, 0x7C, 0x07, 0xB6, 0x01, 0x3C, 0x5D
Sensor 2: 0x28, 0xAA, 0x1B, 0x22, 0x50, 0x14, 0x01, 0x04
Sensor 3: 0x28, 0xAA, 0xD1, 0x22, 0x50, 0x14, 0x01, 0x9B

#define BLYNK_TEMPLATE_ID " xxxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxxxx"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"

#include <DallasTemperature.h>
#include <OneWire.h>

const int oneWireBus = 16; 
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
void getTemperature() 
{
   sensors.requestTemperatures();
    float temperatureA = sensors.getTempCByIndex(0);
    float temperatureB = sensors.getTempCByIndex(1);
    float temperatureC = sensors.getTempCByIndex(2);
    Blynk.virtualWrite(V11, temperatureA);
    Blynk.virtualWrite(V12, temperatureB);
    Blynk.virtualWrite(V13, temperatureC);
    
  
}
void setup()
{
 Serial.begin(115200);
  BlynkEdgent.begin();
  timer.setInterval(1000L, getTemperature); 

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

@Frederico Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

Thanks SR Pete, I’m new to the Forum, I think I fixed it right?

No, I gave you triple backticks to copy/paste, but you’ve used different characters instead.
Also, the triple backticks need to be on a line of their own.

In addition, you seem to be missing part of your sketch.

Pete.

Thanks again for your attention, I think I copied and pasted the backticks on separate lines.

You seem to be missing sensors.begin(); from your void setup.

Adding-in some serial print statements would also help you with your debugging.

This topic might help you if you’re still struggling…

Pete.

Mr Pete, I can make it work on the monitor, but I can’t see the value in blynk, I’m still analyzing the examples that you sent me, I’m going to do other tests with the examples that you gave me, and test. I can contact you again, if I need to mature more… thank you very much!
This example below does not work, but it would be similar, I would not need to see it on the monitor, I just need to send it to blink, each sensor separately by address

#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 16



BlynkTimer timer;


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

DeviceAddress insideThermometer = { 0x28, 0x5E, 0x7C, 0x07, 0xB6, 0x01, 0x3C, 0x5D };
DeviceAddress2 outsideThermometer = { 0x28, 0xAA, 0x1B, 0x22, 0x50, 0x14, 0x01, 0x04 };

void getTemperature(DeviceAddress deviceAddress) 
{

  Blynk.virtualWrite(V1, deviceAddress);
 Blynk.virtualWrite(V2, deviceAddress2);

 
    
    
  }   


void setup(void)
{
  Serial.begin(115200);
  BlynkEdgent.begin();
  sensors.begin();
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  
}

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

How have you configured your V11, V12 and V13 datastreams used by your first example, especially the Min and Max values?
What widgets do you have attached to these datastreams, and how are they configured?

How have you modified your original code to add-in the serial print commands, and what results do you see in your serial monitor? (Post the serial output by copying & pasting the text, with triple backticks, not as a screenshot).

Pete.

Solved, thanks PETE, I don’t know if the code is clean and the best possible, but it’s working very well…

#define BLYNK_TEMPLATE_ID "xxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxxx"



#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"

#include <DallasTemperature.h>
#include <OneWire.h>

const int oneWireBus = 16; 
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor001 = { 0x28, 0x5E, 0x7C, 0x07, 0xB6, 0x01, 0x3C, 0x5D};
DeviceAddress tempSensor002 = { 0x28, 0xAA, 0x1B, 0x22, 0x50, 0x14, 0x01, 0x04 };
DeviceAddress tempSensor003 = { 0x28, 0xAA, 0xD1, 0x22, 0x50, 0x14, 0x01, 0x9B };
float temperature001;
float temperature002;
float temperature003;

BlynkTimer timer;



void sendSensor()
{
  sensors.requestTemperatures();                  
  temperature001 = sensors.getTempC(tempSensor001);  
  temperature002 = sensors.getTempC(tempSensor002); 
  temperature003 = sensors.getTempC(tempSensor003); 
  Blynk.virtualWrite(V11, temperature001);  
  Blynk.virtualWrite(V12, temperature002);  
  Blynk.virtualWrite(V13, temperature003);      
}


   
  
   


void setup()
{
  Serial.begin(115200);
   BlynkEdgent.begin();
   sensors.begin();                        
  sensors.setResolution(tempSensor001, 10); 
  sensors.setResolution(tempSensor002, 10); 
  sensors.setResolution(tempSensor003, 10); 
  timer.setInterval(500L, sendSensor);            
 
    
}

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

Why do you need to check the three temperature reading twice per second?
How much do you think the temperature will have changed during that time?

Pete.

1 Like

I changed it to 1.5 seconds to read the 3 temperatures, thanks.
My Datastreams are configured to read -20 to 40 degrees C. I am having values ​​on the ds18b20 sensors of 28.9° C ambient, a difference of ± 0.25 to 0.50 between each of them. I’m not having readings on the IDE monitor, I thought I didn’t need it, since the interest was to upgrade to blynk 2.0. In addition to the Dsb1820, I have the DHT22, door sensors, in the same equipment.

Even with sensor readings within the 0.5 range of difference, when I compare with 2 thermometers I have here, I have a difference of 1.5° c , compared to other thermometers. Is there any way to fix these values ​​by code? Thank you one more time!

My comments regarding these suggest were aimed at identifying potential issues on your part, and giving you a way of checking if the sensors were being read correctly, or whether the issue was the way you’d configured Blynk.

Yes, just Google how to calibrate these sensors and incorporate the calibration code into your sketch.

Pete.

1 Like

Entendi Pete, obrigado!