Beginner D1 WEMOS

Hi, im new here, and need help on something very simple. The reading on this code is offscale ( 990°C) and have spikes.

i removed the 4,7K resistor but nothing change.

Im using a D1 WEMOS and a DS18B20 temp sensor.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
SimpleTimer timer;
#define Pin 0//  pin DATA ds18b20



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


OneWire ourWire(Pin); 
DallasTemperature sensors(&ourWire); 


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


void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  sensors.begin();
  delay(5000);

  timer.setInterval(2000L, leeTEMP);

}
 
void leeTEMP()
{
  sensors.requestTemperatures();
  Blynk.virtualWrite(0, sensors.getTempCByIndex(0));
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
  timer.run();
}

Having calling the sensor but before the virtualWrite() if you add the following line what does Serial Monitor show?

Serial.println(sensors.getTempCByIndex(0));

How is your sensor connected to your Wemos?
You’ve defined Pin 0, and a common newbie mistake is to assume that this is the pin labelled D0 on the Wemos. On a Wemos D1 Mini (which is what I guess you’re using) GPIO 0 is actually the pin labelled D3.

Pete.

1 Like

Hi Costas,

I added the line, and the monitor shows -127.00 but the Blynk App shows 976°C.

When i put the sensor in Hot Water or Cold Water the reading dont changes. ( The sensor is the waterproof type ).

I Will try today to change the code a little and teste a new sensor.

Thanks!

Thanks Pete,

But i’m using a D1 WEMOS, not the Mini version.

I tested with a Potentiometer, and the reading stabilized. I’m using the correct pin ( A0 ) because when i adjust the potentiometer, the reading changes accordingly

It’s because i have a bad sensor?

-127 is much better than 976 as -127 is the default for " you have not connected the sensor correctly" whereas 976 means nothing.

Let’s get Serial Monitor correct and then we can sort out the easy Blynk stuff.

As per another post in this thread I think you have mixed up the pins.

Sensor is digital and you are trying to use an analogue pin, move it.

1 Like

Costas, Youre right. The sensor was on the wrong pin. My bad.

But i moved the sensor to digital pin 3 and 4, But don’t worked.

Then i tried to use the sensor on a Arduino Mega instead with this code for test:

/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/



void setup(void)
{
  // start serial port
  Serial.begin(115200);
  Serial.println("Dallas Temperature IC Control Library Demo");
  // Start up the library
  sensors.begin();
}
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  /********************************************************************/
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperature readings
  Serial.println("DONE");
  /********************************************************************/
  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
  // You can have more than one DS18B20 on the same bus.
  // 0 refers to the first IC on the wire
  delay(1000);
}

Now worked! Its reading ok on Arduino MEGA.

But the same code, on the same PIN 3 of the D1 Wemos, its reading -127.

What i have done wrong? I tried the sensor on the others pin too with the exactly same code.

Wiring:

Study the post by @PeteKnight it has the answer.

For ESP’s pin 3 is NOT D3 it is GPIO 3 which doesn’t exist. It does exist but it’s the RX pin and best avoided for obvious reasons.

Set the pin in your ESP sketch as 4 and connect the DS18B20 to D2.

2 Likes

Costas,

I changed to 4 and put the sensor on PIN 2. But dont worked ( Dont Know Why ).

Then i changed to GPIO 14 and put the sensor on PIN 5. Now is working nice.

Thanks man! It was fun!

1 Like