Build it step by step
0 of 6 doneWire one sensor
Connect a single DS18B20 with the pull-up and read it.
Add the others
Connect all four data pins to D2 and see the count change to four.
Note the IDs
Copy each ROM ID from the Serial Monitor.
Label them
Warm one sensor in your fingers to see which ID rises, then stick a label on it.
Test a long cable
Extend the data wire with twisted cable and see how far it works.
Use the IDs
Change the sketch to print a name next to each ID.
How do you build a 1-Wire sensor bus?
Many DS18B20 sensors share one data wire, each found by its unique ID. You need Arduino Nano, DS18B20 Temperature Sensor × 4, Resistor 4.7 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 45 minutes.
- Level
- Beginner
- Time
- About 45 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| All DS18B20 pin 1 (GND) | Nano GND | Ground |
| All DS18B20 pin 3 (VDD) | Nano 5V | Power |
| All DS18B20 pin 2 (DQ) | Nano D2 | One shared data line |
| 4.7 kΩ resistor | D2 and 5V | Single pull-up for the whole bus |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "OneWire" and "DallasTemperature". The DS18B20 TO-92 pins, flat face towards you, are GND, DQ, VDD from the left. Wire with the power off, because a reversed sensor gets hot very quickly.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
void printAddress(DeviceAddress a) {
for (byte i = 0; i < 8; i++) { if (a[i] < 16) Serial.print('0'); Serial.print(a[i], HEX); }
}
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.print("Sensors found: "); Serial.println(sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures();
for (byte i = 0; i < sensors.getDeviceCount(); i++) {
DeviceAddress addr;
if (sensors.getAddress(addr, i)) {
Serial.print("Sensor "); Serial.print(i); Serial.print(" ID ");
printAddress(addr);
Serial.print(" "); Serial.print(sensors.getTempC(addr), 2); Serial.println(" C");
}
}
Serial.println();
delay(1000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Sensors found: 1 Sensor 0 ID 28FF641E0F16035C 24.50 C
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Four sensors | Count is four and each has its own ID |
| Warm one sensor | Only that sensor's reading rises |
| Unplug one | Count drops to three |
| Room temperature | All four read within about 0.5 °C |
If it does not work
Count is zero
Check the 4.7 kΩ pull-up between D2 and 5V.
Reads -127
Sensor lost power or the data wire is loose.
Reads 85
The sensor did not finish converting. Check power and wait before reading.
Sensor gets very hot
It was wired backwards. Disconnect, let it cool and check the pinout.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the 1-Wire sensor bus?
Arduino Nano, DS18B20 Temperature Sensor × 4, Resistor 4.7 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the 1-Wire sensor bus take to build?
About 45 minutes for a beginner maker, in 6 steps.
How do I know the 1-Wire sensor bus works?
Four sensors: Count is four and each has its own ID. Warm one sensor: Only that sensor's reading rises. Unplug one: Count drops to three.
Count is zero: what should I check?
Check the 4.7 kΩ pull-up between D2 and 5V.
Reads -127: what should I check?
Sensor lost power or the data wire is loose.
Reads 85: what should I check?
The sensor did not finish converting. Check power and wait before reading.
Sensor gets very hot: what should I check?
It was wired backwards. Disconnect, let it cool and check the pinout.
