#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 13 // ESP32 pin GIOP36 (ADC0) connected to LM35
#include <OneWire.h>
#include <DallasTemperature.h>
// GPIO em que o sensor DS18B20 está conectado
const int oneWireBus = 14;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup() {
// Start the Serial Monitor
Serial.begin(9600);
// Start the DS18B20 sensor
sensors.begin();
}
void loop() {
//Código DS18B20
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
// float temperatureF = sensors.getTempFByIndex(0);
Serial.print("Tanque: ");
Serial.print(temperatureC);
Serial.println("ºC");
//Serial.print(temperaturef);
//Serial.println("F");
//*********************
//Código LM35
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in °C
float tempC = milliVolt / 10;
// convert the °C to °F
float tempF = tempC * 9 / 5 + 32;
Serial.print("Estufa: ");
Serial.print(tempC);
Serial.println("ºC");
//*********************
delay(5000);
}