it seems that the wifi is not connecting.Can anybody help
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <ESP32Servo.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6heJrl5GS"
#define BLYNK_TEMPLATE_NAME "SMART PIGEON HOLE"
#define BLYNK_AUTH_TOKEN "ovExbhLNfo7nReW_ryT03XzyvEPU0NOz"
// Define servos
Servo servoA;
Servo servoB;
Servo servoC;
// Define LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define keypad
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'3', '2', '1'},
{'6', '5', '4'},
{'9', '8', '7'},
{'#', '0', '*'}
};
byte rowPins[ROWS] = {19, 18, 5, 17};
byte colPins[COLS] = {2, 4, 16};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Define pins
int relay1 = 26;
int relay2 = 27;
// Blynk authentication token
char auth[] = "ovExbhLNfo7nReW_ryT03XzyvEPU0NOz";
// Wi-Fi credentials
char ssid[] = "omar";
char pass[] = "password";
String server = "http://maker.ifttt.com";
String eventName = "pigeonhole";
String IFTTT_Key = "bH9MiYG5YTNq8YZn3qoz6o";
bool relay2State = false; // State of relay2
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
// Initialize Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
// Wait for Wi-Fi connection
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize Blynk
Blynk.begin(auth, ssid, pass);
// Sync the initial state of the switch widget with relay2State
Blynk.syncVirtual(V3);
servoA.attach(25);
servoB.attach(33);
servoC.attach(32);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
lcd.print("Enter Matrix No.");
}
// Add this function to handle incoming virtual pin writes
BLYNK_WRITE(V3) {
int switchState = param.asInt(); // Read the value from the switch widget
// Update relay2State based on the switch state
relay2State = (switchState == 0); // 0 in the switch widget turns relay2 on
// Update the relay2 state accordingly
digitalWrite(relay2, relay2State);
}
void sendDataToSheet(String matrixNo, String compartment) {
String url = server + "/trigger/" + eventName + "/with/key/" + IFTTT_Key + "?value1=" + matrixNo + "&value2=" + compartment;
Serial.println(url);
//Start to send data to IFTTT
HTTPClient http;
Serial.print("[HTTP] begin...\n");
http.begin(url); //HTTP
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void loop() {
Blynk.run(); // Handle Blynk communication
char key = keypad.getKey();
if (key != NO_KEY) {
static String matrixNo;
matrixNo += key;
lcd.setCursor(0, 1);
lcd.print(matrixNo);
if (matrixNo.length() == 6) {
lcd.clear();
lcd.print("Select Compartment");
char compartment = NO_KEY;
while (compartment == NO_KEY) {
compartment = keypad.getKey();
delay(50);
}
lcd.clear();
lcd.print("Submitting...");
if (compartment == '1') {
openCompartment(servoA, relay1, matrixNo, String("1"));
} else if (compartment == '2') {
openCompartment(servoB, relay1, matrixNo, String("2"));
} else if (compartment == '3') {
openCompartment(servoC, relay1, matrixNo, String("3"));
}
matrixNo = "";
lcd.clear();
lcd.print("Enter Matrix No.");
}
}
}
void openCompartment(Servo& servo, int relayPin, String matrixNo, String compartment) {
servo.write(90);
delay(1000);
digitalWrite(relayPin, LOW);
lcd.clear();
lcd.print("Paper Inserted? (1=yes, 0=no)");
char confirmation = NO_KEY;
while (confirmation == NO_KEY) {
confirmation = keypad.getKey();
delay(50);
}
if (confirmation == '1') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Submission");
lcd.setCursor(0, 1);
lcd.print("Successful");
delay(2000);
digitalWrite(relayPin, HIGH);
relay2State = !relay2State; // Toggle relay2 state
digitalWrite(relay2, relay2State); // Update relay2
Blynk.logEvent("budakhantar"); // Log event
// Update switch widget state in Blynk
Blynk.virtualWrite(V3, relay2State);
// Send data to Google Sheets with a delay of 10 seconds
sendDataToSheet(matrixNo, String(compartment));
delay(10000);
} else if (confirmation == '0') {
lcd.clear();
lcd.print("Submission");
lcd.setCursor(0, 1);
lcd.print("Unsuccessful");
delay(2000);
digitalWrite(relayPin, HIGH);
}
servo.write(0);
}

