#include <Arduino.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS D2
//OneWire oneWire(ONE_WIRE_BUS);
//OneWire ourWire(D2);
OneWire ourWire(4);
DallasTemperature sensors(&ourWire);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
sensors.begin();
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
float tempC = sensors.getTempCByIndex(0);
Serial.println(tempC);
// Check if reading was successful
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
delay(10); // this speeds up the simulation
}