I dont know what to do

Im a begginer coder in arduino so take it easy on me

So why does my buttons have a huge delay or dont even work when i press them ( ive tested in button testing codes and they work fine, no delay.)

#include <DHT2pin.h>
#include <DHT.h>
#define DHTPIN A2
#define DHTTYPE DHT11
#define BUTTON_UP_PIN 6
#define BUTTON_DOWN_PIN 7
DHT dht(DHTPIN, DHTTYPE);
int humidityThreshold = 60;
void setup() {
Serial.begin(9600);
Serial.print("?G420");
pinMode(5, OUTPUT);
pinMode(BUTTON_UP_PIN, INPUT_PULLUP);
pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP);
dht.begin();
}
void loop() {
if (digitalRead(BUTTON_UP_PIN) == LOW) {
humidityThreshold += 1;
}
if (digitalRead(BUTTON_DOWN_PIN) == LOW) {
humidityThreshold -= 1;
}
digitalWrite(5, HIGH);
delay(1000);
digitalWrite(5, LOW);
delay(1000);
int delay_ms = 2000;
delay(delay_ms);
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Falha ao ler o sensor DHT!");
return;
}
Serial.print("?f");
Serial.print("Temperatura = ");
Serial.print(int(temperature));
Serial.print(" Humidade = ");
Serial.print(int(humidity));
Serial.print(" Humidade Ideal: ");
Serial.print(humidityThreshold);
Serial.println("%");
delay(100);
}

Im using this lcd if its of any help New Product: SMD LCD 117 – Modern Device

Because you have put 4 seconds of delays.
You must use millis().

Regards

Big delays, you say?
Hmmm.

1 Like

It 1 second and im talking wayyyy bigger than that

i need 2 second delay at least for the dht11

Use millis() instead delay().

1 Like

Bro thank you so much i asked everyone and the actual fix was so easy

I know, but I stopped looking after that.

No, you need to to wait 2 seconds, but that doesn't mean sitting and twiddling your thumbs.

OP says it wants to wait like that, see. :rofl:

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