Untitled
unknown
plain_text
a year ago
3.0 kB
8
Indexable
#define BLYNK_TEMPLATE_ID "TMPL67zMA43IN" #define BLYNK_TEMPLATE_NAME "Peltier Air Cooler" #define BLYNK_AUTH_TOKEN "2TMYDJKchYZZ4pGS5YHDEdQnT0ffF75a" #define BLYNK_PRINT Serial #include <WiFi.h> #include <BlynkSimpleEsp32.h> #include <DHT.h> #define ROOM_DHTPIN 14 // Digital pin connected to the room DHT sensor #define OUTPUT_DHTPIN 13 // Digital pin connected to the output DHT sensor #define IN1_PIN 33 // Digital pin connected to IN1 on L298N #define FAN_PIN 32 // FAN PWM PIN // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) char auth[] = BLYNK_AUTH_TOKEN; char ssid[] = "Town House"; char pass[] = "dizon777"; float roomTemp = 0; float outputTemp = 0; float desiredTemp = 25; // Default desired temperature // Initialize DHT sensors. DHT roomDht(ROOM_DHTPIN, DHTTYPE); DHT outputDht(OUTPUT_DHTPIN, DHTTYPE); bool fanEnabled = false; BLYNK_WRITE(V3) { fanEnabled = param.asInt(); // Get value from the Blynk switch widget } BLYNK_WRITE(V4) { desiredTemp = param.asFloat(); // Get desired temperature from the Blynk app } void setup() { Serial.begin(115200); pinMode(FAN_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); // Set IN1 pin as output digitalWrite(IN1_PIN, LOW); // Initially keep IN1 pin low analogWrite(FAN_PIN, 0); // Initialize fan speed to 0 Serial.println(F("DHTxx test!")); roomDht.begin(); outputDht.begin(); Blynk.begin(auth, ssid, pass); } void loop() { Blynk.run(); // Wait a few seconds between measurements. delay(2000); // Read temperature from both sensors roomTemp = roomDht.readTemperature(); outputTemp = outputDht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(roomTemp) || isnan(outputTemp)) { Serial.println("Failed to read from one of the DHT sensors!"); return; } Serial.print(F("Room Temperature: ")); Serial.print(roomTemp); Serial.print(F("°C ")); Serial.println(); Serial.print(F("Output Temperature: ")); Serial.print(outputTemp); Serial.print(F("°C ")); Serial.println(); Serial.println("*********************"); Serial.println(); // Adjust fan speed based on desired temperature if (fanEnabled) { int fanSpeed = 0; // Initialize fan speed to 0 if (roomTemp <= desiredTemp) { fanSpeed = 255; // Maximum speed until desired temperature is reached } else { fanSpeed = 170; // Medium speed if above desired temperature } analogWrite(FAN_PIN, fanSpeed); // Set the fan speed using PWM digitalWrite(IN1_PIN, HIGH); // Set IN1 high to enable the Peltier module } else { analogWrite(FAN_PIN, 0); // Turn off the fan if not enabled digitalWrite(IN1_PIN, LOW); // Set IN1 low to disable the Peltier module } Blynk.virtualWrite(V1, roomTemp); Blynk.virtualWrite(V2, outputTemp); }
Editor is loading...
Leave a Comment