hi there. i am trying to make a code that when the tempature turns to 70 degres farenhieght it will turn on an led. this is my code
#include <DHT.h>
// Define DHT sensor type and pin
#define DHTPIN 2 // Pin where the data pin of the DHT sensor is connected
#define DHTTYPE DHT11 // DHT11 or DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize the built-in LED as an output
pinMode(LED_BUILTIN, OUTPUT);
// Initialize the DHT sensor
dht.begin();
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the temperature in Fahrenheit
float temperature = dht.readTemperature(true);
// Check if the reading is valid
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print temperature to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °F");
// If the temperature is above 68°F, make the LED blink
if (temperature > 68) {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on
delay(300); // Wait for 300 ms
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off
delay(300); // Wait for 300 ms
} else {
digitalWrite(LED_BUILTIN, LOW); // Ensure the LED is off if temperature <= 68
}
}
can somebody help? i just started and am 9 so can you create a diagram? thank you.
