@antons15
Thry the following sketch which does functional check on a DS18B20 temperature sensor.
//12-bit default resolution; external power supply
#include<OneWire.h>
OneWire ds(23); //IO Pin-23 with which the data line of the senosr is connected.
byte addr[8]; //to hold 64-bit ROM Codes of DS1
byte data[9]; //buffer to hold data coming from DS18B20
void setup()
{
Serial.begin(9600);
ds.reset();
ds.search(addr); //collect 64-bit ROM code from sensor
}
void loop()
{
//----------------------------
ds.reset(); //bring 1-Wire into idle state
ds.select(addr); //slect with DS18B20 sensor with address in addr[] array
ds.write(0x44); //conversion command
delay(1000); //insert max conversion time or poll status word
//---------------------------
ds.reset();
ds.select(addr); //selectimg the desired DS18B20
ds.write(0xBE); //Function command to read Scratchpad Memory (9-byte)
ds.read_bytes(data, 9); //data comes from DS and are saved into buffer data[]
//---------------------------------
int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
float myTemp = (float)raw / 16.0; //12-bit resolution
Serial.println(myTemp, 2); //show two-digit after decimal point
}