BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Wemos ESP8266 Standalone D1-R2 / DS18B20


#1

Hi , i was looking for an example of a sketch for Temp Sensor DS18B20 with a Wemos D1-R2 on Blynk ?
I have no idea how to write code but have used the basic sketches to automate all my lighting .
i cant work out how to add a temp sensor to a project.
Could i just cut and paste the required code (OneWireHub & DallasTemperature )to the ESP8266 standalone sketch that Im already using and add the appropriate widget on the app or is that a bit of wish full thinking ?
Any help would be greatly appreciated.
Dave


#2

Basically, yes - you can.
The thing you have to watch out for is to ensure that you don’t take temperature readings too often and that you don’t use delay() in your code to slow-down those readings.
Use a timer to call (say every 5 seconds or more) the function that takes a temperature reading and uploads the result to Blynk so that it can be viewed in a display widget.

Pete.


#3

Hi pete
Thanks for the reply,
Could you help with where in the existing sketch i would add the additional code for the temp sensor ?
I have tried for a while with no success.

regards
Dave


#4

If you click the magnifying glass symbol at the top of the page, type “DS18B20” then hit return, you’ll get over 100 search results from this forum.
Your answer lies in these results, and the more you read, the more you’ll learn.

Pete.


#5

Thanks for that Pete


#6

Hi Pete ,
I was hoping you might have time to help me with this project ?
I managed to get as far as reading the temps in the serial monitor and connecting the Wemos to Blynk.
(See Below)
So now i imagine i just need to write the temp to a virtual pin matching a widget on my phone in the Blynk app ?Probably a simple task for an experienced person , but its taken me 2 days just to get here. Using Blynk with
Digital pins is fairly easy ,but a whole different situation when it comes to modifying code .
I am however enjoying the challenge.

Regards
Dave


#define BLYNK_PRINT Serial

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxx”;
char ssid[] = “xxxxxxxxxxxxxx”;
char pass[] = “xxxxxxxxxx”;

#define ONE_WIRE_BUS 4


OneWire oneWire(ONE_WIRE_BUS);

 
DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = {0x28, 0xFF, 0x7D, 0x8B, 0xB5, 0x16, 0x05, 0x74  };;
 

void setup(void)
{
  
  Serial.begin(9600); 
  Blynk.begin(auth, ssid, pass);
  Serial.println("Dallas Temperature IC Control Library Demo");
  
 
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  
  sensors.setResolution(insideThermometer, 9);
 
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();
}
    void printTemperature(DeviceAddress deviceAddress)
{
    float tempC = sensors.getTempC(deviceAddress);
    Serial.print("Temp C: ");
    Serial.print(tempC);
    Serial.print(" Temp F: ");
    delay (1000);
    Serial.println(DallasTemperature::toFahrenheit(tempC)); 
  }
  
    void loop(void)
  { 
   Blynk.run();
    Serial.print("Requesting temperatures...");
    sensors.requestTemperatures(); 
    Serial.println("DONE");
    
    
    printTemperature(insideThermometer); 
    delay (1000);
  }
  
  // function to print a device address
     void printAddress(DeviceAddress deviceAddress)
  {
    for (uint8_t i = 0; i < 8; i++)
    {
      if (deviceAddress[i] < 16) Serial.print("0");
      Serial.print(deviceAddress[i], HEX);
   
    }
  }

#7

Please properly format all posted code as per the Welcome Topic instructions.


Blynk - FTFC


#8

Done , sorry about that
Dave