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.
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
#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”;
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>
#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
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.
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.
@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 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.