like discribed in the title my temperature sensor goes to -127 after a few minutes of run time, it works again after a restart, I have already replaced the sensor and I'm using the same code for the temperature which I had used before which has been running flawlessly for almost 6 months now, I really have no clue what I did wrong hopefully someone got an idea.

Thank you!

  • 3
    There's not much information there to figure out what happened. Did changing the sensor fix the problem or did it continue with the new sensor? Providing a schematic of your sensor connection to the Arduino(?) would help. So would seeing a minimum sketch that still reproduces the problem. Both of those edited into your question, please.
    – JRobert
    Jul 29, 2023 at 12:10
  • Thank you for your reply but I just used a diferent library now.
    – Dennis
    Jul 29, 2023 at 13:52
  • decimal -127 is binary 11111111 ... reading all 1 bits is usually a wiring issue
    – jsotola
    Jul 29, 2023 at 17:28
  • Reading '0xFF' could be caused by poor grounding or insufficient power supply, incorrect pull-up resistor value or simply bad/fake chip. If the code you posted below as an "answer" is the code that you are running, you are also causing the sensor self heat-up by constantly looping it. DS18B20 supposed to be read at once every second to avoid self heating.
    – hcheung
    Jul 30, 2023 at 1:06

1 Answer 1


There's a problem with using OneWire and Wire/I2C in one Sketch at once.

I believe this is because OneWire takes too long not sure, but this is probably why the temperature reading went to -127 after a while to fix thi.

I used an NTC 10K at 20°C. Below you can see code to make the NTC work and how to wire it!

Hope this helps!


#include <math.h>
const int thermistor_output = A1;

void setup() {

void loop() {
  int thermistor_adc_val;
  float output_voltage, thermistor_resistance, therm_res_ln, temperature; 
  thermistor_adc_val = analogRead(thermistor_output);
  output_voltage = ( (thermistor_adc_val * 5.0) / 1023.0 );
  thermistor_resistance = ((5 * (10.0 / output_voltage)) - 10); 
  thermistor_resistance = thermistor_resistance * 1000 ; 
  therm_res_ln = log(thermistor_resistance);
  temperature = (1 / (0.001129148 + (0.000234125 * therm_res_ln) + (0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln)));
  temperature = temperature - 273.15;
  Serial.print("Temperature in degree Celsius = ");

Wiring: enter image description here

  • Hi @Dennis, the point of this and the many other stack exchange web sites are to accumulate clear, concise and well-worded Questions and Answer to help others w/similar problems. There is absolutely nothing wrong w/answering your own question. Consider editing your Title, Question & Answer to make it clear what was not working and how you fixed it. Copy any important information from the comments and integrate them into the Question and Answer. Thanks.
    – st2000
    Jul 29, 2023 at 14:58
  • 1
    Is this the solution to your own question, or is it meant as an addition. -- If the latter, you urgently need to take the tour to learn how this site works, it is not a forum. Then edit your question and add this content to it, then delete this non-answer. Jul 29, 2023 at 21:20
  • -127 is the default code for an open wire.
    – Gil
    Jul 31, 2023 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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