The DS18B20 is a precision digital temperature sensor that offers a convenient way to measure temperature in a wide range of applications. Manufactured by ELEGOO, this sensor is known for its ease of use with microcontrollers such as the Arduino UNO. It uses the 1-Wire protocol, which minimizes the number of pins required for operation, allowing multiple DS18B20 sensors to be connected in parallel on the same data line.
Pin Number | Name | Description |
---|---|---|
1 | GND | Ground pin, connected to the system ground |
2 | DQ | Data pin, used for 1-Wire communication |
3 | VDD | Power supply pin, 3.0V to 5.5V |
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin(); // Start up the library
}
void loop() {
sensors.requestTemperatures(); // Send command to get temperatures
float temperatureC = sensors.getTempCByIndex(0);
Serial.print("Temperature is: ");
Serial.print(temperatureC);
Serial.println("°C");
delay(1000); // Wait 1 second before next reading
}
sensors.getAddress()
function to verify the unique address of each sensor.Q: Can the DS18B20 be powered parasitically? A: Yes, the DS18B20 can be powered parasitically by connecting the VDD pin to the DQ line through a pull-up resistor.
Q: How many DS18B20 sensors can be connected on the same data line? A: There is no strict limit, but practical considerations like power supply stability and data line capacitance typically allow for around 10-20 sensors.
Q: How do I read the temperature from multiple sensors? A: Each sensor has a unique address. Use the DallasTemperature library functions to read each sensor by its address.
Q: What is the purpose of the unique 64-bit serial code? A: The unique code allows multiple DS18B20 sensors to be used on the same 1-Wire bus without address conflicts, enabling individual sensor identification and communication.