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();
}
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.
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
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.