Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together!
Please order via PiShop.ca, as we are no longer taking orders through this site.
More details are in our blog!

Audio Triggers: the very basics

August 04, 2017

Our customers build a lot of projects using embedded audio using Adafruit Audio FX boards. They're pretty much the easiest way to add sampled audio to your electronics project. I'm working on a personal project where I need to generate sound in a fairly small enclosure, and this project was the first time I'd ever used an audio trigger or sound board. While they're pretty straightforward, and Adafruit's tutorial is really helpful, there are some little gotchas that you've got to learn and work around.

Audio triggers, if you haven't heard of them before, are a really simple idea: press a button, it plays a sound. Fancy ones have multiple buttons, and fancier still ones can have loops, stop/start controls and a whole bunch more. The Audio FX boards are definitely up there in the “fancier still” category. The board attaches to a USB port and becomes a drive on which you can save samples. Eject the drive, and you've got a solid multi-sample sound trigger.

I've only got room in my project for the tiny Audio FX Mini Sound Board, but I can also (just!) fit in a tiny amplifier and flat speaker. This results in a compact and loud mono unit, all in a couple of small circuit boards.

A couple of tips I picked up from this build:

  • While you absolutely can't play samples while the Audio FX board is attached to a computer, it's also hit-or-miss whether you can play samples when connected to a simple USB power source. A couple of chargers and USB sources I tried stopped the trigger from working. Best to power it via the Vin port.
  • There's a nice big pad carrying Vin on the back of the board which makes a nice source to drive an external amp.
  • If you don't seem to be getting results, check that the ACT LED come on when you trigger the board. ACT tells you if the board is playing a sample or not.
  • If you need to see if there's output but don't have an amp connected, a multimeter with frequency reading will show a few hundred Hz between the L or R channels and ground.
  • The ground pins either side of the L & R audio channels are a bit special. These are audio grounds, and are electrically much more quiet than the power ground ports elsewhere on the board. If your speaker buzzes or ticks, check that you're using an audio ground on your amplifier's negative input, or check that you haven't accidentally tied a power ground to the audio ground.

While triggers are most often used with buttons, you can trigger them from a microcontroller. Here's a simple Arduino setup to play a single sample once every fifteen seconds. I may have chosen the opening bars of “The Hampsterdance Song”, but you might wish something less annoying.

In order to trigger the sample, we need to setup a pin as an output, and hold the value high until we want the sample triggered. We then have to hold the pin low for a time (Adafruit suggest 50 ms, but I didn't find anything less than 120 ms to be reliable) and the sample will play.


 *  “Think of it, Ellen - a world that plays
 *   ‘The Hampsterdance Song’ every 15 seconds”
 *  “That would be wonderful ...”

void setup() {
  pinMode(7, OUTPUT);             // pin 7 to Audio FX port
  pinMode(LED_BUILTIN, OUTPUT);   // also signal built-in LED on Arduino
  digitalWrite(7, HIGH);          // keep the trigger pin high
  delay(5000);                    // initial 5 s pause

void loop() {
  digitalWrite(7, LOW);             // set trigger
  digitalWrite(LED_BUILTIN, HIGH);  // set visual confirmation
  delay(120);                       // pause 0.12 seconds
  digitalWrite(LED_BUILTIN, LOW);   // clear trigger
  digitalWrite(7, HIGH);            // turn off visual confirmation
  delay(15000);                     // wait 15 s before next trigger

Also in News

Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together!

October 03, 2022

Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together! Please see our blog for more info.

Continue Reading

Adding RGB LEDs to an illuminated arcade button

March 14, 2022

Continue Reading

We Made a Media Controller!

October 12, 2021

Continue Reading