Temperature sensing with Dallas 18B20 and blynk

Perhaps a simple question but i need to ask. Do I need to add additional libraries to my sketch to be able to read the data from this sensor?

Im using blynk and I am able to turn on an LED with my android (samsung S7), but i cannot get the “guage” widget to work.
Ive connected the temp sensor (18B20) to gnd, 3.3v, and pinD2 respectively and set the “guage” widget to virtual Pin V6.

Any help is appreciated.

Thanks in advance

Paul S

If you don’t have the DS18B20 libraries you will not get any data.
Search Google for “Arduino DS18B20” and then mod the sketch for use with Blynk

Or you can use the search at this forum, read below post:

Thank you, I now have onewire and dallastemperature libraries.

Here is what I have for sketch, but it will not upload. compiler error.
/**************************************************************

  • Blynk is a platform with iOS and Android apps to control
  • Arduino, Raspberry Pi and the likes over the Internet.
  • You can easily build graphic interfaces for all your
  • projects by simply dragging and dropping widgets.
  • Downloads, docs, tutorials: http://www.blynk.cc
  • Blynk community: http://community.blynk.cc
  • Social networks: http://www.fb.com/blynkapp
  •                           http://twitter.com/blynk_app
    
  • Blynk library is licensed under MIT license
  • This example code is in public domain.

  • This example runs directly on ESP8266 chip.
  • You need to install this for ESP8266 development:
  • https://github.com/esp8266/Arduino
  • Please be sure to select the right ESP8266 module
  • in the Tools -> Board menu!
  • Change WiFi ssid, pass, and Blynk auth token to run :slight_smile:

**************************************************************/

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

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

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “xxxxxxx”;
char pass[] = “xxxxxxx”;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}

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

@psutton,
Did you check my post? The code is there, have a look…
On the other hand…Code snippet should be formatted. Edit your post!

My apologies for bad snipping. I am reviewing your code now. I am trying to incorporate it with my existing code.
thanks for your help

@psutton are you using an ESP, Arduino or something else?

This link will show you how to post code on the forum so we can read it [README] Welcome to Blynk Community!

i am using an esp8266 and programming with Arduino IDE 1.6.12.
thanks i will review how to post code.

I’ll just pile on with what I typically start with:

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

#define ONE_WIRE_BUS 2          // This is the ESP8266 pin (WeMos D1 Mini in my case)
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[] = "xxxxxxxxxxxxxxxxxxxxxxx";

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


SimpleTimer timer;

int roomTemperature;            // Room temperature in F

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

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

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

  timer.setInterval(2000L, sendTemps);    // Temperature sensor "polling" interval.
}

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

void sendTemps()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  roomTemperature = sensors.getTempFByIndex(0);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(1, roomTemperature);         // Send temperature to Blynk app virtual pin 1.
}

try this again. arduino IDE gets error and cant compile

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

#define ONE_WIRE_BUS 2          // This is the ESP8266 pin (WeMos D1 Mini in my case)
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[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

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


SimpleTimer timer;

int roomTemperature;            // Room temperature in F

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

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

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

  timer.setInterval(2000L, sendTemps);    // Temperature sensor "polling" interval.
}

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

void sendTemps()
{
  sensors.requestTemperatures();                  // Polls the sensors.
  roomTemperature = sensors.getTempFByIndex(0);   // Stores temperature. Change to getTempCByIndex(0) for celcius.
  Blynk.virtualWrite(1, roomTemperature);         // Send temperature to Blynk app virtual pin 1.
}
```cpp

This is the error message from IDE

In file included from C:\Users\admin\Documents\Arduino\ESP8266_temp_all_included\ESP8266_temp_all_included.ino:32:0:

C:\Users\admin\Documents\Arduino\libraries\OneWire/OneWire.h:77:2: error: #error “Please define I/O register types here”

#error “Please define I/O register types here”

The compiler is indicating 2 errors, line 32 in your sketch and a problem with the OneWire library.

Did you use the Library recommended by @psoro?

You can comment out the while loop from lines 32 to 34 as Blynk recently made Blynk.begin() a blocking function so the while loop is no longer required. Maybe they removed the Blynk.connect() function but I don’t think they have.

http://www.pjrc.com/teensy/arduinolibraries/OneWire.zip
link @psoro referred to doesnt work, regardless i researched http://www.pjrc.com and found the correct reference but still no link. This reference directed me to Paul Stoffregen’s rendition. I used that one.

I also commented out the While loop on line 32 and still no change. compiling error is the same. Perhaps if you could direct me to a onewire library i could try that.

BTW am grateful for any guidance you have provided thus far and hope you can bare with me

@psutton the sketch you have compiles just fine on my machine and I have 1.6.12 too.

You said you were able to do the basic blink an LED with Blynk so I am assuming you have added the Arduino core for the ESP etc.

Did you install all 6 “Blynk” libraries manually as per the docs as I’m not convinced that the automatic method is 100% operational from the IDE? One of the 6 libraries is Simple Timer which is not used in the basic ESP standalone sketch. So you can turn an LED on and off with just the single Blynk library but you can’t do much more, hence the total package is 6 libraries including time and gsm stuff etc.

That said the 2 extra libraries of One Wire and DS18B20 libraries can normally be added via the IDE.

I will check to see what versions I am using and take a look at some of the links for the libraries that appear in this thread.

@psutton Ok I think there is a onewire library adapted for ESP.

Might be worth you closing the IDE and removing Dallas and One Wire.

Go back into the IDE and enter OneWire in the library search. Mine shows version 2.3.2 and includes Paul Stoffregen’s (of Time library fame) in the spiel.

If you search the IDE library for DS18B20 you should be able to pick the Dallas one. Mine is shown as version 3.7.6.

I am always a little slow at updating libraries as I like others to find the bugs before I make the switch :slight_smile: So 2.3.2 and 3.7.6 may have progressed a little and should be fine to use the latest versions as I haven’t read of any bugs.

Wherever possible it is best to install via the IDE (not Blynk yet AFAIK) as the IDE knows you are using an ESP and offers you the correct library rather than a standard Arduino equivalent.

@psoro and other ESP users can you please advise the version numbers of 1-Wire and DS18B20 that you have in your IDE.