/Smart-Stick

Empowering independent mobility with an intelligent, sensor-packed walking companion.

Primary LanguageC++

Smart-Stick

Documentation

Project Overview

Blind Stick Simulation

image

Component's Used 💡

Name Quantity Component Usage
U1 1 Arduino Uno R3 Microcontroller board for programming and controlling the project
DIST1 1 Ultrasonic Distance Sensor (4-pin) Measures the distance to an object using ultrasonic waves
M1 1 Vibration Motor Creates vibrations or motion for tactile feedback or other purposes
PIEZO1 1 Piezo Produces sound or tones, often used as a buzzer or speaker

Sketch

Code

Code Explanation ©️

This code is written in Arduino programming language, which is based on C/C++. It is designed to control an ultrasonic sensor for measuring the distance of an object and then react accordingly by turning on or off a buzzer and a motor based on the measured distance. Here is a breakdown of the code:

Variable Declarations:

  • trigPin: An integer variable used to define the pin number connected to the trigger pin of the ultrasonic sensor.
  • echoPin: An integer variable used to define the pin number connected to the echo pin of the ultrasonic sensor.
  • buzzer: An integer variable for the pin number attached to the buzzer.
  • motorPin: An integer variable for the pin number connected to the motor.
  • duration: A long variable to store the time between sending and receiving the sound pulse.
  • distance: An integer variable to store the calculated distance.
  • safetyDistance: An integer variable used to set a threshold distance at which the buzzer and motor are activated.

setup() Function:

This is called when the Arduino board starts:

  • pinMode(): Sets the mode of specified pins. trigPin and buzzer are set as OUTPUT because they send signals, while echoPin is set as INPUT to receive signals.
  • Serial.begin(9600): Initializes serial communication at a baud rate of 9600, used for data transmission between the Arduino board and a computer or other devices.

loop() Function:

This function runs continuously after setup() is finished:

  • Sends a short high pulse to the trigPin to trigger the ultrasonic pulse. This is done by first setting it to LOW for a brief period (to ensure a clean pulse), then to HIGH for 10 microseconds, and back to LOW.
  • pulseIn(echoPin, HIGH): Measures the duration of the incoming pulse. This is the time taken for the echo to be received after the sound wave is transmitted.
  • The distance is calculated based on the duration of the echo. The speed of sound is approximately 340 meters per second (0.034 cm/µs), and since the sound has to travel to the object and back, the distance is half the product of the speed of sound and the time (duration).
  • safetyDistance is then compared to a predefined value (30 in this case). If the calculated distance is less than or equal to safetyDistance, the buzzer and motor are turned on (set HIGH); otherwise, they are turned off (set LOW).
  • Finally, the distance is printed to the Serial Monitor, which allows you to view the distance on your computer using the Arduino IDE.

In summary, this code continuously measures the distance using an ultrasonic sensor. If the object is within 200 cm, it activates a buzzer and a motor; otherwise, it deactivates them. This could be used in various applications like obstacle avoidance in robotics.

Reference Research Articles 📰

Join the Collaborative Effort 🖋️

Contribute