Untitled
unknown
plain_text
a year ago
3.0 kB
5
Indexable
#define BLYNK_TEMPLATE_ID "TMPL6cET3uP7Q" #define BLYNK_TEMPLATE_NAME "Peltier Air Cooler" #define BLYNK_AUTH_TOKEN "NTslalQqGkKcpXjvCp3nmgQRfV_hPZGh" #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 // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) #define FAN_PIN 32 // FAN PWM PIN char auth[] = BLYNK_AUTH_TOKEN; char ssid[] = "Town House"; char pass[] = "dizon777"; float roomTemp = 0; float outputTemp = 0; // 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 } 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 temperature reading only if fan is enabled if (fanEnabled) { int fanSpeed = 0; // Initialize fan speed to 0 if (roomTemp <= 15) { fanSpeed = 0; // Fan off } else if (roomTemp > 15 && roomTemp <= 20) { fanSpeed = 150; // Low speed } else if (roomTemp > 20 && roomTemp <= 25) { fanSpeed = 170; // Medium speed } else if (roomTemp > 25) { fanSpeed = 255; // High speed } 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