Talking Pumpkin




So my boss came to me one last week and said he wanted to scare the trick-or-treaters who came to his home, and the kids who would come to work during a special Halloween Walk the community does. Thus was born the talking pumpkin.
Talking Pumpkin




In short, I used an Arduino, an SD card read/writer, and an ultrasonic sensor to trigger a sound byte when the kids walk past our pumpkin… something they would not expect.

If you just want to download the code, and wire it up, skip ahead to step 4. Otherwise, just continue reading in order.

Step 1: Parts List

Major Components in Project

[1] Arduino Uno
[1] SD card module (about $1.50 on Ebay)
[1] Ultrasonic HR-SR04 (about $1.50 on Ebay)
[1] Single pole single throw switch ($.50 Radio Shack)
[1] 3.5 mm mono female solder-type audio connector (about $1 from local store)
[1] Class 4, 4GB, SD card (from my camera)
[1] Mini Breadboard (from previous projects)
[1] Enclosure (I had mine laying around)
[1] 9volt battery connector ($.50)
Various resistors, wires, and capacitors (less than $5 from previous projects)

For less than $30 total you can get all the parts. Chances are that you have most of these things lying around, especially if you have previously worked with the Arduino or Raspberry Pi platforms. I spent a total of $1 for the 3.5 mm jack. The rest I had on hand.

Step 2: Distance Sensor (first real step)

Distance Sensor (first real step)

The first step is to get the distance sensor working. There are lots of tutorials to follow to get it running. There is one that is easy to follow on the Arduino site. The code is as follows: (directly out of the built in examples)

/* Ping))) Sensor

This sketch reads a PING))) ultrasonic rangefinder and returns the
distance to the closest object in range. To do this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse
to return.  The length of the returning pulse is proportional to
the distance of the object from the sensor.

The circuit:
* +V connection of the PING))) attached to +5V
* GND connection of the PING))) attached to ground
* SIG connection of the PING))) attached to digital pin 7

http://www.arduino.cc/en/Tutorial/Ping

created 3 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

*/

// this constant won’t change.  It’s the pin number
// of the sensor’s output:
const int pingPin = 7;

void setup() {
// initialize serial communication:
Serial.begin(9600);
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print(“in, “);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second).  This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

Once you get this working you are well on your way. Check the serial monitor to make sure everything is working well.

Step 3: SD Card Music Player

This part was taken from a great tutorial found at http://apcmag.com/arduino-project-5-digital-audio-player.htm. Note that you do need to replace the current SD card class, as far as I can tell, it doesn’t harm other projects, but I have not done extensive tests. If you are worried about changing the class, you can always add this to your libraries as SD2 instead.

Step 4: Putting it together, part 1

If you skipped right to this step follow the following step. Otherwise, skip to the next step.

We’ll need the ‘tmrpcm’ and a modified ‘SD’ card library. You’ll find these in the zip file you can download from apcmag.com/arduino.htm (look under the Project 5 heading). Copy the ‘SD’ and ‘tmrpcm’ folders to the ‘libraries’ folder in your Arduino IDE folder (yes, overwrite the original ‘SD’ library) and restart the IDE if you’ve had it running already.

The ‘apc_05_audioplayer.ino’ file is our sketch, which ties everything together. It boots up the Arduino, turns on the SD module, checks the card and waits for you to press the button. Press it for less than a second and it’ll load and play the first file. If you press the button again for less than a second, it’ll pause playback; pressing it again resumes playback. Press it for more than a second, and it’ll automatically skip forward to the next audio track and begin playback. There are no volume controls — you adjust this at your amplified speakers.

Unfortunately, the ‘tmrpcm’ library creates a pop whenever a track stops or starts. A low-pass filter will help a little, but it’s caused by the PWM signal turning on and off. (Qutoed from http://apcmag.com/arduino-project-5-digital-audio-player.htm)

 

For more detail: Talking Pumpkin




This Post / Project can also be found using search terms:

  • arduino sound and RGB turtorial slides
  • arduino uno audio projects
Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Basics of Turning your Remote Controll Vehicle into an Autonomous System (Drone) Using an Arduino

I began this project with the objective of cheaply turning my RC helicopter into something of a UAV or at...

Close
Scroll to top