#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#define ONE_WIRE_BUS 4 // DS18B20 on GPIO 4
#define DHTPIN 12 // DHT22 on GPIO 12
#define DHTTYPE DHT22 // DHT22 type
#define ANALOG_PIN 2 // Analog temperature sensor on GPIO 2
#define BETA 3950 // Beta value
#define REF_RESISTANCE 10000 // Reference resistance at 25°C
#define REF_TEMPERATURE 298.15 // Reference temperature in Kelvin (25°C)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
DS18B20.begin();
dht.begin();
pinMode(ANALOG_PIN, INPUT);
}
void loop() {
DS18B20.requestTemperatures();
float tempDS18B20 = DS18B20.getTempCByIndex(0);
float tempDHT22 = dht.readTemperature();
float humidityDHT22 = dht.readHumidity();
int analogValue = analogRead(ANALOG_PIN);
float resistance = (4095 / (float)analogValue) - 1;
resistance = REF_RESISTANCE / resistance;
float tempAnalog = 1 / (log(resistance / REF_RESISTANCE) / BETA + 1 / REF_TEMPERATURE) - 273.15;
Serial.print("DS18B20 Temperature: ");
Serial.print(tempDS18B20);
Serial.println("°C");
Serial.print("DHT22 Temperature: ");
Serial.print(tempDHT22);
Serial.println("°C");
Serial.print("Analog Sensor Temperature: ");
Serial.print(tempAnalog);
Serial.println("°C");
Serial.print("DHT22 Humidity: ");
Serial.print(humidityDHT22);
Serial.println("%");
// Compare temperatures
float maxTemp = max(max(tempDS18B20, tempDHT22), tempAnalog);
Serial.print("Highest temperature is: ");
Serial.print(maxTemp);
Serial.println("°C");
delay(5000); // Wait 5 seconds
}