Introduction: DRUMMER'S TEMPO KEEPER

About: I'm a pretty experienced programmer, although I've never done it for a living. I'm new to electronics. I'm also a drummer in a local cover band.

A drummer's single most important job is to keep time. That means making sure the beat stays constant for each song.

The Drummer's Tempo Keeper is a device that helps drummers keep even better time. It consists of a small piezo disc that attaches to the snare drum head. Each time the drummer hits the snare drum, the device displays the beats per minute based on the time between strokes. If the band starts to speed up or slow down unintentionally, the drummer becomes instantly aware and can make a small correction to maintain a consistent tempo.

At a recent performance with a band that I play drums for, another drummer in the audience thought my band was playing to a click track -- a metronome that clicks each beat into the earphones that band members wear -- because the beat was so steady throughout every song. What a compliment and tribute to the Drummer's Tempo Keeper!

Step 1: PARTS

Here's a complete list of the parts you need to create the Drum Temp Keeper, the approximate cost and notes about exactly what I used to create mine. You can get these parts on websites such as Amazon, eBay, Adafruit and SparkFun. The least expensive parts are usually sold on eBay and they come from China, so they can take a few weeks to arrive. You have to use different drivers if you get a cheap microcontroller from China (as I did) than if you buy a brand-name Arduino from the USA. I've noted what you need to do to download and install the other drivers.

1. Microcontroller. I used an Arduino Nano clone from China that came with the headers already soldered on. ($4.50)

2. Four-Digit Display. Make sure you get a four-digit display that uses four pins. Don't get a 7-Segment four-digit display because it requires 12 pins. ($3.50)

3. Project Enclosure. I used a RadioShack 3" x 2" x 1" project enclosure. Make sure it's plastic because you have to cut a hole for the four-digit display. ($6.00)

4. Piezo Because this part sits on the snare drum and is subject to a lot of movement and vibration, you should use a piezo with a casing around it. There are cheap versions with plastic casing, but I opted for one with a stronger casing that's used for guitar pickups. ($10.00)

5. Extension wire for piezo. I used regular 22 AWG wire. ($1.00)

6. 10K Ohm Resistor. The 10K is brown - black - orange - gold. ($0.25)

7. Battery Pack. This was the easiest solution for me because I didn't want to hassle with alkaline batteries, it serves as a base under the project box and it lasts forever! For something smaller, you could probably use a couple of coin cell batteries. ($8.00)

8. USB Cable. The cable provides power to the Nano from the battery pack and provides the interface between your computer and the Nano for uploading the sketch. ($0.00 - included with the microcontroller)

9. Perf Board. You will solder the components to the board and then cut out only the portion that you're using. ($2.00)

10. Breadboard. I first assembled a prototype of this project using a plastic breadboard and jumper wires. Once I had it working correctly, I soldered a final version to the perf board. You don't need to do this, but it's recommended. ($2.00)

11. Jumper Wires. You need four male-to-female wires to assemble, test and solder. ($1.00)

12. Velcro Strips. Use the velcro to attach the piezo sensor to the snare drum. You can also use it to connect the project enclosure and the battery pack. ($0.80)

Total approximate cost: $39.05

Step 2: TOOLS

Here are the tools you will need to assemble the project.

1. Soldering Iron. Once the prototype is working, you will move the components from the breadboard to a perf board.

2. Solder. Same as #1.

3. Dremel or similar tool. You will use this to cut the perf board and to create holes in the project enclosure for the display and the USB port.

4. Electrical Tape. You will solder extension wires to the piezo and then put electrical tape around the place you soldered.

5. Screwdriver. You need this to open and then close the project enclosure.

6. Computer. You will write your sketch on the computer and upload it to the microcontroller.

7. Arduino IDE software. (also available as a Web-based tool).

Step 3: HOW IT WORKS

Before you put it together, it's helpful to understand how it works.

1. A piezo* is a component that measures how much vibration there is. We attach the piezo to the snare drum and the wires of the piezo to a microcontroller to read how much vibration is present on the snare drum.

2. The microcontroller sketch reads the piezo to determine when the drum was hit, and it records the time. The next time the drum is hit, it notes that time and calculates the beats per minute based on this hit and the previous hit.

3. We also attach a digital display to the microcontroller. After it calculates beats per minute, it displays the result on the digital display. You can put that part of the device anywhere that's visible to you while you play. I put mine next to the highhat on the floor.

Note: If you're not playing quarter notes on the snare, the reading will reflect whatever you're playing. Wait until you return to playing the song's beat to determine the speed.

* We use a piezo as an INPUT component in this project to measure the amount of vibration. In other projects, when you use it as an OUTPUT component, it creates vibrations and becomes a speaker!

Step 4: BREADBOARD PROTOTYPE

    Because soldering isn't my best talent, I first put a prototype device together using a plastic breadboard and jumper wires to ensure it worked. Once it was working, I moved it to a perf board and soldered it. If you're a seasoned maker, you can skip this part and solder directly to a perf board instead.

    1. Place the microcontroller in the middle of the breadboard so that there is a column of plastic that separates the pins on the left side of the board and the pins on the right side of the board. Make sure the USB port is at the edge of the breadboard and not in the middle, as shown in the picture.

    Step 5: CONNECT PIEZO

    The piezo is an analog sensor because it reports a value between 0 and 1024, so it needs to connect to an analog pin on the arduino. I used the first analog pin, A0.

      1. Connect the positive (red) wire of the piezo to pin A0 on the Arduino.

      2. Connect the negative (black) wire of the piezo to one of the ground (GND) pins on the Arduino.

      Step 6: CONNECT RESISTOR

      1. Connect the resistor to the same pins that the piezo is connected to (A0 and GND).

      (It doesn't matter which side of the resistor connects to which pin; they are the same.)

      Step 7: CONNECT DISPLAY CLK PIN

      The four-digit display unit connects to two digital pins on the Arduino. I used the first two digital pins on the Nano, which are D2 and D3.

      1. Connect the CLK pin on the display to the D3 pin on the Arduino using a female-to-male cable.

      Step 8: CONNECT DISPLAY DIO PIN

      1. Connect the DIO pin on the display to the D2 pin on the Arduino using a female-to-male cable.

      Step 9: CONNECT DISPLAY VCC PIN

      1. Connect the VCC pin on the display to the 5V power pin on the Arduino using female-to-male cable.

      Step 10: CONNECT DISPLAY GND PIN

        1. Connect the GND pin on the display to a GND pin on the Arduino using a female-to-male cable.

        That's all there is for the prototype electronics!

        Step 11: DOWNLOAD CH340 DRIVERS (Optional)

        If you're using a cheaper Arduino from China, it probably uses the CH340 chip to communicate with a computer. You have to download and install the drivers for that chip. You can download the official drivers from this site (the page is in English and Chinese if you look closely). Install the drivers on your PC by running the executable.

        Step 12: DOWNLOAD DIGITAL DISPLAY LIBRARY (TM1637)

        The four-digit display uses a TM1637 chip. You need to download a library that makes it easy to display numbers on the digitial display. Go to https://github.com/avishorp/TM1637. Choose Clone or Download and select Download Zip. Save the file on your computer.

        Step 13: INSTALL DIGITAL DISPLAY LIBRARY

          1. Run the Arduino IDE software on your computer. It will present the outline for a blank sketch.

          2. Select Sketch | Include Library | Add .ZIP Library... and choose the file you downloaded from Github to install the library.

          Step 14: SELECT ARDUINO BOARD AND PORT

            1. Connect the Arduino to your computer with a USB cable. Then switch to the Arduino IDE and the new sketch that's open.

            2. Select the correct board, for example, the Arduino Nano.

            3. Select the port your Arduino is connected to on the computer.

            Step 15: SKETCH: BACKGROUND

            1. To determine whether the drum was hit, we read the piezo sensor pin A0. The piezo measures the amount of vibration on the snare drum and gives us a value between 0 (no vibration) and 1024 (maximum vibration).

            2. Since there might be some slight vibrations from the music and the other instruments, we can't say that any reading above zero indicates a hit to the drum. We need to allow for some noise when we check the reading from the piezo. I call this value the THRESHHOLD, and I selected 100. This means that any reading above 100 indicates a hit to the drum. Anything 100 or lower is just noise. Hint: if the device shows readings when you haven't hit the drum, increase this value.

            3. Since we're calculating beats per minute, we need to track the time of each stroke to the drum. The microcontroller keeps track of the number of milliseconds that have passed since it started. This value is available to us with the function millis(), which is a long integer (type long).

            Step 16: SKETCH: PRE-SETUP

            Type the following at the top of the sketch, above the setup function. (If you prefer, you can download the final sketch at the end of the explanation).

            1. First, include the two libraries we need: TM1637Display that you downloaded and math.h.

            2. Next, define the pins we're using. If you recall from assembling the device, the CLK pin is digital pin 2, the DIO pin is digital pin 3 and the Piezo pin is A0 (analog 0).

            3. For now, define the THRESHHOLD to be 100.

            4. Then, create two variables we need for the sketch called reading (the current piezo sensor reading) and lastbeat (the time of the prior stroke).

            5. Finally, initialize the TM1637 library by passing it the pin numbers we're using the CLK and DIO.

            // Libraries
            
            #include  <TM1637Display.h>
            #include <math.h>
            
            // Pins
            #define CLK 2
            #define DIO 3
            #define PIEZO A0
            #define THRESHHOLD 100
            
            // Variables
            int reading;
            long lastBeat;
            
            // Set up display library
            TM1637Display display(CLK, DIO);

            Step 17: SKETCH: SETUP FUNCTION

            If you're building the sketch step-by-step, type the following for the setup() function.

            1. Use the pinMode function to declare the piezo pin as an INPUT pin, since we're going to read from it.

            2. Use the setBrightness function to set the digital display to the brightest level. It uses a scale from 0 (least bright) to 7 (most bright).

            3. Since we don't have a prior drum stroke, set that variable to the current time.

            void setup() {
               // Set up pins
               pinMode(PIEZO, INPUT);
            
               // Set display brightness
               display.setBrightness(7);
            
              // Record first hit as now
               lastBeat = millis();
            }

            Step 18: SKETCH BODY: THE LOGIC

            Type the following for the main loop() function if you're building the sketch step-by-step.

              1. Read the value of the piezo sensor until the sensor reads a value above the threshhold, indicating a hit on the snare drum. Store the current time of the stroke as thisbeat.

              2. Then, call the calculateBPM function to calculate beats per minute. Pass the function the time of this stroke and the time of the last stroke for the calculation. (The next step contains the body of the function). Store the result in bpm.

              3. Next, display the beats per minute on the LED display by passing the result to the function from the TM1347 library called showNumberDec().

              4. Finally, set the time of the previous stroke (lastbeat) to be the time of this stroke (thisbeat) and wait for the next hit to the drum.

              void loop() {
                    // Did we get a drum hit?
                    int piezo = analogRead(PIEZO);
                    if (piezo > THRESHHOLD) {
                       // Record the time, calculate bpm and display result
                       long thisBeat = millis();
                       int bpm = calculateBPM(thisBeat, lastBeat);
                       display.showNumberDec(bpm);
              
                       // thisBeat is now lastBeat for the next drum hit
                       lastBeat = thisBeat;
                  }
              }

              Step 19: SKETCH: CALCULATE BEATS PER MINUTE

              Hint: Put this function above the setup function in the program so you don't have to declare it twice.

              Refer to the diagram above for a sample calculation.

              1. Create a function to perform the beats per minute (bpm) calculation. Accept the time of this drum stroke (thisTime) and the time of the previous drum stroke (lastTime) as parameters.

              2. Subtract the time between the two drum hits and store that as elapsed. The difference in time provides the number of beats (1) per millisecond (ms).

              3. Convert beats per millisecond to beats per minute. Since there are 1000 milliseconds in a second, divide 1000 by the time between the two strokes to get beats (1) per second. Since there are 60 seconds in a minute, multiply that by 60 to get beats (1) per minute. Round the final result to return an integer (whole number) value.

              If you prefer, you can download the final sketch from this step.

              int calculateBPM(long thisTime, long lastTime) {
                 long elapsed = thisTime - lastTime;
                 double bpm = round(1000. / elapsed * 60.);
                 return (int)bpm; 
              }
              

              Step 20: SAVE AND UPLOAD

              1. In the Arduino IDE, select File and choose Save. Type a name for your sketch and click Save to save the sketch (you only have to name it the first time you save it).

              2. Select Sketch and choose Upload to upload the sketch to your Arduino and get ready for testing.

              Step 21: CONNECT THE BATTERY AND TEST THE PROTOTYPE

              Test the device before you put together the final version.

              1. Connect the battery pack to the microcontroller t

              2. Place the piezo on a snare drum and hold it in place with your finger.

              3. Hit the snare drum a few times and verify that the reading provides the beats per minute based on your drum strokes.

              3. Once it's working correctly, you can solder the final version.

              Step 22: SOLDER EXTENSION WIRES TO PIEZO

              1. Since the piezo will be on the snare drum and the rest of the unit will be somewhere else, you need to extend the amount of wire on the piezo. Solder the ends of the piezo to about three feet of wire to provide extra slack.

              Hint: If your extension wire isn't colored, mark which is the red and which is the black wire from the piezo.

              Step 23: MOVE COMPONENTS TO PERF BOARD

                Next, move the circuitry from the plastic breadboard to the perf board and solder the components. The soldered version should be identical to the breadboard version.

                1. Move the microcontroller from the plastic breadboard to the perf board, making sure that the left and right sets of pins aren't connected and the USB connector is facing in the right direction. Solder each pin to the perf board.

                2. Solder the long piezo wires you attached (black wire to GND and red wire to A0).

                3. Solder the resistor to the same pins as the piezo.

                4. Solder the display unit as it was wired on the breadboard (CLK to D3; DIO to D2; VCC to +5V and GND to GND).

                Step 24: TRIM PERF BOARD

                1. Carefully cut the unused sections of the perf board so that the microcontroller fits in the project enclosure.

                Step 25: PROJECT ENCLOSURE: DIGITAL DISPLAY MODIFICATION

                1. Use a dremel or similar tool to cut a hole in the top of the project enclosure to fit the digital display.

                Step 26: PROJECT ENCLOSURE: USB MODIFICATION

                1. Cut a hole in the side of the project enclosure for the USB port.

                Step 27: PROJECT ENCLOSURE: NOTCH FOR PIEZO WIRES

                On the opposite end from where the microcontroller's USB connection is, cut a small notch for the piezo wires.

                Step 28: ASSEMBLE FINAL UNIT

                1. Mount the display in the top of the project enclosure so it fits in the hole you created.

                2. Mount the perf board with the microcontroller in the bottom of the project enclosure so that the USB port is accessible through the hole you created.

                Hint: I put a small piece of cork board between the two boards so they don't touch each other.

                Step 29: SCREW PROJECT ENCLOSURE TOGETHER

                Fit the piezo wires through the notch you created and screw the project enclosure together.

                Step 30: MOUNT PIEZO AND TEST

                1. Mount the piezo on the snare drum head using velcro strips.

                2. Please the rest of the device on the floor or in another location that's easy to view while you're playing the drums.

                3. Impress your bandmates with your enhanced timekeeping skills!

                Microcontroller Contest

                Participated in the
                Microcontroller Contest