# Capacitive Touch Drum Machine

## Overview

Have you (or your dog) ever wanted a&nbsp;drum machine? If so, this project is for you. We will use an Arduino Leonardo, a MPR121 capacitive touch shield, and a strip of sixteen&nbsp;RGB NeoPixels to make a simple drum machine that you can use to control USB MIDI or serial MIDI devices.

This tutorial is based on the same hardware setup&nbsp;used&nbsp;in the [Make a Sequencer&nbsp;from a Tree](https://youtu.be/vX16VXK64do)&nbsp;video. The only difference is that the MPR121 capactive touch breakout was used in the video instead of the MPR121 shield we will be using in this tutorial, but they both will work equally well for this project. If you would like to learn more about how the metal buttons were created in that video, you can check out our guide on [using metal inlay for capactive touch buttons](../../../metal-inlay-capacitive-touch-buttons).

Let's take a look at the version of that sequencer we will be making in this tutorial.

https://youtu.be/DxWZUTnEvhs

Now that you have a handle on what we are making, let's take a look at how to wire everything up.

# Capacitive Touch Drum Machine

## Wiring

There are only a few things to wire up since we are using the MPR121 shield. First, you will need to solder&nbsp;the&nbsp;headers to the MPR121 shield. If you need help learning how to solder, check out [our soldering guide](../../../../adafruit-guide-excellent-soldering/). You can use male headers or shield stacking headers if you have some handy.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/803/medium800/microcontrollers_pins.jpg?1429915516)

Next, you will need to add two male header pins to **ADDR** and **IRQ** pins on the top of the MPR121 shield. Make sure the long portion the pins are facing up as shown in the picture below.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/804/medium800/microcontrollers_irq.jpg?1429915612)

Use a female/male jumper cable to connect the MPR121 **IRQ** pin to **digital pin 4**.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/805/medium800/microcontrollers_jumper.jpg?1429915666)

Next, grab your strip of 16 NeoPixels and solder three lengths of wire to the **5V** , **DIN** , and **GND** pins on the NeoPixels. If you are using two NeoPixel sticks, you will also need to solder&nbsp;them together. If you are using a strip of NeoPixels, you can&nbsp;cut a strip of&nbsp;16 NeoPixels for use with this project.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/801/medium800/microcontrollers_neo.jpg?1429915030)

Seat the MPR121 shield on top of the Leonardo, and attach the NeoPixel **5V** and **GND** wires to the **5V** and **GND** pins on the MPR121 shield. Attach the NeoPixel **DIN** wire to **digital pin 6** on the MPR121 shield.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/802/medium800/microcontrollers_P1040240.jpg?1429915188)

Use alligator clips to connect&nbsp;pads&nbsp;0-5 on the MPR121 shield to fruit, metal, or anything else that is electrically conductive. In the example below, I'm using copper tape.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/800/medium800/microcontrollers_all.jpg?1429914839)

Next, we will look at the uploading the code to the Leonardo.

# Capacitive Touch Drum Machine

## Code

For this project you will need version **1.6.3 of the Arduino IDE** with the Adafruit Arduino Board Manager proxy added to your Arduino preferences. If you haven't configured the proxy yet, [check out our guide](../../../../adding-custom-boards-to-the-arduino-v1-6-board-manager)&nbsp;on setting up your Arduino IDE to use the proxy.

[Arduino IDE v1.6.3 Download](http://www.arduino.cc/en/Main/Software)
## Virtual MIDI Synths

You will need a virtual MIDI synth installed on your computer for this project. For Windows, the best one seems to be [VirtualMIDISynth](http://coolsoft.altervista.org/en/virtualmidisynth#download), and for OS X [SimpleSynth](http://notahat.com/simplesynth/)&nbsp;is your best bet.

## Installing the Arduino Library Dependencies

You will need to install a few things using the new Arduino Library and Board Managers. First, open up the Arduino Library Manager under the **Sketch-\>Include Library** menu. Select the **Manage Libraries...** item from the menu.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/762/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.15.30_PM.png?1429902994)

You will need to use the search box to find and install these three libraries:

- **FifteenStep**
- **Adafruit NeoPixel**
- **Adafruit MPR121**

![](https://cdn-learn.adafruit.com/assets/assets/000/024/763/medium800thumb/sensors_microcontrollers_libraries.jpg?1448317842)

## Adding&nbsp;USB MIDI Support

Next, you will need to install USB MIDI support for the Leonardo using the Boards Manager. Click on the **Boards Manager** item under the **Tools-\>Board** menu.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/765/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.27.03_PM.png?1429903724)

Search for _MIDI_ using the search box, and install the **Leonardo & Micro MIDI-USB** package.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/769/medium800thumb/sensors_microcontrollers_boards.jpg?1448317853)

Next, make sure you have selected the **Arduino Leonardo (MIDI)** from the **Tools-\>Board** menu, and plug in the Leonardo to your computer's USB port using a micro USB&nbsp;cable.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/772/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.38.06_PM.png?1429904360)

Now we are ready to open the example sketch. Open the **neo\_mpr121** example from the **File-\>Examples-\>FifteenStep** menu. The example code is heavily commented, so we won't go into too much detail here. If you have any problems&nbsp;with it, please file an [issue on GitHub](https://github.com/adafruit/FifteenStep/issues).

![](https://cdn-learn.adafruit.com/assets/assets/000/024/773/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.38.53_PM.png?1429904514)

Next, upload&nbsp;the example sketch to your Leonardo using the _right arrow icon_ at the top of the sketch window.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/774/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.45.20_PM.png?1429904734)

If everything goes as expected, you will see a _Done Uploading_ message at the bottom of the window.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/777/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.46.54_PM.png?1429905104)

## Running the Example

Now that you have uploaded the sketch, you should see a sequence running on the NeoPixels. Open up your software synth that you downloaded earlier, and select the _USB MIDI_ device as your input source. Then select a drum set from the list of available instruments. I'm using the TR-808 patch in SimpleSynth on OS X. Press a few of the pads, and your drum machine should save&nbsp;them to the sequence and play them back through the MIDI software synth.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/779/medium800/microcontrollers_Screen_Shot_2015-04-24_at_3.58.02_PM.png?1429905653)

Next, we will look at the simple user interface in the example sketch.

# Capacitive Touch Drum Machine

## User Interface

There are some handy commands buried beneith&nbsp;the surface of the example sketch. You can change things like tempo, shuffle, MIDI channel, sequence length, MIDI pitch, and MIDI velocity on the fly using a few simple button combinations. There is a condensed single page cheatsheet PDF download available for the user interface that will&nbsp;be a good reference once you have read through the full command&nbsp;documentation.

[User Interface Cheatsheet PDF](https://github.com/adafruit/FifteenStep/raw/master/examples/neo_mpr121/cheatsheet.pdf)
## Record Mode Toggle

The sequencer starts in record mode, but if you would like to toggle it off so you can test out the instruments without recording them to the sequence, you can press pads **4** and **5** &nbsp;simultaneously. You will know if you are currently recording if every fourth NeoPixel flashes red, if you are not recording, all pixels will flash&nbsp;blue.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/812/medium800/sensors_record_toggle.gif?1448020574)

## Play & Pause Toggle

You can toggle between play and pause by pressing pads **5** &nbsp;and&nbsp; **6** &nbsp;simultaneously.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/813/medium800/sensors_pause.gif?1448020568)

## All Notes Off

You can clear all currently playing notes from the sequence by pressing pads **1** &nbsp;and&nbsp; **6** &nbsp;simultaneously.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/814/medium800/sensors_notes_off.gif?1448020560)

## Command Mode Toggle

Tempo, shuffle, step count, MIDI channel, pitch, and velocity are all available underneath a sub menu I'm calling&nbsp;_Command Mode_. You can enter command mode by pressing pads **1** & **2** &nbsp;simultaneously. You will know you have entered&nbsp;command mode when all of the NeoPixels flash red.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/815/medium800/sensors_command_1.gif?1448020553)

## Tempo Change

You can change the tempo by entering command mode and then pressing pad **1**.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/816/medium800/sensors_command_tempo.gif?1448020545)

You should see the NeoPixels flash a different color at this point. You can now use pad **5** to decrease the tempo, or&nbsp;pad **6** to increase the tempo.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/817/medium800/sensors_change_value.gif?1448020538)

You can exit tempo change mode by using the command mode toggle pads.

## Shuffle Change

You can add or remove shuffle by entering command mode and then pressing pad **2**.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/818/medium800/sensors_command_shuffle.gif?1448020530)

You should see the NeoPixels flash a different color at this point. You can now use pad **5** to decrease the shuffle, or&nbsp;pad **6** to increase the shuffle.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/819/medium800/sensors_change_value.gif?1448020522)

You can exit shuffle&nbsp;mode by using the command mode toggle pads.

## Changing the Length of the Sequence

You can change the number of steps in the sequence by entering command mode and then pressing pad **3**.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/820/medium800/sensors_command_step.gif?1448020515)

You should see the NeoPixels flash a different color at this point. You can now use pad **5** to decrease the length, or&nbsp;pad **6** to increase the length.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/821/medium800/sensors_change_value.gif?1448020507)

You can exit sequence length change&nbsp;mode by using the command mode toggle pads.

## MIDI Channel Change

You can change the current MIDI channel for new notes&nbsp;by entering command mode and then pressing pad **4**. The notes previously&nbsp;recorded will remain on the MIDI channel that was selected when they were recorded.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/822/medium800/sensors_command_midi.gif?1448020499)

You should see the NeoPixels flash a different color at this point. You can now use pad **5** to decrease the channel number, or&nbsp;pad **6** to increase the channel number.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/823/medium800/sensors_change_value.gif?1448020492)

You can exit MIDI channel&nbsp;mode by using the command mode toggle pads.

## Pad Pitch Change

You can change the MIDI pitch of a pad is using&nbsp;by entering command mode and then pressing pad **5**.&nbsp;This change will only impact newly recorded notes. All previously recorded notes will retain their recorded pitch.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/824/medium800/sensors_command_pitch.gif?1448020485)

You can then select which&nbsp;pad you wish to change.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/828/medium800/sensors_pad_select.gif?1448020459)

Once you have selected the pad you wish to change, you can use pad **5** to decrease the MIDI pitch value for the previously selected pad, or pad **6** to increase the MIDI pitch.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/826/medium800/sensors_change_value.gif?1448020472)

You can exit pitch change mode by using the command mode toggle pads.

## Pad Velocity&nbsp;Change

You can change the MIDI velocity of&nbsp;a pad is using&nbsp;by entering command mode and then pressing pad **6.** &nbsp;This change will only impact newly recorded notes. All previously recorded notes will retain their recorded velocity.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/827/medium800/sensors_command_velocity.gif?1448020466)

You can then select which&nbsp;pad you wish to change.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/829/medium800/sensors_pad_select.gif?1448020452)

Once you have selected the pad you wish to change, you can use pad **5** to decrease the MIDI velocity&nbsp;value for the previously selected pad, or pad **6** to increase the MIDI velocity.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/830/medium800/sensors_change_value.gif?1448020444)

You can exit velocity&nbsp;change mode by using the command mode toggle pads.

# Capacitive Touch Drum Machine

## Next Steps & Thanks

The [FifteenStep MIDI sequencer library](https://github.com/adafruit/FifteenStep)&nbsp;that the example uses does not have to be used with USB MIDI. You could use it to output to a standard serial MIDI device, or use the MIDI note data for other purposes. There's an&nbsp;example included with the&nbsp;FifteenStep library that demonstrates using the library with&nbsp;serial MIDI out.

Another possibility is to use the MIDI data to control devices without MIDI capabilities. Below is an example of using an Arduino Uno, NeoPixels, and two&nbsp;MCP4725 DAC breakouts to record MIDI data from a&nbsp;MIDI controller and play it back as contol voltage to a modular synthesizer.

https://youtu.be/Yl2PlUmhZpo

You can find the code used in this example [on GitHub](https://gist.github.com/toddtreece/5449fdb479ddadd0ed5b).

## Thanks

Thanks to Ladyada&nbsp;&&nbsp;Tony DiCola for the huge memory saving suggestions that greatly increased polyphony in the FifteenStep library, and thanks to Brennen Bearnes for the UI Cheatsheet PDF idea. Also, another big thanks to Marty McGuire and&nbsp;[Baltimore Node](http://baltimorenode.org/)&nbsp;for the help with laser engraving&nbsp;the Adafruit logo on the sequencer featured&nbsp;in the [Make a Sequencer from a Tree](https://youtu.be/vX16VXK64do)&nbsp;video.

## Special Thanks

A special thanks goes out to my friendly Alaskan Malamute, Biko. He graciously donated&nbsp;his time and beat making skills for the video at the beginning of the guide.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/739/medium800thumb/sensors_microcontrollers_biko2.jpg?1448317800)


## Featured Products

### Adafruit 12 x Capacitive Touch Shield for Arduino - MPR121

[Adafruit 12 x Capacitive Touch Shield for Arduino - MPR121](https://www.adafruit.com/product/2024)
This touch-able add on shield for Arduinos will inspire your next interactive project with 12 capacitive touch sensors. Capacitive touch sensing works by detecting when a person (or animal) has touched one of the sensor electrodes. Capacitive touch sensing used for stuff like touch-reactive...

In Stock
[Buy Now](https://www.adafruit.com/product/2024)
[Related Guides to the Product](https://learn.adafruit.com/products/2024/guides)
### Arduino Leonardo ATmega32u4 with headers

[Arduino Leonardo ATmega32u4 with headers](https://www.adafruit.com/product/849)
 **Note:** This product is&nbsp; **discontinued,** but you can purchase the [Seeeduino Lite](https://www.adafruit.com/product/3228), which is an equivalent alternative that can be used instead.

The Arduino Leonardo is a microcontroller board based on...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/849)
[Related Guides to the Product](https://learn.adafruit.com/products/849/guides)
### Small Alligator Clip Test Lead (set of 12)

[Small Alligator Clip Test Lead (set of 12)](https://www.adafruit.com/product/1008)
Connect this to that without soldering using these handy mini alligator clip test leads. 15" cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a multimeter so we...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1008)
[Related Guides to the Product](https://learn.adafruit.com/products/1008/guides)
### Adafruit 12-Key Capacitive Touch Sensor Breakout - MPR121

[Adafruit 12-Key Capacitive Touch Sensor Breakout - MPR121](https://www.adafruit.com/product/1982)
Add lots of touch sensors to your next microcontroller project with this easy-to-use 12-channel capacitive touch sensor breakout board, starring the MPR121. This chip can handle up to 12 individual touchpads.  
  
The MPR121 has support for only I2C, which can be implemented with nearly...

In Stock
[Buy Now](https://www.adafruit.com/product/1982)
[Related Guides to the Product](https://learn.adafruit.com/products/1982/guides)
### NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers

[NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/1426)
Make your own little LED strip arrangement with this stick of NeoPixel LEDs. We crammed 8 of the tiny 5050 (5mm x 5mm) smart RGB LEDs onto a PCB with mounting holes and a chainable design. Use only one microcontroller pin to control as many as you can chain together! Each LED is addressable as...

In Stock
[Buy Now](https://www.adafruit.com/product/1426)
[Related Guides to the Product](https://learn.adafruit.com/products/1426/guides)
### Shield stacking headers for Arduino (R3 Compatible)

[Shield stacking headers for Arduino (R3 Compatible)](https://www.adafruit.com/product/85)
_“How could something so simple be so useful?”&nbsp;_

We heard once that&nbsp;in the 4th millennium B.C.&nbsp;some guy asked the person who invented the wheel that question.&nbsp; The person who invented the wheel’s answer, we were told, was...

In Stock
[Buy Now](https://www.adafruit.com/product/85)
[Related Guides to the Product](https://learn.adafruit.com/products/85/guides)
### Premium Female/Male 'Extension' Jumper Wires - 40 x 12" (300mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 12" (300mm)](https://www.adafruit.com/product/824)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 12" (300mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

In Stock
[Buy Now](https://www.adafruit.com/product/824)
[Related Guides to the Product](https://learn.adafruit.com/products/824/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

In Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)

## Related Guides

- [No-Code Indoor Air Quality Monitor with Separate Display](https://learn.adafruit.com/no-code-indoor-air-quality-monitor-with-separate-display.md)
- [Naughty or Nice Machine](https://learn.adafruit.com/naughty-or-nice-machine.md)
- [3D Printed Unicorn Horn](https://learn.adafruit.com/3d-printed-unicorn-horn.md)
- [Knobby Sequencer](https://learn.adafruit.com/knobby-sequencer.md)
- [Sipping Power With NeoPixels](https://learn.adafruit.com/sipping-power-with-neopixels.md)
- [CircuitPython Hardware: MPR121 Capacitive Touch Breakout](https://learn.adafruit.com/circuitpython-hardware-mpr121-capacitive-touch-breakout.md)
- [Adafruit MPR121 12-Key Capacitive Touch Sensor Breakout Tutorial](https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial.md)
- [LED Acrylic Sign](https://learn.adafruit.com/led-acrylic-sign.md)
- [Metal Inlay Capacitive Touch Buttons](https://learn.adafruit.com/metal-inlay-capacitive-touch-buttons.md)
- [Adafruit IO Time Tracking Cube](https://learn.adafruit.com/time-tracking-cube.md)
- [Circuit Playground: K is for Kits](https://learn.adafruit.com/circuit-playground-k-is-for-kits.md)
- [Using NeoPixels with Netduino Plus 2](https://learn.adafruit.com/using-neopixels-with-netduino.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Adabot Toy Robot Friend](https://learn.adafruit.com/adabot-rp2040.md)
- [3D Scans for Low Poly Statues](https://learn.adafruit.com/low-poly-3d-scans-for-3d-printing.md)
