#include "thingProperties.h"
#include <Arduino.h>
#include <HTTPClient.h>
#include <DHT.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
HTTPClient client;
#define DHT22PIN 23
#define LED_PIN 15
#define FAN_PIN 13
volatile int state=0;
DHT dht(DHT22PIN, DHT22);
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Initialize serial and wait for port to open:
Serial.begin(9600);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// Initialize DHT sensor
dht.begin();
// Set up LED and fan pins
pinMode(LED_PIN, OUTPUT);
pinMode(FAN_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
digitalWrite(FAN_PIN, LOW); // Ensure fan is off initially
}
void loop() {
ArduinoCloud.update();
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature: ");
Serial.println(t);
if (t > 35) {
digitalWrite(LED_PIN, HIGH); // Turn on LED
digitalWrite(FAN_PIN, HIGH); // Turn on fan
} else {
digitalWrite(LED_PIN, state||LOW); // Turn off LED
digitalWrite(FAN_PIN,state||LOW); // Turn off fan
}
delay(500);
}
/*
Since Sw is READ_WRITE variable, onSwChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSwChange() {
// Add your code here to act upon Sw change
}
/*
Since Swm is READ_WRITE variable, onSwmChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSwmChange() {
// Add your code here to act upon Swm change
}
/*
Since Boolx is READ_WRITE variable, onBoolxChange() is
executed every time a new value is received from IoT Cloud.
*/
void onBoolxChange() {
// Add your code here to act upon Boolx change
digitalWrite(FAN_PIN,boolx);
state=1-state;
}
/*
Since Y is READ_WRITE variable, onYChange() is
executed every time a new value is received from IoT Cloud.
*/
void onYChange() {
// Add your code here to act upon Y change
digitalWrite(LED_PIN,y);
state=1-state;
}
/*
Since T is READ_WRITE variable, onTChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTChange() {
// Add your code here to act upon T change
}
/*
Since H is READ_WRITE variable, onHChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHChange() {
// Add your code here to act upon H change
}