Arduino metronome with keypad input - Page 1
Forum section: electronics / projects

author: JuiceKing
author_rank: Regular Contributor
timestamp: July 30, 2012, 03:50:56 am
content: My wife is a musician, and this morning she complained that her metronome didn't have the precision she wanted. She could set it to 72 or 76 beats/minute, but nothing in between.Happily, she said that she didn't need a metronome to be battery-powered, which makes it easier. This looked like a nice opportunity to use a 12-button keypad I had in my parts box with an Arduino Uno. The Arduino would be simple to set up as a metronome with a flashing LED and clicking piezo, and the keypad would take an arbitrary input for tempo.The result is below. One thing I discovered in working on this is that the Arduino has a very easy-to-use external interrupt scheme, tied to pins 2 and 3. I connected pin 2 to the '*' button on the keypad. So, to enter a tempo, my wife would press '*' to get the Arduino's attention, followed by the number. I used pin 3 to drive an LED, and pin 0 to drive a piezo buzzer.One useful lesson learned: pins 0 and 1 have special serial duties associated with code loading as well as run-time serial communications for monitoring. That means that if you use serial communications for debugging messages, you must avoid using pins 0 and 1 for anything else or the utility communications will clobber your user data and vice-versa. This prototype continues to use pin 0 for the piezo buzzer, but you get a bit of spurious buzzing at boot-time and when code is loading. Unfortunately, the Arduino Uno has just enough digital input lines to handle the digits 0-9, plus the special character '*' and that leaves only 1 pin for the LED left-over, plus pins 0 and 1. That means there aren't enough pins for mapping to the '#' button, which might have served as a special termination character--an "Enter" key. I got around this by making all tempo inputs a 3-digit number. That means that 60 beats/minute is entered "*060".Even if you don't need or want a metronome, it seems to me that this is a useful if you want to use a keypad with the Arduino for any kind of digital input. I see that there are matrix-driven keypads that use fewer pins in exchange for more complicated decoding. That's probably a better choice, and if I knew this much I wouldn't have bought this particular keypad. But since I had it on-hand, it's what I used.Code is attached, and here's how it looks:- Ken

author: FenderBender
author_rank: Super Contributor
timestamp: July 30, 2012, 07:14:03 pm
content: What a coincidence...I was laying in bed last night thinking of projects and I thought how simple and effective an metronome would be and you can deck it out with all sorts of nice features. It would be interesting if we could develop a tuner also...I'm not sure exactly how one would do that because musical instruments have all sorts of harmonics and I'm not sure how you would analyze all of that..You'd have to extract the fundamental frequency somehow. Actually all sorts of stuff you'd need. Lot's of filters. Hmmm maybe some other time. Haha

author: AlphZeta
author_rank: Regular Contributor
timestamp: July 30, 2012, 08:16:08 pm
content: Great job! The keypad input is a nice touch.I have built two metronomes for my daughter over the years. Since a typical metronome only has around 30 discrete frequencies, I used LEDs to multiplex the display in my first built (http://www.kerrywong.com/2011/01/16/digital-metronome/).A couple of months ago, I built another one (http://www.kerrywong.com/2012/06/21/digital-metronome-revisited/) with improved sound level and displays. It is certainly fun to build something that is also useful.

author: IanJ
author_rank: Unknown
timestamp: July 30, 2012, 08:55:41 pm
content: Quote from: JuiceKing on July 30, 2012, 03:50:56 amYes, I've bricked a serial LCD when uploading to an Arduino because the USB data is echo'd out on pin 1. Got away with it a few times until the USB data just happened to match some config codes for the LCD. No amount of soft/hard reset could fix it.Ian.