#include "DHT.h" #define DHTPIN D9 // Uncomment whatever type you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); float temperatureC; float temperatureF; float humidity; int btn; int btnPIN = D1; int led = D10; int LDR = A0; int lastButtonState = 0; void setup() { pinMode(led, OUTPUT); pinMode(LDR, INPUT); pinMode(btnPIN, INPUT); Serial.begin(9600); Serial.println(F("Ousiafb's XIO_ESP32")); dht.begin(); } void loop() { btn = digitalRead(btnPIN); Serial.print("Button State: "); Serial.println(btn); buttonSateChange(); float LDRread = analogRead(LDR); //Reads the Value of LDR(light). Serial.print("LDR value is :"); Serial.println(LDRread); humidity = dht.readHumidity(); // Read temperature as Celsius (the default) temperatureC = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) temperatureF = dht.readTemperature(true); delay(500); } void buttonSateChange() { // compare the buttonState to its previous state if (btn != lastButtonState) { // if the state has changed, increment the counter if (btn == HIGH) { // if the current state is HIGH then the button went from off to on: // String msg = "Someone just opened the door"; // bot.sendMessage(CHAT_ID, msg, ""); Serial.println("opened"); } else if (btn == LOW) { // if the current state is LOW then the button went from on to off: // String msg = "Someone just closed the door"; // bot.sendMessage(CHAT_ID, msg, ""); Serial.println("closed"); } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, for next time through the loop lastButtonState = btn; }