Sahana
Created August 29, 2024

Smart Mobility Aid with GPS and Obstacle Detection

Smart Mobility Aid: GPS and obstacle detection for safer, independent navigation with real-time feedback.

22
Smart Mobility Aid with GPS and Obstacle Detection

Things used in this project

Hardware components

Seeed Studio XIAO ESP32S3 Sense
Seeed Studio XIAO ESP32S3 Sense
×1
Blues Notecard (Cellular)
Blues Notecard (Cellular)
×1
Aaware Ultrasonic Sensors
×1
Solar Cockroach Vibrating Disc Motor
Brown Dog Gadgets Solar Cockroach Vibrating Disc Motor
×1
9V battery (generic)
9V battery (generic)
×1

Story

Read more

Code

code

C/C++
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM6DSOX.h>
#include <Adafruit_LIS3MDL.h>
#include <Notecard.h>

// Define pins for ultrasonic sensor
const int trigPin = 9;
const int echoPin = 10;
const int motorPin = 8;  // For haptic feedback

// Define distance threshold (in cm)
const int threshold = 30;

// Instantiate Notecard object
Notecard notecard;

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorPin, OUTPUT);

  // Ensure motor is off initially
  digitalWrite(motorPin, LOW);

  // Initialize Notecard
  notecard.begin();
  notecard.sendRequest("card.status");

  // Configure GPS
  notecard.sendRequest("{\"req\":\"card.location.mode\",\"mode\":\"periodic\",\"seconds\":60}");
}

void loop() {
  // Send a pulse to trigger the ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the echo time
  long duration = pulseIn(echoPin, HIGH);
  int distance = duration * 0.034 / 2; // Calculate distance in cm

  // Check if an obstacle is within the threshold
  if (distance <= threshold && distance > 0) {
    // Activate haptic feedback
    digitalWrite(motorPin, HIGH);
  } else {
    // Deactivate haptic feedback
    digitalWrite(motorPin, LOW);
  }

  // Request GPS data
  J *req = notecard.newRequest("card.location");
  if (req != NULL) {
    J *rsp = notecard.sendRequest(req);
    if (rsp != NULL) {
      Serial.println(JGetString(rsp, "status"));
      Serial.println(JGetString(rsp, "mode"));
      JDelete(rsp);
    }
  }

  // Short delay before next measurement
  delay(100);

Credits

Sahana

Sahana

1 project • 1 follower

Comments