تفاصيل العمل

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "YourAuthToken";

// Your WiFi credentials.

char ssid[] = "YourNetworkName";

char pass[] = "YourPassword";

// Pin assignments

#define RELAY_PIN 13 // Pin connected to the fan relay

#define BUZZER_PIN 12 // Pin connected to the buzzer

#define GREEN_LED_PIN 14 // Pin connected to the green LED

#define RED_LED_PIN 15 // Pin connected to the red LED

BlynkTimer timer;

// Function to turn on the fan

void turnFanOn() {

digitalWrite(RELAY_PIN, HIGH); // Turn on the relay

}

// Function to turn off the fan

void turnFanOff() {

digitalWrite(RELAY_PIN, LOW); // Turn off the relay

}

// Function to sound the buzzer

void soundBuzzer() {

tone(BUZZER_PIN, 1000, 1000); // Sound the buzzer for 1 second

}

void setup() {

// Debug console

Serial.begin(9600);

pinMode(RELAY_PIN, OUTPUT);

pinMode(BUZZER_PIN, OUTPUT);

pinMode(GREEN_LED_PIN, OUTPUT);

pinMode(RED_LED_PIN, OUTPUT);

// Connect to WiFi

Blynk.begin(auth, ssid, pass);

// Setup virtual pins

// V0 - Fan control button

// V1 - Buzzer button

// V2 - Green LED button

// V3 - Red LED button

Blynk.virtualWrite(V0, 0);

Blynk.virtualWrite(V1, 0);

Blynk.virtualWrite(V2, 0);

Blynk.virtualWrite(V3, 0);

// Attach virtual pin handlers

Blynk.virtualWrite(V0, 0);

Blynk.virtualWrite(V1, 0);

Blynk.virtualWrite(V2, 0);

Blynk.virtualWrite(V3, 0);

}

BLYNK_WRITE(V0) {

int fanValue = param.asInt();

if (fanValue == 1) {

turnFanOn();

} else {

turnFanOff();

}

}

BLYNK_WRITE(V1) {

int buzzerValue = param.asInt();

if (buzzerValue == 1) {

soundBuzzer();

}

}

BLYNK_WRITE(V2) {

int greenLedValue = param.asInt();

digitalWrite(GREEN_LED_PIN, greenLedValue);

}

BLYNK_WRITE(V3) {

int redLedValue = param.asInt();

digitalWrite(RED_LED_PIN, redLedValue);

}

void loop() {

Blynk.run();

  timer.run();

}

بطاقة العمل

اسم المستقل Msutafa M.
عدد الإعجابات 0
عدد المشاهدات 6
تاريخ الإضافة
تاريخ الإنجاز