Der Dallas DS18B20 Temperatursensor ist ein One-Wire Digitalsensor.

Anschluss 18B20 (diskret mit 4,7k Pull Up-Widerstand)
1 2
3 4
5 6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop()
{
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" °Celsius temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}
|
Last modified: Friday, 8 April 2022, 9:23 AM