Wemos d1 + DS18b20 not working

Hi,
I try to make a ds18b20 sensor.

DS18b20 : red (vcc); Black (Gnd); Yellow (data) (I think this is correct).
So I plus red on 5v pin, Yellow on pin 2, Black on G pin.
I put a 4.7k resistor between Vcc and Data pin. (In fact two 10k in parallel, I have no 4.7k resistor)

I use this code :

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

#define ONE_WIRE_PIN D2

OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);

void setup()
{
Serial.begin( 9600 );
Serial.print( “Demo capteur de temperature DS18B20\n” );

// Démarre le processus de lecture.
// IC Default 9 bit. If you have troubles consider upping it 12.
// Ups the delay giving the IC more time to process the temperature
// measurement
sensors.begin();
}

void loop()
{
long t1 = millis();

// Requête de toutes les températures disponibles sur le bus
sensors.requestTemperatures();
// On ne garde que la première température (index = 0)
float Temp = sensors.getTempCByIndex( 0 );

long t2 = millis();
long dt = t2 - t1;

Serial.print( “t = " );
Serial.print( t2 );
Serial.print( " ms\t” );

Serial.print( “dt = " );
Serial.print( dt );
Serial.print( " ms\t” );

Serial.print( “T = " );
Serial.print( Temp, 1 );
Serial.print( " degC\n” );
}

My problem, is that the serial monitor shows me always temperature of -127 !! If I unplug all, it continues telling me -127 !!!
What’s wrong ?
I tried an another sensor ds18b20, and same issues.

Thank you for your help.

-127 is what you get when the MCU fails to communicate with the DS18B20.
Did you try another pin?
Post a picture of the setup.

VCC of a WeMos D1 (mini) is 3.3volt (ESP8266 is 3.3volt logic processor),
so the DS18B20 supply and the pull up resistor should be connected to the 3.3volt pin.

always use unsigned long for millis().
Leo..

same effect when I plug vcc3.3.
I already try another pin instead of d2 …

Hi davidmarli,

The DS18B20 is a very special sensor in the sense that every individual DS18B20 has its own identity (address). The device address of the DS18B20 that I used here is 0x28, 0xFF, 0xD7, 0x91, 0x92, 0x16, 0x04, 0x69 - belongs to one of my DS18B20s

You can find the particular device addresses of your DS18B20s with the sketch ‘DS18B20 address finder’ - search on the internet (e.g. hacktronics).

When you have a lot of temperature sensors attached to your Wemos through one wire (I have 10 to measure circulation water temperatures in floor heating loops) you simply call one of the DS18B20’s via its device address and you wll get the temperature recorded by that particular DS18B20. A fantastic device. I love them!

As Wawa pointed out: The Wemos is a 3.3V device. DS18B20s fully support 3.3V, so use that voltage. Keep the 4.7 k pullup resistor, can’t do harm

Now your pin problem: The Wemos D1 mini has a different pin nomenclature than the Arduino. In effect this means that in order to use pin D2 of the Wemos you must define that pin in the Arduino sketch as pin 4 (the one who invented this does certainly not earn a place in the Electronics Hall of Fame).
There exist many conversion tables of Wemos pins to Arduino sketch pin definitions. I published one on https://thesolaruniverse.wordpress.com. Here is the picture:

which means that if you want to use pin D2 of the Wemos you must address it in your sketch as pin 4.
Your sketch may contain the following:

declarations section:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_PIN 4 /// this is arduino equivalent of pin D2 of Wemos
OneWire oneWire (ONE_WIRE_BUS_PIN);
DallasTemperature sensors (&oneWire);
DeviceAddress ds18b20_probe_01 = { 0x28, 0xFF, 0xD7, 0x91, 0x92, 0x16, 0x04, 0x69}; // fill in your DS18B20’s device address - used DS18B20 address finder sketch

float temperature;

void setup:
// no DS18B20 related instructions

void loop:
sensors.requestTemperatures ();
temperature = sensors.getTempC (ds18b20_probe_01);

Finally: I have published a description of how to connect a DS18B20 to an Arduino nano (with reporter sketch). You may find that ‘bare project’ here

Ok, thank you for your answer.
In fact I find another ds18b20 (not the same packgae et the 5 others).
With that one it works perfectly.
It seems the other ones are not ds18b20, but fake ones.

If I try the sketch finder.
No adresses is listed with the 5 ones !
With the last it’s ok …

A post was split to a new topic: Problem with DS18B20 sensor