#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup() {
// Start serial communication
Serial.begin(9600);
// Initialize the DS18B20 sensor
sensors.begin();
}
void loop() {
// Request temperature readings from all sensors on the bus
sensors.requestTemperatures();
// Get the temperature from the DS18B20 sensor
float temperatureC = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000);
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1
Loading
ds18b20
ds18b20