#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into GPIO 5 on the ESP32
#define ONE_WIRE_BUS 15
// 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() {
// put your setup code here, to run once:
Serial.begin(115200);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
Serial.print("Temperature is: ");
Serial.print(temperatureC);
Serial.println("°C");
// int digitalVal = digitalRead(TEMP_IN_PIN);
// Serial.println(digitalVal);
// float celsius = 1 / (log(1 / (1023. / digitalVal - 1)) / BETA + 1.0 / 298.15) - 273.15;
// String temp = (String) celsius;
// Serial.println(temp);
// put your main code here, to run repeatedly:
delay(1000); // this speeds up the simulation
}
// #include "DHTesp.h"
// const int DHT_PIN = 15;
// DHTesp dhtSensor;
// void setup() {
// Serial.begin(115200);
// dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// }
// void loop() {
// TempAndHumidity data = dhtSensor.getTempAndHumidity();
// Serial.println("Temp: " + String(data.temperature, 2) + "°C");
// Serial.println("Humidity: " + String(data.humidity, 1) + "%");
// Serial.println("---");
// delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
// }