ds18b20 issue show -127°c

hello, i have problem with using this sensore, sometimes when power on arduino the display show me -27°c( -127°C but i am using 7 digit numbers with only 2 numbers) if i reconect only the sensor power it work but after some times it show back, i am using 2 sensors trying change pull up from 4k7 to 2k2 and also capacitor 100uf between gnd and 5v, but i am still geting the problem. when iam using the 4k7 on both sensors the problem show only on OUT sensore with about 1 meter added cabels, but after 2k2 and capacitor the problem start sometimes OUT sensore and sometimes both or only IN sensore. maybe is problem with code or the sensor dont have enough time to read and send the data. i am trying also get temp by adress with adres of the senrsor and sometimes i cant get the addres from the sensor, but all is soldered together, i checked it two times for cold connection .as power i use car 12V with step down module about to 12->7.5 volst to dc jack. can someon help me pleas? sorry for my english if any problem to understand.
photo in attachment of my project when it work well, i have video but it too much big if you want see more

teplomer_tft_golf_zajizdeci_komplet.ino (10.4 KB)

Hi, Your English is okay 8)

The -127 degrees is an error code from the library. It means that something failed.
You should not display that temperature. Ignore it and hope that the next one will be okay.

  if( Celcius < -100.0)     // not possible, something failed.
    Serial.println( F( "Error, first DS18B20 miscommunication"));
  else     // temperature is normal, display it.
    Serial.print("teplota1:");         //seriovy monitor napis
    Serial.println(Celcius);             //teplota1 ser. monitor

    if (Celcius < 0) {                   //pokud teplota1 klesne pod 0
    tft.setCursor(10, 63);               //nastavi kurzor na x,y

Please tell which Arduino board you use.

A 100 µF capacitor does not help with high frequency noise from the DC-DC converter.

Perhaps there is a bad contact to the DS18B20.

Perhaps the DC-DC converter is too noisy. It probably is. The voltage regulator on the Arduino board stops most noise, but there might be a ground path that brings the noise to the board.

To avoid a grounding problem with the DS18B20, power them with 5V and GND wires that are directly connected to the Arduino board and not connected to something else. A beginners mistake is for example to connect a relay halfway to the same GND wire that is also connected to the DS18B20, or using a GND wire to a breadboard, and on the breadboard are also other things beside the DS18B20 connected to the GND.

A link to AliExpress can be cut off after the “.html” : https://www.aliexpress.com/item/1PCS-17x11x3-8mm-RC-Airplane-Module-Mini-360-DC-Buck-Converter-Step-Down-Module-4-75V/32336508941.html

Do you have an Arduino Uno for testing ? Connect only the DS18B20 to the Arduino Uno, and that should work 100% reliable.

Koepel: The -127 degrees is an error code from the library. It means that something failed.

More than that, it means the sensor is not connected. And the next one will not be OK until you fix the connection.

More than that, it means the sensor is not connected. And the next one will not be OK until you fgix the connection.

It could be due to a bug in the example program of the IDE. The simple.ino example of IDE of Dallas Library has shown -1270C for my DS18B20 sensor; but, the single.ino example of the IDE of the same library under the same setup shows normal temperature for the sensor.

You haven't initialized the library on each pin. Add this to the setup() function:


BTW: -127 means that the scratchpad memory couldn't be read to get the temperature.


Koepel- i am using chines arduino uno (withnout big chip). yeah when i have it home at trying only uno and senstors it work all time , after i using some relays and complete in to car there come problem , relays changing motors + and - for opening and closing and withnout resistor and dion on input relay (com) arduino after unconnect restar every time i thing there come some shortcut or high voltage from coil that do it, so that problem stop after resistor (i think 4k7 5w and diode ) .so maybe the relays are problem, i have all grounds from relay, sonsors in one pin. and i hear when i turn the dc-dc converter my radio in garage is disturbed. maybe the problem is also here, dont know how to fixt it. i will try your upgrade but i think i never get the right code becaous when it that error come, it didnt fix alone withnout unplug and power on again or unplug the sonsore. and whent this eroro come sometimes that senors what show fault geting hot and warm, so after reconect or unplug and plug the power it show high temperature and that it cooling down to output temperature. i try draw youu scheme of my project to understand my invent and try to help my fix it.

GolamMostafa - so what i try to change??

el_supremo- ok i try it

there is my scheme sory for quality maybe you better understand. after press switch and key on the reley conncet 12v and go to dc-dc convert and power on arduino. arduino write on tft temperature out , tempretarue in and line in half and start one relay and dc engine start opening my case for some time, after it unconect and start the loop, where is changing color ( if 0 or lower blue, gren to 29 and 30 is colored red). and also if is -1 or lower that show - in middle of number becaus iam using convert to 7 digit numbers and they didnt how me - id is -3 it show only 3 .and program is showing it on tft display until recognizet on pin A5 0 volts againts pull down. and thay start closing(zavirani) and close the case and switch power off arduino.
void zobraz7ciselnouOut= 7 digint numbers out
void zobraz7ciselnouIn= 7 digit numbers in
void otevreni()= opening by relays¨
void zavreni()= closing by relays

desik99: GolamMostafa - so what i try to change??

I would follow this link to be sure that the sensor is present, and then I would go for temperature measurement.

Your diagram is somewhat confusing. The "in" DS18B20 has the power pin labelled 5V+. The "out" DS18B20 has the power pin labelled 5V-. You do the same kind of thing with the relays which have connections labelled 12V+ and 12V-. What are those and exactly where do they come from - especially for the 5V+ and 5V- ? I suspect that the problem is due to having the relays and motors powered from a 12V supply which is also used to power the UNO through a DC-DC converter. The supply is almost certainly causing a glitch on the 5V to the UNO which resets the DS18B20. That DC-DC converter is labelled in an odd way. It has an input labeleld + and the other input is labelled 12V-.

Have you added the .begin() calls in setup() ?


GolamMostafa- ok i try it when i will have more time for take it out and build that scheme.

el_supremo- yes i added sensors.begin(); and sensors2.beigin(); but that error coming again, when i powe on it 80% work normal but when i drive after some time or someting it show -127 and didnt work solo normal again , only after off and on device. sorry my bad 12v- mean ground, but it from car battery not arduino gnd. and 5v- is also gnd from arduino sorry for mistakes. the "out" sensors is 5v+ not (-). the plus on dc-dc converter is from relay thay is manual controling only use gnd switch for off and on. to relay is 12v+ all time and with switch i connect relay if there is 5v from phone charger and when arduino on, there come to relay 5v from arduino to hold relay until switch is off.on this 2x 5v+ are diodes for not charging arduino.