Temperature drops occasionally from 59+C to -13C or to other random values. Used sketch and info from this site: http://internetofthinking.blogspot.com/2016/02/upload-ds18b20-temperature-sensor-data.html

NodeMCU powered by phone charger 5v 1a via microUSB. Placing 4.7 kOm resistor between data wire and 3v3 didn't help me.

Does anyone know how to solve this issue? Like filtering results and pushing to server only values that do not differ by more than n*C, or something like that?

Here is the sketch

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

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec
#define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* server = "api.thingspeak.com";
String apiKey ="-";
const char* MY_SSID = "-"; 
const char* MY_PWD = "-";
int sent = 0;
void setup() {

void loop() {
  float temp;
  //char buffer[10];
  temp = DS18B20.getTempCByIndex(0)+5;
  //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
  Serial.print(String(sent)+" Temperature: ");

  //if (temp != prevTemp)
  //prevTemp = temp;

  int count = myPeriodic;

void connectWifi()
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {

}//end connect

void sendTeperatureTS(float temp)
   WiFiClient client;

   if (client.connect(server, 80)) { // use ip or api.thingspeak.com
   Serial.println("WiFi Client connected ");

   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(temp);
   postStr += "\r\n\r\n";

   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");

   }//end if
}//end send


  • measure several times ... ignore max and min readings – jsotola Nov 4 '19 at 18:41

Have you checked the device's Scratchpad CRC

Idk how to.

How is your device hooked up (diagram)

Device is hooked up in normal mode, right like in this pic enter image description here

DS18b20 (waterproof) is located on top of the boiler in a special pit for measuring temperatures, there are definitely no any sort of microwaves here, and the temp is not higher than 80C. I'll try today to change the power supply, just in case, and later switch the sensor into parasite mode.


Discarding (potentially) bogus readings could help as a last resort, but something's going on to cause those bogus readings. You'd be better off finding and fixing that than finding a work-around.

These are pretty stable devices and you shouldn't see more than a couple of LSB (a few 1/4 degC). I'm inclined to suggest noise pickup on the one-wire bus but the bogus samples in your photo look identical. I have a >15' parasitic one-wire bus, just a twisted pair with no shield, and a DS18b20 close to the MCU and another out at the end. I do smooth the input but no de-spiking.

Have you checked the device's Scratchpad CRC between converting and reading the temperature? How is your device hooked up (diagram)? Is it in parasitic mode?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.