22. Creating a Smart Stick for visually challenged peoples with GPS and Ultrasonic Sensors

Introduction :-
    In this project, we'll build a "Smart Blind Stick" that uses GPS and ultrasonic sensors to assist visually impaired individuals in navigating their surroundings. This device can detect obstacles, provide water alerts, and send SOS messages with GPS coordinates to a predefined contact. We'll break down the project step by step and provide the Arduino code for each component.

Components Needed :

    1. Arduino Uno or compatible board

    2. Ultrasonic distance sensors (HC-SR04)

    3. GPS module (NEO-6M or similar)

    4. GSM module (SIM800C or equivalent)

    5. Buzzer

    6. Push-button (for SOS)

    7. Power source (e.g., battery or power bank)

    8. Jumper wires

Arduino Code :

C++
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

float latitude, longitude;
float gpsData[2];
String message = "Please Help Me.";
String mapLink = "My current Location is https://www.google.com/maps/place/";
String mapLinkWithCoords;
String incomingData = "";
String response = "";
SoftwareSerial gpsSerial(2, 3); // GPS module connected to pins 2 (RX) and 3 (TX)
SoftwareSerial gsmSerial(4, 5); // GSM module connected to pins 4 (RX) and 5 (TX)
int sosButton = 6;
int buzzerPin = 7;
TinyGPSPlus gps;

// Ultrasonic sensor pins
const int trigPin1 = A0;
const int echoPin1 = A1;
long duration1;
int distance1;

const int trigPin2 = A2;
const int echoPin2 = A3;
long duration2;
int distance2;

void setup() {
    pinMode(trigPin1, OUTPUT);
    pinMode(echoPin1, INPUT);
    pinMode(buzzerPin, OUTPUT);
    pinMode(A4, INPUT_PULLUP);
    Serial.begin(9600);
    
    pinMode(trigPin2, OUTPUT);
    pinMode(echoPin2, INPUT);
    pinMode(sosButton, INPUT_PULLUP);
    delay(1000);

    // Initialize serial communication with GPS and GSM modules
    gpsSerial.begin(9600);
    delay(1000);
    gsmSerial.begin(9600);
    delay(1000);

    // Initialize GSM module
    gsmSerial.println("AT");
    gsmSerial.println("AT+CMGF=1");
    delay(3000);
    Serial.print("Initializing...");
    delay(2000);
    Serial.print("System Ready");
    delay(1000);

    // Forward data between Arduino Serial Monitor and GSM module
    while (Serial.available()) {
        gsmSerial.write(Serial.read());
    }

    while (gsmSerial.available()) {
        Serial.write(gsmSerial.read());
    }
}

// Helper function to flash the buzzer
void flash(int duration) {
    digitalWrite(buzzerPin, HIGH);
    delay(duration);
    digitalWrite(buzzerPin, LOW);
    delay(duration);
}

// SOS signal using the buzzer
void Sos() {
    flash(200); flash(500); flash(200); // S
    flash(500); flash(500); flash(500); // O
    flash(200); flash(200); flash(200); // S
}

void loop() {
    // Ultrasonic sensor measurements
    digitalWrite(trigPin1, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin1, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin1, LOW);
    duration1 = pulseIn(echoPin1, HIGH);
    distance1 = duration1 * 0.034 / 2;
    Serial.print("Distance1: ");
    Serial.println(distance1);
    
    digitalWrite(trigPin2, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin2, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin2, LOW);
    duration2 = pulseIn(echoPin2, HIGH);
    distance2 = duration2 * 0.034 / 2;
    Serial.print("Distance2: ");
    Serial.println(distance2);
    
    // Obstacle detection using the buzzer
    if (distance1 <= 20 || distance2 <= 20) {
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
    } else if (distance1 <= 15 || distance2 <= 15) {
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
    } else {
        digitalWrite(buzzerPin, LOW);
    }

    // Water alert detection
    int waterSensorValue = digitalRead(A4);
    if (waterSensorValue == 1) {
        digitalWrite(buzzerPin, HIGH);
        Serial.println("Water Alert");
        delay(1500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(1500);
    } else {
        digitalWrite(buzzerPin, LOW);
    }

    // SOS button press
    if (digitalRead(sosButton) == LOW) {
        Serial.println("SOS button pressed");
        delay(2000);
        Sos();
        get_gps();
        SendMessage();
    }

    // GSM module data handling
    if (gsmSerial.available() > 0) {
        Serial.write(gsmSerial.read());
    }

    while (gsmSerial.available()) {
        gsmSerial.read();
    }

    while (Serial.available()) {
        Serial.read();
    }

    Find();
}

// Function to retrieve GPS coordinates
float *get_gps() {
    gpsSerial.listen();
    Serial.println("INSIDE get_gps");
    while (1) {
        while (gpsSerial.available() > 0) {
            gps.encode(gpsSerial.read());
        }
        if (gps.location.isUpdated()) {
            Serial.print("LAT=");
            Serial.println(gps.location.lat(), 6);
            Serial.print("LONG=");
            Serial.println(gps.location.lng(), 6);
            latitude = gps.location.lat();
            longitude = gps.location.lng();
            break;
        }
    }
    gpsData[0] = latitude;
    gpsData[1] = longitude;
    return gpsData;
}

void prepare_message() {
    Serial.println(latitude);
    Serial.println(longitude);
    mapLink = message + "," + mapLink + latitude + "," + longitude;
    mapLinkWithCoords = mapLink + latitude + "," + longitude;
    Serial.println(mapLink);
    Serial.println(mapLinkWithCoords);
}

void SendMessage() {
    prepare_message();
    gsmSerial.println("AT+CMGF=1");
    delay(1000);
    gsmSerial.println("AT+CMGS=\"+918825xxxxxx\"\r"); // Replace with your recipient's phone number
    delay(1000);
    gsmSerial.println("I Am In Problem Plz Help Me");
    delay(1000);
    gsmSerial.println(mapLink);
    delay(1000);
    gsmSerial.println((char)26);
    delay(1000);
}

void Find() {
    if (gsmSerial.available()) {
        char a = gsmSerial.read();
        Serial.write(a);
        incomingData = incomingData + String(a);
        if (a == 13)
            incomingData = "";
        incomingData.trim();
        if (incomingData == "RING") {
            Serial.println("Sending SMS");
            delay(1000);
            response = gsmSerial.println("ATH");
            delay(1000);
            response = gsmSerial.println("ATE0");
            delay(1000);
            response = "";
            incomingData = "";
            gsmSerial.println("AT+CIPGSMLOC=1,1");
            delay(5000);
            while (gsmSerial.available()) {
                char letter = gsmSerial.read();
                response = response + String(letter);
            }
            Serial.print("Result Obtained as:");
            Serial.print(response);
            Serial.println("*******");
            prepare_message();
            delay(1000);
            gsmSerial.println("AT+CMGF=1");
            delay(1000);
            gsmSerial.println("AT+CMGS=\"88xxxxxxxx\""); // Replace with your recipient's phone number
            delay(1000);
            gsmSerial.println(mapLinkWithCoords);
            delay(1000);
            gsmSerial.println((char)26);
            delay(1000);
        }
    }
}

Circuit Diagram :-

Let's break down the code step by step to understand its functionality :

Step 1 : Include Libraries

C++
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

The code starts by including two libraries:
    1. SoftwareSerial.h : This library is used to create software serial communication channels on Arduino digital pins.
    2.TinyGPS++.h : This library is used for parsing GPS data.

Step 2 : Declare Global Variables

C++
float lattitude, longitude;
float a[2];
float *p;
String msg = "Please Help Me.";
String Link = "My current Location is https://www.google.com/maps/place/";
String Link1;
String incoming = "";
String responce = "";
SoftwareSerial gpsdata(2, 3);
SoftwareSerial gsmdata(4, 5);
int sos = 6;
int Buzzer = 7;
TinyGPSPlus gps;
const int trigPin1 = A1;
const int echoPin1 = A0;
long duration1;
int distance1;
const int trigPin2 = A2;
const int echoPin2 = A3;
long duration2;
int distance2;

    Here, various global variables are declared. These variables will be used throughout the code to store GPS coordinates, messages, URLs, sensor data, and communication with the GPS and GSM modules. Additionally, pins for various components (ultrasonic sensors, buzzer, SOS button) are defined.

Step 3 : Setup Function

C++
void setup()
{
    pinMode(trigPin1, OUTPUT);
    pinMode(echoPin1, INPUT);
    pinMode(buzzerPin, OUTPUT);
    pinMode(A4, INPUT_PULLUP);
    Serial.begin(9600);
    
    pinMode(trigPin2, OUTPUT);
    pinMode(echoPin2, INPUT);
    pinMode(sosButton, INPUT_PULLUP);
    delay(1000);

    // Initialize serial communication with GPS and GSM modules
    gpsSerial.begin(9600);
    delay(1000);
    gsmSerial.begin(9600);
    delay(1000);

    // Initialize GSM module
    gsmSerial.println("AT");
    gsmSerial.println("AT+CMGF=1");
    delay(3000);
    Serial.print("Initializing...");
    delay(2000);
    Serial.print("System Ready");
    delay(1000);

    // Forward data between Arduino Serial Monitor and GSM module
    while (Serial.available()) {
        gsmSerial.write(Serial.read());
    }

    while (gsmSerial.available()) {
        Serial.write(gsmSerial.read());
    }
}


    The `setup()` function initializes the system and sets up the communication with the GPS and GSM modules. It configures pins, initializes serial communication, and prepares the GSM module for text messages.

Step 4: `flash()` and `Sos()` Functions

python
void flash(int duration) {
    digitalWrite(buzzerPin, HIGH);
    delay(duration);
    digitalWrite(buzzerPin, LOW);
    delay(duration);
}

// SOS signal using the buzzer
void Sos() {
    flash(200); flash(500); flash(200); // S
    flash(500); flash(500); flash(500); // O
    flash(200); flash(200); flash(200); // S
}

    These functions are utility functions used for controlling the buzzer to generate SOS signals. The `flash()` function takes a duration as input and toggles the buzzer on and off with that duration. The `Sos()` function uses `flash()` to produce the SOS pattern.

Step 5 : `loop()` Function

C++
void loop()
{
 // Ultrasonic sensor measurements
    digitalWrite(trigPin1, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin1, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin1, LOW);
    duration1 = pulseIn(echoPin1, HIGH);
    distance1 = duration1 * 0.034 / 2;
    Serial.print("Distance1: ");
    Serial.println(distance1);
    
    digitalWrite(trigPin2, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin2, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin2, LOW);
    duration2 = pulseIn(echoPin2, HIGH);
    distance2 = duration2 * 0.034 / 2;
    Serial.print("Distance2: ");
    Serial.println(distance2);
    
    // Obstacle detection using the buzzer
    if (distance1 <= 20 || distance2 <= 20) {
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
    } else if (distance1 <= 15 || distance2 <= 15) {
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
    } else {
        digitalWrite(buzzerPin, LOW);
    }

    // Water alert detection
    int waterSensorValue = digitalRead(A4);
    if (waterSensorValue == 1) {
        digitalWrite(buzzerPin, HIGH);
        Serial.println("Water Alert");
        delay(1500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(1500);
    } else {
        digitalWrite(buzzerPin, LOW);
    }

    // SOS button press
    if (digitalRead(sosButton) == LOW) {
        Serial.println("SOS button pressed");
        delay(2000);
        Sos();
        get_gps();
        SendMessage();
    }

    // GSM module data handling
    if (gsmSerial.available() > 0) {
        Serial.write(gsmSerial.read());
    }

    while (gsmSerial.available()) {
        gsmSerial.read();
    }

    while (Serial.available()) {
        Serial.read();
    }

    Find();
}

    The `loop()` function is the main execution loop of the Arduino. It continuously checks various conditions and performs actions based on sensor data and incoming GSM commands.

Step 6 : Ultrasonic Distance Sensing

C++
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = duration1 * 0.034 / 2;

    This block of code measures the distance from an obstacle using an ultrasonic sensor (trigPin1 and echoPin1). It sends a pulse to trigger the sensor and calculates the distance based on the time taken for the pulse to bounce back.

Step 7 : Buzzer Alerts for Obstacles

C++
if (distance1 <= 20 || distance2 <= 20) {
 digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
}
else if (distance1 <= 15 || distance2 <= 15) {
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(500);
        digitalWrite(buzzerPin, LOW);
}
else
digitalWrite(Buzzer, LOW);

    Depending on the measured distances from the ultrasonic sensors, this section activates the buzzer to alert the user if an obstacle is detected.

Step 8 : Water Sensor

C++
int sensorValue = digitalRead(A4);
if (sensorValue == 1) {
        digitalWrite(buzzerPin, HIGH);
        Serial.println("Water Alert");
        delay(1500);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(buzzerPin, HIGH);
        delay(1500);
}
else
digitalWrite(Buzzer, LOW);

    This block of code checks the status of a water sensor connected to pin A4. If water is detected, it activates the buzzer to alert the user.

Step 9 : SOS Button

C++
if (digitalRead(sosButton) == LOW) {
        Serial.println("SOS button pressed");
        delay(2000);
        Sos();
        get_gps();
        SendMessage();
    }

    This section monitors the state of an SOS button. If the button is pressed, it generates an SOS signal using the `Sos()` function and sends an SOS message using the `SendMessage()` function.

Step 10 : GSM Communication and GPS Data Retrieval

C++
if (gsmdata.available() > 0)
Serial.write(gsmdata.read());


while (gsmdata.available())
{
gsmdata.read();
}


while (Serial.available())
{
Serial.read();
}


Find();
}


    This part of the code handles GSM communication. It checks for incoming GSM data, forwards it between the Arduino and GSM module, and calls the `Find()` function to handle specific GSM responses.

Step 11 : `get_gps()`, `prepare_message()`, and `SendMessage()` Functions

    These functions are responsible for GPS data retrieval and sending messages with GPS coordinates and Google Maps links.

Step 12 : `Find()` Function

C++
void Find() {
    if (gsmSerial.available()) {
        char a = gsmSerial.read();
        Serial.write(a);
        incomingData = incomingData + String(a);
        if (a == 13)
            incomingData = "";
        incomingData.trim();
        if (incomingData == "RING") {
            Serial.println("Sending SMS");
            delay(1000);
            response = gsmSerial.println("ATH");
            delay(1000);
            response = gsmSerial.println("ATE0");
            delay(1000);
            response = "";
            incomingData = "";
            gsmSerial.println("AT+CIPGSMLOC=1,1");
            delay(5000);
            while (gsmSerial.available()) {
                char letter = gsmSerial.read();
                response = response + String(letter);
            }
            Serial.print("Result Obtained as:");
            Serial.print(response);
            Serial.println("*******");
            prepare_message();
            delay(1000);
            gsmSerial.println("AT+CMGF=1");
            delay(1000);
            gsmSerial.println("AT+CMGS=\"88xxxxxxxx\""); // Replace with your recipient's phone number
            delay(1000);
            gsmSerial.println(mapLinkWithCoords);
            delay(1000);
            gsmSerial.println((char)26);
            delay(1000);
        }
    }
}

    The `Find()` function monitors incoming GSM data and responds to specific commands. It retrieves GPS location data and sends it as a message when a "RING" command is received.

Project Overview :

1. Ultrasonic Sensors : The project uses two ultrasonic sensors to measure distances in front of the blind stick. If an obstacle is detected within a certain range, the buzzer produces sound signals to alert the user.

2. Water Alert : A water sensor is used to detect water or wet surfaces. If water is detected, the buzzer will sound to notify the user.

3. SOS Button : A dedicated SOS button is included. When pressed, it triggers an SOS signal using the buzzer and sends an SOS message with GPS coordinates to a predefined contact.

4. GPS Module : The GPS module provides real-time latitude and longitude coordinates, which are included in the SOS message. It uses the TinyGPS++ library for parsing GPS data.

5. GSM Module : The GSM module enables communication by sending SMS messages. It's used to send SOS messages and respond to incoming calls.

6. Serial Communication : Serial communication is established between the Arduino board, GPS module, and GSM module to transmit data.

Note : Be sure to replace placeholders such as phone numbers (`+918825xxxxxx`, `88xxxxxxxx`) with your actual phone numbers. Additionally, verify the connections of the components according to your hardware setup.

    This "Smart Blind Stick" project provides a comprehensive solution for assisting visually impaired individuals in navigating their environment safely. The combination of GPS and ultrasonic sensors, along with the SOS functionality, ensures that users can seek help and stay aware of obstacles and water hazards.
Post a Comment (0)
Previous Post Next Post