Problems using DS18B20 waterproof temperature sensor with Blynk

Hi

I am using a DS18B20 waterproof temperature sensor in my project. I am also using other sensors which work fine with blynk but the temperature sensor wont seem to work. When i run the below code the serial monitor shows that it is connected to blynk but it wont run the getTemperature command every 5 seconds. Is there anyone who has used this sensor with Blynk before? I am using an Arduino Uno rev3 board with an ESP8266 wifi shield.



// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPL7mLWZCzi"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "SQKj9qqAVwTsrLHimtkkdvSPMFuj8Ss_"


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Tenda_3165"; //"VODAFONE-6360";     //"Tenda_3165";
char pass[] = "JDwRadYk"; //"tYsx6nsxx946KAKf";     //"JDwRadYk";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2,3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

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

#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

 float Celcius=0;

int DesiredTemperature = 25;

BLYNK_WRITE(V1)
{
  DesiredTemperature = param.asInt();
 
}
void getTemperature()
{
   sensors.requestTemperatures(); 
  Celcius=sensors.getTempCByIndex(0);
  Serial.print(" C  ");
  Serial.println(Celcius);
   Serial.print("Desired Temp ");
  Serial.println(DesiredTemperature);
}

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

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN,wifi, ssid, pass);


  timer.setInterval(5000L, getTemperature);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Have you tried the same sketch without the Blynk.begin and Blynk.run commands to prove that communication with the sensor is working as expected?

How are you powering your ESP-01 and your sensor?

Pete.

Hi Pete,

Yes i have tried that and they work.

I have done research and found that other people are having trouble using the Wire library and Blynk together. My code works perfectly with other sensors that don’t use the wire library. I don’t know if you have found this problem before?

No, I haven’t.

Pete.

Have you tried to access the ‘getTemperature’ routine outside of the ‘timer’ routine.

In uPython I found that the issue with calling Blynk management routines with the Wi-Fi on cause no/false triggers and issues in some cases, something to do with the “priorities” within the ESP devices, test it in the following way first to see if this is the case:

  1. Disable all Wi-Fi connections, so run it as a basic microcontroller
  2. Run your routine and see if you getting the temperature readings
  3. if this is the case, suggested work around below

create a Timer Flag and then check the flag and use the ‘getTemperature’ when it is set.

example:

int TempFlag = 0

void manageTemperature
{
     TempFlag = 1;
}

// then place this in your code
if TempFlag ==1
{
    getTemperature()
}