Photon with Temp Sensor acting strange publishing temps

I have a weird one. I have a Photon with with a ds18b20 temp sensor. It was working fine and every 30 seconds would publish the temp (F) to the particle cloud. It would also publish the correct temp each time. I do not know what changed but for some reason it is publishing the correct temp, then 32F, correct temp, then 32F. So every other time it publishes, the temp is 32F. Back and forth… I tried changing the delay in the code increasing and decreasing but that didn’t change anything except how often it publishes to the cloud. Regardless, it is always… 76, 32, 76, 32, 76, 32, 76, 32. I have tried replacing the resistor I have in the circuit and the sensor but still doing the same thing. It was working just fine in the beginning. Months later it started doing this. It also sends the data to Cayenne ( I commented that stuff all out to rule it out and made no difference.

Here is my code…

#define CAYENNE_PRINT Serial
#include "cayenne-particle.h"
#include "DS18.h"

int tempval = 0;

DS18 sensor(D0);

char auth[] = "[auth-key]";

void setup()
    Particle.variable("temp", tempval);
    delay(5000); // Allow board to settle

void loop()  // The loop is running the code that sends the sensor data to Cayenne.
        Serial.printf("Temperature %.2f C %.2f F ", sensor.celsius(), sensor.fahrenheit());
        Particle.publish("Temperature", String(sensor.fahrenheit()));
        Blynk.virtualWrite(V2, sensor.fahrenheit());
        tempval = sensor.fahrenheit();        

You could try a different library - e.g.

1 Like

Thanks ScruffR! I appreciate the suggestion. I tried that library just using the supplied example and looks like it’s working just fine. It is consistently publishing the correct temps now. I will have to re-work my code using this library so it also ties in with Cayenne too. I will post back here how that goes.



OK I am good to go. Thanks again. This has solved the problem and I am getting the temp registering in my Cayenne dashboard. It still boggles my mind why with the previous library it was working fine for months and then out of the blue it started acting up.