Codecoding
Codecoding
h>
#include <BlynkSimpleEsp32.h>
// WiFi credentials
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
void setup() {
pinMode(RPWM_PIN, OUTPUT);
pinMode(LPWM_PIN, OUTPUT);
pinMode(R_EN_PIN, OUTPUT);
pinMode(L_EN_PIN, OUTPUT);
pinMode(LIMIT_SWITCH_OPEN_PIN, INPUT_PULLUP);
pinMode(LIMIT_SWITCH_CLOSE_PIN, INPUT_PULLUP);
void loop() {
Blynk.run();
}
BLYNK_WRITE(VIRTUAL_OPEN_BTN) {
int openButtonState = param.asInt();
if (openButtonState == HIGH) {
if (digitalRead(LIMIT_SWITCH_OPEN_PIN) == LOW) {
// Gate is already fully open
return;
}
// Move the gate in the open direction
enableMotors(true); // Enable motors
analogWrite(RPWM_PIN, 255); // Adjust PWM value for desired speed
analogWrite(LPWM_PIN, 255); // Adjust PWM value for desired speed
} else {
// Stop the motor
analogWrite(RPWM_PIN, 0);
analogWrite(LPWM_PIN, 0);
enableMotors(false); // Disable motors
}
}
BLYNK_WRITE(VIRTUAL_CLOSE_BTN) {
int closeButtonState = param.asInt();
if (closeButtonState == HIGH) {
if (digitalRead(LIMIT_SWITCH_CLOSE_PIN) == LOW) {
// Gate is already fully closed
return;
}
// Move the gate in the close direction
enableMotors(true); // Enable motors
analogWrite(RPWM_PIN, 255); // Adjust PWM value for desired speed
analogWrite(LPWM_PIN, 255); // Adjust PWM value for desired speed
} else {
// Stop the motor
analogWrite(RPWM_PIN, 0);
analogWrite(LPWM_PIN, 0);
enableMotors(false); // Disable motors
}
}