All posts by Kevin Lenhart

Playing an Audio File with Processing

In this tutorial, we will demonstrate how to use Processing to play an audio file of your choise. We intend to use this function as part of a larger project involving the use of sensors in public spaces to trigger pre-recorded sounds when people pass through the space. In this larger project, the function we describe here will be linked with the function of using a piezo sensor to detect vibration.

INGREDIENTS:
Arduino UNO
Processing software
IMG_3248 Processing code

While it is possible to use arduino to play individual audio files in mono, Processing allows for the playback of audio files in stereo, and can overlap multiple audio files at once.

To clarify this terminology, “mono” means the audio file has a single audio channel, as opposed to the left and right audio channels of stereo audio files. Virtually all contemporary music is formatted in stereo, and it is the format we are accustomed to listening to.

Processing is capable of performing these magical feats of musical playback by virtue of the Minim library. Minim comes included with Processing software. It can also be used outside of Processing, but we’re not going to get into that here.

The only assembly required to run this function is to connect your arduino to a computer via usb. Do this now.

Next, open a new Processing file. Save it under your file name of choice (I called mine “Minim_1”). When you save, a folder will be generated to contain your Processing file. This folder will have the same title as your processing file.

Next, select an audio file, something short. Place your audio file in the Processing folder that you just generated. We chose a Napalm Death song titled “You Suffer”, which lasts about 3 seconds. It’s amazing, and downloadable here if you want to use my code.

If you do use this file, re-title it “you_suffer.mp3”, place it in your Processing folder, and use the code I provide below.

If you wish to play a different audio file, this link provides you with code to do so, as well as lots of helpful info about Minim.

To play the audio file you have now placed in your Processing folder, simply plug it in to the code provided by the link by deleting the song title they have in quotes (“mysong.wav”), and typing in the file name of your audio file between the quotes (e.g. “you_suffer.mp3”).

Here is the code we used:

That’s it on your end, the code handles all the rest of the work, importing the Minim library and using an audio player function to play your audio file.

When you run the code, a small window will appear to the side, and your audio file will play. It looks like this:Processing2

Happy jamming!

Using Piezo Sensors to Detect Vibration

Using Piezo Sensors to
Detect Vibration

In this tutorial, you will learn how to use a Piezo sensor to detect vibration. We intend to use this function as
part of a larger project involving the use of sensors in public spaces to turn on background music and trigger
pre-recorded sounds when people pass through the space. To keep things simple, however, this tutorial will
stick to the simpler concept of the film sensor perceiving vibration.

IMG_3115

 

INGREDIENTS:
• Arduino UNO
• Solderable breadboard
• (1) LM358 OpAmp
Integrated Circuit
• (1) Piezo sensors
• (1) Potentiometers
• (1) 1 mega-ohm resistor
• (1) Zener 5.1V 1 Watt diode
• (1) 0.1 uF capacitor
• Jumper wires

The first step is to put your circuit together.
The image below shows the completed circuit using a solderable breadboard.
In the bottom left of the image the green and yellow wires are coming from the piezo element. The yellow is
the ground, the green is the positive output. A resistor is used for the component. To prevent voltage spikes,
a diode is added in parallel to protect other parts of the circuit.
The signal is taken into the op amp. The op amp amplifies the signal from the piezo element, and sends
that signal from one side of the op amp to the other. The right side of the op amp receives the signal, and is
used for amplification of the signal. The left side gets the amplified signal from the right side, and is used for
a comparator, determining which values to designate as high or low. The potentiometer adjusts the sensitivity
of the comparator, and thus the sensitivity of the trigger.
The output of the comparator provides the input for the arduino. Using our code, this input determines the
display in the serial monitor, either “EARTHQUAKE” when motion is detected, (a HIGH reading) or “CHILLIN”
when motion is not detected (a LOW reading).Piezo Diagram

This diagram illustrates the flow of the signal through the circuit:

 

Tutorial 3_Circuit Diagram

The completed code and serial monitor display look like this:

Code and Serial Monitor