// Define Blynk settings
#define BLYNK_TEMPLATE_ID "TMPL3FR9dY-_A"
#define BLYNK_TEMPLATE_NAME "SMART GLASSES FOR VISUALLY BLIND"
#define BLYNK_AUTH_TOKEN "W0UQHwSq9Dhcz1WnUfMhgtRtjp16gwi1"
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// #include <TinyGPSPlus.h> // GPS library is commented out
// Ultrasonic Sensor Pins
#define TRIG_PIN1 14
#define ECHO_PIN1 13
#define TRIG_PIN2 45
#define ECHO_PIN2 48
// IR Sensor Pins
#define IR_PIN1 15
#define IR_PIN2 42
#define IR_PIN3 35
// DHT22 Sensor Settings
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Buzzer Pin
#define BUZZER_PIN 12
// Temperature Sensor Pins
#define ONE_WIRE_BUS 18
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// GPS Settings
// TinyGPSPlus gps; // GPS object is commented out
// HardwareSerial gpsSerial(1); // RX, TX // GPS serial object is commented out
// WiFi and Blynk settings
char ssid[] = "Hash";
char pass[] = "contrasena";
// ThingSpeak settings
unsigned long myChannelNumber = 2628555;
const char * myWriteAPIKey = "TSBK165SONTOXYR1Y";
WiFiClient client;
void setup() {
Serial.begin(115200);
// gpsSerial.begin(9600); // GPS serial initialization is commented out
// Initialize sensors and modules
pinMode(TRIG_PIN1, OUTPUT);
pinMode(ECHO_PIN1, INPUT);
pinMode(TRIG_PIN2, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(IR_PIN1, INPUT);
pinMode(IR_PIN2, INPUT);
pinMode(IR_PIN3, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
dht.begin();
sensors.begin();
// Initialize WiFi, Blynk, and ThingSpeak
WiFi.begin(ssid, pass);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// ThingSpeak.begin(client);
}
void loop() {
Blynk.run();
checkUltrasonicSensors();
checkIRSensors();
checkTemperature();
// checkGPS(); // GPS check function is commented out
delay(2000); // delay between checks
}
void checkUltrasonicSensors() {
long duration1, distance1, duration2, distance2;
// Ultrasonic 1
digitalWrite(TRIG_PIN1, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN1, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN1, LOW);
duration1 = pulseIn(ECHO_PIN1, HIGH);
distance1 = (duration1 * 0.034) / 2;
// Ultrasonic 2
digitalWrite(TRIG_PIN2, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN2, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN2, LOW);
duration2 = pulseIn(ECHO_PIN2, HIGH);
distance2 = (duration2 * 0.034) / 2;
// Object detection
if (distance1 < 50 || distance2 < 50) {
Serial.println("Obstacle ahead");
// tone(BUZZER_PIN, 1000, 200); // Uncomment if buzzer needed
}
// Stairs detection (up or down)
if (distance1 > distance2 + 10) {
Serial.println("Stairs down detected");
} else if (distance2 > distance1 + 10) {
Serial.println("Stairs up detected");
}
}
void checkIRSensors() {
int ir1 = digitalRead(IR_PIN1);
int ir2 = digitalRead(IR_PIN2);
int ir3 = digitalRead(IR_PIN3);
// Hole or gap detection
if ((ir1 == LOW && ir2 == LOW) || (ir2 == LOW && ir3 == LOW) || (ir1 == LOW && ir3 == LOW)) {
Serial.println("Gap detected");
// tone(BUZZER_PIN, 1500, 200); // Uncomment if buzzer needed
}
}
void checkTemperature() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
float tempDHT = dht.readTemperature();
if (temperature > 30 || tempDHT > 30) {
Serial.println("Hot object detected");
// tone(BUZZER_PIN, 1000, 200); // Uncomment if buzzer needed
}
}
// void checkGPS() { // GPS function is commented out
// while (gpsSerial.available() > 0) {
// gps.encode(gpsSerial.read());
// if (gps.location.isUpdated()) {
// float latitude = gps.location.lat();
// float longitude = gps.location.lng();
//
// // Send location to ThingSpeak
// ThingSpeak.setField(1, latitude);
// ThingSpeak.setField(2, longitude);
// ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
//
// Serial.print("Location updated: ");
// Serial.print("Latitude: ");
// Serial.print(latitude, 6);
// Serial.print(", Longitude: ");
// Serial.println(longitude, 6);
// }
// }
// }