// Setup a oneWire instance to communicate with the DS18B20 temperature sensor
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication
Serial.begin(9600);
// Start the DS18B20 sensor
sensors.begin();
}
void loop(void)
{
// Call sensors.requestTemperatures() to issue a global temperature request to all sensors
sensors.requestTemperatures();
// Get the temperature in Celsius from the DS18B20 sensor
float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature in Celsius to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" degrees Celsius");
delay(3000); // Wait for 3 second before taking another temperature measurement
}
include
include
include
// Data wire is plugged into GPIO 15 on the ESP32
define ONE_WIRE_BUS 15
// Setup a oneWire instance to communicate with the DS18B20 temperature sensor OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);
void setup(void) { // Start serial communication Serial.begin(9600);
// Start the DS18B20 sensor sensors.begin(); }
void loop(void) { // Call sensors.requestTemperatures() to issue a global temperature request to all sensors sensors.requestTemperatures();
// Get the temperature in Celsius from the DS18B20 sensor float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature in Celsius to the serial monitor Serial.print("Temperature: "); Serial.print(temperatureC); Serial.println(" degrees Celsius");
delay(3000); // Wait for 3 second before taking another temperature measurement }