Translate

Arduino Talking Distance Sensor

 1. Introduction

An Arduino Talking Distance Sensor is a smart project that measures the distance of an object and announces it using voice output. This is especially useful for applications like assistive devices for visually impaired people, obstacle detection systems, and smart robotics.

The system uses an ultrasonic sensor to measure distance and a voice playback module or text-to-speech module to output the distance as audio.


2. Components

  • Arduino UNO / Nano
  • Ultrasonic Sensor (HC-SR04)
  • DFPlayer Mini MP3 Module (or ISD1820 voice module)
  • Speaker (3W recommended)
  • MicroSD Card (for DFPlayer)
  • Jumper Wires
  • Breadboard
  • Resistor (1kΩ for safety on RX pin)
  • Power Supply

3. Circuit and Connections

Pinout Diagram of Arduino Uno R3

Pin Diagram Ultrasonic Sensor
Pinout Diagram of DF Player Mini


Ultrasonic Sensor (HC-SR04)

  • VCC → 5V
  • GND → GND
  • TRIG → Pin 9
  • ECHO → Pin 10

DFPlayer Mini Module

  • VCC → 5V
  • GND → GND
  • TX → Arduino Pin 2
  • RX → Arduino Pin 3 (via 1kΩ resistor)
  • SPK1 & SPK2 → Speaker

4. Detailed Step By Step Circuit Working

  1. The ultrasonic sensor sends a high-frequency sound pulse using the TRIG pin.
  2. The sound wave hits an object and reflects back.
  3. The ECHO pin receives the reflected signal.
  4. Arduino calculates the time taken for the echo to return.
  5. Using this time, distance is calculated using the formula:
    Distance = (Time × Speed of Sound) / 2
  6. Based on the measured distance, Arduino selects a corresponding audio file stored in the DFPlayer.
  7. The DFPlayer plays the audio through the speaker (e.g., “10 centimeters”).

5. Code

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

SoftwareSerial mySerial(2, 3);
DFRobotDFPlayerMini player;

int trigPin = 9;
int echoPin = 10;

long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

mySerial.begin(9600);
Serial.begin(9600);

if (!player.begin(mySerial)) {
Serial.println("DFPlayer not detected");
while(true);
}

player.volume(25); // Volume (0 to 30)
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;

Serial.print("Distance: ");
Serial.println(distance);

if (distance > 0 && distance <= 10) {
player.play(1); // "10 cm"
}
else if (distance <= 20) {
player.play(2); // "20 cm"
}
else if (distance <= 30) {
player.play(3); // "30 cm"
}

delay(2000);
}

6. Detailed Step By Step Code Working

  1. Library Inclusion
    • SoftwareSerial is used for communication with DFPlayer.
    • DFRobotDFPlayerMini controls audio playback.
  2. Pin Definition
    • TRIG and ECHO pins are defined for distance measurement.
  3. Setup Function
    • Initializes serial communication.
    • Initializes DFPlayer module.
    • Sets volume level.
  4. Distance Measurement
    • Sends ultrasonic pulse.
    • Measures return time using pulseIn().
    • Converts time into distance in cm.
  5. Decision Logic
    • Uses if-else conditions to check distance ranges.
    • Plays corresponding audio file from SD card.
  6. Delay
    • Adds delay to avoid continuous repetition.

7. Tips

  • Use properly recorded audio files (e.g., “10 cm”, “20 cm”).
  • Record it using mobile phone recorder or any such device 
  • Format: MP3 (recommended) or WAV
  • Sample rate: 44.1 kHz (standard)
  • Bitrate: 128 kbps (good quality)
  • Mono preferred (saves space)
  • Name files as 0001.mp3, 0002.mp3, etc.
  • Keep sensor stable for accurate readings.
  • Avoid noisy environments for better ultrasonic performance.
  • Use battery power for portability.
  • Only nearest round figure will be the output

8. Uses

  • Assistive device for visually impaired
  • Obstacle detection robots
  • Smart walking stick
  • Parking assistance system
  • Industrial distance monitoring
  • Automation safety systems

9. Conclusion

The Arduino Talking Distance Sensor is a powerful and practical project combining sensing and audio feedback. It demonstrates how embedded systems can improve accessibility and automation. With simple modifications, it can be expanded into advanced smart systems.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.