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

Can't read temperature DS18b20


#1

Hi.
I’m trying to create a simple project to read the temperature. But I’m receiving the value: -127
I’m using esp-01, I have connected 3 pins: 3.3 V, ground, GPIO0.
The code is following:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TimeLib.h>
#include <SimpleTimer.h>
#define ONE_WIRE_BUS 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

char auth[] = "";

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "1TP1", "astoria!");

  sensors.begin();

  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
}

void sendTemps()
{
  sensors.requestTemperatures(); // Polls the sensors

  float tempBabyRoom = sensors.getTempCByIndex(0); // Gets first probe on wire in lieu of by address

  Blynk.virtualWrite(4, tempBabyRoom);
}

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

Please advice, what I am doing wrong.


#2

Without delving into code too much… Try to use the only really freely available pin on ESP-01 (the GPIO2) and do not forget about pull-up resistor on DIO line. The GPIO0 might be used, but with some care taken as it is used as a bootloader pin.

Also… I’m always using the “V4”, not just “4” for virtual pin assigning. Not sure if the “4” alone can be used equivalently


#3

I have an ESP-01 running a DHT12 (GPIO3), a DS18B20 (GPIO2) and controlling a RGB LED Ring (GPIO0)… so a few more then just one pin usable. :smiley:

I use OTA for any programming, but it is also wired for a TTL-USB adapter in case I goof up the OTA.

I use GPIO2 for my DS18B20 and I power mine via the parasitic method. My particular sensor wants the 5v line in order to function (@DoMoney - that might be your issue as well?) , but since it is feeding through a 4.7K resistor there is no concern.

// DS18B20 Sensor setup
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float DS18B20Temp;
timer.setInterval(60000L, DS18B20TempSensor);
void DS18B20TempSensor() { // DS18B20 sensor reading
  DS18B20.requestTemperatures();
  delay(500);  // Yes, I use a short delay... no problems in this case ;)
  Blynk.virtualWrite(V3, DS18B20.getTempCByIndex(0));
}

As a neat trick, I even have an LED (white - no resistor) across the data and 3.3v line… so it actually pulses quickly everytime the temperature is reading.


#4

The GPIO1, as the last one too… Although a LED is connected here, but it works as a GPIO - if you know how to handle them all. :rofl:


#5

Yep, I actually have messed with GPIO1 as well… it is one pimped out ESP-01 :sunglasses:. The sketch is set with pinMode(1, OUTPUT); and I have done sophisticated things (OK, just blinked another LED :stuck_out_tongue: ) But as it is wired to my TTL socket, I don’t do anything permanently with it… besides, I am already overloading the PSU with the RGB Ring :zap:

Although looking at it closer I forgot I had downgraded to a DHT11… and a burnt out RGB… poor ESP :disappointed_relieved:


#6

Yes, he problem was in V4. Thanks a lot for your help.