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

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:

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);
digitalWrite(pingPin, HIGH);
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("in, ");


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:
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 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 (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


For more detail: Talking Pumpkin


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top