Talking Distance With Arduino Uno, the Ultrasonic Sensor HC-SR04 and the WTV020SD Sound Module

Introduction: Talking Distance With Arduino Uno, the Ultrasonic Sensor HC-SR04 and the WTV020SD Sound Module

About: I studied Electrical Engineering and a lot of other things. I'm always driven by my passions. Please visit also my Youtube channel.

Welcome to my Instructable #31, aka one of the most popular Arduino projects.

If you like this project, please become one of my followers on Instructables and subscribe to my Youtube channel... www.youtube.com/rcloversan

Anyway, for this project you need:

1x Arduino Uno
http://www.banggood.com/UNO-R3-ATmega328P-Developm...

1x WTV020-SD-16P Sound Moudule

http://www.banggood.com/WTV020-SD-16P-U-Disk-Audi...

1x Ultrasonic module

http://www.banggood.com/UNO-R3-ATmega328P-Developm...

1x Breadboard

http://www.banggood.com/Mini-Solderless-Prototype...

Jumper Wires

http://www.banggood.com/UNO-R3-ATmega328P-Developm...

1x Speaker (8 Ohm)

1x LED

1x Resistor 470K

1x SD card (Sandisk)* 1, or 2GB max!!!

Finding the right SD (the WTV020SD module works just with the original Sandisk), drove me literally crazy.
There are so many fake models on Ebay, that I had to buy 3 of them, to get the right one.

Step 1: Preparing the Audio Files

This is the most tedious part of the project....

Anyway, download WavePad Audio Editing Software
http://www.nch.com.au/wavepad/index.html

and launch the software.

Using your voice, record the .wav files pressing the red button (2nd from the left bottom). Every file should contain the distance (in centimeter) you want to hear, according to the position of the object in front of the ultrasonic sensor. You should have "a beep" sound (less than 5cm), 10cm, 15cm, 20cm, 25cm, 30cm and so on (the limit of the ultrasonic sensor used for this project is 200!).

Open the files you want to put on the SD card, save the .wav with these attributes:

Format: PCM Uncompressed

Attributes: 32000Hz, 16 bits, Mono

Naming the files: Voice1, Voice2, Voice3... and so on.

I saved the files putting them in a directory on the desktop (voice), so it was easy to find them.

Now, download the ad4 converter software...

https://docs.google.com/file/d/0B4p82-pNB6o7QXFwZ...

to convert the .wav file into ad4.

Remember to save this file in the same directory of the sounds you intend to use for your project (directory voice). Launch the ad4 software clicking on the .EXE file, the MS-DOS window will pop-up immediately.

At the prompt (C:\>) write cd desktop/voice

(please note that my complete path was C:\>cd users/user/documents/desktop/voice).

Now write: ad4converter -E4 voice1.wav

The software will create automatically the file voice1.ad4.

Repeat this operation for all the other files, until you have all the .wav converted in the ad4 format.

Now you can copy all these files on the sd card, using the slot available in the most of the PC and the SD card will be ready to be put inside the WTV020SD-16P module.

Step 2: Test the WTV020SD-16P Module

An important thing that can affects the functionality of the WTV020SD is the volume of your sounds/voices.

If you don't listen the sounds, try to lower it (using the proper command: wtv020sd16p.setVolume(6);)

If it doesn't work, the problem is a wrong/fake SD card.

If you have some problems you can read this amazing tutorial written by Build Circuit...

http://www.buildcircuit.com/how-to-convert-mp3-and...

Step 3: Wiring...

Please wire the circuit, following the diagram in the picture.

Step 4: Coding...

// include the Library Code
#include

#define trigPin 12

#define echoPin 13

int resetPin = 2; // The pin number of the reset pin.

int clockPin = 3; // The pin number of the clock pin.

int dataPin = 4; // The pin number of the data pin.

int busyPin = 5; // The pin number of the busy pin.

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);

void setup(){

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

Serial.begin (115200);

wtv020sd16p.reset();

wtv020sd16p.setVolume(6);

}

void loop()

{

int duration, distance; //send a pulse and calculate how long it took to travel

digitalWrite(trigPin, HIGH);

delayMicroseconds(1000);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

//then check the distance and play file 1,2,3,4,5,6,7,8 if it’s in the range

if (distance >= 200 || distance <= 0){

Serial.println(“Out of range”);

}

else if (distance >=0 && distance <=5){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice1();

delay (400);

}

else if (distance >=5 && distance <=10){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice2();

delay (400);

}

else if (distance >=11 && distance <=15){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice3();

delay (400);

}

else if (distance >=16 && distance <=20){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice4();

delay (400);

}

else if (distance >=21 && distance <=25){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice5();

delay (400);

}

else if (distance >=26 && distance <=30){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice6();

delay (400);

}

else if (distance >=31 && distance <=35){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice7();

delay (400);

}

else if (distance >=36 && distance <=40){

Serial.print(distance);

Serial.println(” cm”);

delay (100);

voice8();

delay (400);

}

// else if (distance >=31 && distance <=60) //{

// Serial.print(distance);

// Serial.println(” cm”);

// beepFast();

//}

else {

Serial.print(distance);

Serial.println(” cm”);

// when characters arrive over the serial port…

if (Serial.available()) {

// wait a bit for the entire message to arrive

delay(100);

// read all the available characters

while (Serial.available() > 0) {

}

}

}

}

void voice1(){

wtv020sd16p.playVoice(1);

delay (200);

}

void voice2() {

wtv020sd16p.playVoice(2);

delay (200);

}

void voice3() {

wtv020sd16p.playVoice(3);

delay (200);

}

void voice4() {

wtv020sd16p.playVoice(4);

delay (200);

}

void voice5() {

wtv020sd16p.playVoice(5);

delay (200);

}

void voice6() {

wtv020sd16p.playVoice(6);

delay (200);

}

void voice7() {

wtv020sd16p.playVoice(7);

delay (200);

}

void voice8() {

wtv020sd16p.playVoice(8);

delay (200);

}

Share

    Recommendations

    • Water Contest

      Water Contest
    • Metalworking Contest

      Metalworking Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    Discussions