// Include the necessary libraries
#include <OneWire.h>
#include <DallasTemperature.h>
// Set up the temperature sensor
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Set up the relay module
int relayPin = 3;
// Set up the LED
int ledPin = 4;
void setup() {
// Initialize the temperature sensor
sensors.begin();
// Initialize the relay module and LED
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the temperature from the sensor
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// If the temperature is above a certain threshold, turn on the fan
if (temperature > 25) {
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
}
// Otherwise, turn off the fan
else {
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
}
// Wait for a short period of time before taking another temperature reading
delay(1000);
}