Dht11 program error

my program is bellow but its not working ,please help!

#include <dht.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 2  // Define the pin to which the DHT sensor is connected
#define BUZZERPIN 3  // Define the pin to which the buzzer is connected

dht DHT;  // Create a DHT object
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Define LCD address and dimensions

unsigned long previousMillis = 0;
const long interval = 3600000;  // 1 hour in milliseconds

void setup() {
  Serial.begin(9600);
  pinMode(BUZZERPIN, OUTPUT);

  lcd.begin(16, 2);
  lcd.print("Temperature:");
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // Reset the buzzer after 1 hour
    digitalWrite(BUZZERPIN, LOW);
    previousMillis = currentMillis;
  }

  delay(2000);  // Wait for 2 seconds between readings

  int chk = DHT.read11(DHTPIN);  // Read data from DHT sensor

  float temperature = DHT.temperature;  // Get temperature in Celsius

  lcd.setCursor(0, 1);
  lcd.print(temperature);
  lcd.print(" *C");

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" *C");

  // Set the desired temperature thresholds
  float buzzerOnThreshold = 24.0;
  float buzzerOffThreshold = 21.0;

  if (temperature >= buzzerOnThreshold) {
    // If temperature is 24 degrees or higher, sound the buzzer
    digitalWrite(BUZZERPIN, HIGH);
  } else if (temperature <= buzzerOffThreshold) {
    // If temperature is 21 degrees or lower, turn off the buzzer
    digitalWrite(BUZZERPIN, LOW);
  }
}

And how exactly is your program not working?

Is it not compiling?

Is it not loading?

Is it not doing what you expect it to do?

boss its not compiling

And what error message are you seeing that you haven't shown us? Please include the entire error message, enclosed in code tags, as shown in How to get the best out of this forum.

Is this a sketch that you have written? If it isn't, please include a link to where it came from.

What dht library? I found it... Use this DHTlib...

I would suggest you read the forum guidelines: How to get the best out of this forum Then post the error codes properly, you did a good job with the code. Links to technical information on the hardware items will help a lot to better help you. This would answer van_der_decken's request.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.