Introduction: Get the Serial Number of a DS18B20 With an Arduino

This is a quick guide on how to get the individual serial numbers of your DS18B20 1-wire temperature sensors.

This is handy for projects that require multiple sensors.

Things you need:

Step 1: Add the Required Library to Arduino IDE

  1. Open Arduino IDE (I am using 1.8.1)
  2. Click "Sketch" -> "Include Library" -> "Manage Libraries..."
  3. Select the search bar and type "dallas"
  4. Click "DallasTemperature" and click "Install"

Alternatively you can download the Library from here:

This Library includes the OnWire Library.

Step 2: Wire Up the DS18B20

Using a bread board connect +5V, GND and Digital Pin 2 (Pin 2 is already set in the example sketch) from the Arduino using Male to Male breadboard jumpers.

Connect the DS18B20 parallel to the 3x terminal strips on the breadboard.

  • Pin 1 (GND) -> GND (Ground 0V)
  • Pin 2 (DATA) -> Digital Pin 2
  • Pin 3 (Vdd) -> +5V

For Normal Power Mode connect a 4.7K Resistor from +5V to Digital Pin 2 wire on the breadboard.

The following link is a great resource for the DS18B20 1-wire temperature sensor.

Step 3: Load the Example Sketch "Single"

Once you have it wired up you are ready to load the Dallas Temperature "Single" Sketch

Open Arduino IDE (I am using 1.8.1)

Click "File" -> "Examples" -> "Dallas Temperature" -> "Single"

I added in delay(5000); on line 103 to give me time to copy the serial number

Select your appropriate board form "Tools" -> "Board"

Select your appropriate port "Tools" -> "Port"

Now "Upload" the Sketch "Sketch" -> "Upload"

Click "Tools" -> "Serial Monitor" make sure the baud rates match mine is 9600

If you sketch did not upload check your Board, Port, USB drivers etc.

Step 4: Copy the Serial Number

From the "Serial Monitor" you will see the 4th line is "Device 0 Address: xxxxxxxxxxxxxxxx"

This is the Serial Number of the DS18B20

If it is "0000000000000000" then there is an issue reading your DS18B20.

Highlight it with your mouse and press CTRL+C on you keyboard then past it in Notepad

For my other projects my code uses an array of these numbers. I reformatted the HEX string to the following format.

DeviceAddress tempSensorSerial[9]= {

{0x28, 0xFF, 0x07, 0xA6, 0x70, 0x17, 0x04, 0xB5}, {0x28, 0xFF, 0xB2, 0xA6, 0x70, 0x17, 0x04, 0x28}, {0x28, 0xFF, 0x42, 0x98, 0x70, 0x17, 0x04, 0xD3}, {0x28, 0xFF, 0x86, 0xA8, 0x70, 0x17, 0x04, 0xA6}, {0x28, 0xFF, 0x2B, 0x65, 0x71, 0x17, 0x04, 0x76}, {0x28, 0xFF, 0x66, 0x62, 0x71, 0x17, 0x04, 0xF5}, {0x28, 0xFF, 0xD9, 0x9B, 0x70, 0x17, 0x04, 0x9C}, {0x28, 0xFF, 0x98, 0x6A, 0x71, 0x17, 0x04, 0xED}, {0x28, 0xFF, 0x99, 0x42, 0x71, 0x17, 0x04, 0x4C} };

Step 5: Finished

Now you can identify each individual DS18B20 1-wire temperature sensor in your code and use a function like this:

float getTemperature(byte j)


float tempC = sensors.getTempC(tempSensorSerial[j]);

return tempC;


Check out my simple example sketch