JEEVAN L
Created September 4, 2024

VisionSense

VisionSense: Advanced Ultrasonic Blind Stick with GPS Tracking for Enhanced Mobility and Safety

12
VisionSense

Things used in this project

Story

Read more

Schematics

VisionSense block diagram

VisionSense: Advanced Ultrasonic Blind Stick with GPS Tracking for Enhanced Mobility and Safety

VisionSense image

VisionSense: Advanced Ultrasonic Blind Stick with GPS Tracking for Enhanced Mobility and Safety

Code

VisionSense

C/C++
VisionSense: Advanced Ultrasonic Blind Stick with GPS Tracking for Enhanced Mobility and Safety
#include <avr/io.h>
#include <util/delay.h>
#include "uart.h"  // For GSM & GPS Communication
#include "lcd.h"   // For LCD Display

#define F_CPU 16000000UL
#define TRIG_PIN PD0
#define ECHO_PIN PD1
#define WATER_SENSOR_PIN PD2
#define LDR_PIN PC0
#define BUZZER_PIN PB0

void init_ports() {
    DDRD |= (1 << TRIG_PIN);           // Set TRIG_PIN as output
    DDRD &= ~(1 << ECHO_PIN);          // Set ECHO_PIN as input
    DDRD &= ~(1 << WATER_SENSOR_PIN);  // Set WATER_SENSOR_PIN as input
    DDRC &= ~(1 << LDR_PIN);           // Set LDR_PIN as input
    DDRB |= (1 << BUZZER_PIN);         // Set BUZZER_PIN as output
}

void trigger_ultrasonic() {
    PORTD |= (1 << TRIG_PIN);
    _delay_us(10);
    PORTD &= ~(1 << TRIG_PIN);
}

uint16_t measure_distance() {
    trigger_ultrasonic();
    uint16_t count = 0;
    while (!(PIND & (1 << ECHO_PIN)));
    while (PIND & (1 << ECHO_PIN)) count++;
    return (count / 58);  // Convert to cm
}

void check_water() {
    if (!(PIND & (1 << WATER_SENSOR_PIN))) {
        PORTB |= (1 << BUZZER_PIN);
        lcd_clear();
        lcd_print("Water Detected!");
    } else {
        PORTB &= ~(1 << BUZZER_PIN);
    }
}

void check_light() {
    if (PINC & (1 << LDR_PIN)) {
        lcd_set_cursor(1, 0);
        lcd_print("Light Detected");
    } else {
        lcd_set_cursor(1, 0);
        lcd_print("Darkness Detected");
    }
}

void send_gps_data() {
    uart_init(9600);
    uart_send_string("AT+CGNSPWR=1\r");
    _delay_ms(1000);
    uart_send_string("AT+CGNSINF\r");
    char gps_data[100];
    uart_receive_string(gps_data, 100);
    uart_send_string("AT+CMGF=1\r");  // Set SMS mode
    uart_send_string("AT+CMGS=\"+1234567890\"\r");  // Replace with your number
    uart_send_string(gps_data);
    uart_send_char(26);  // Send CTRL+Z to send the SMS
}

int main(void) {
    lcd_init();
    init_ports();
    lcd_print("VisionSense Ready");

    while (1) {
        uint16_t distance = measure_distance();
        lcd_set_cursor(0, 0);
        lcd_print("Distance: ");
        lcd_print_num(distance);
        lcd_print(" cm");

        check_water();
        check_light();

        if (distance < 30) {
            PORTB |= (1 << BUZZER_PIN);
        } else {
            PORTB &= ~(1 << BUZZER_PIN);
        }

        _delay_ms(1000);
    }
}

Credits

JEEVAN L

JEEVAN L

1 project • 0 followers

Comments