Introduction: Micro-controller Based Metronome
A metronome is a timing device used by musicians to keep track of beats in songs and to develop a sense of timing among beginners who are learning a new instrument. It helps to maintain a sense of rhythm which is crucial in music .
This metronome built here can be used to set the number of beats per bar and the beats per minute. Once this setup data is entered , it beeps according to the data accompanied with appropriate lighting using LEDs. The setup data is displayed in an LCD screen.
Step 1: Components Required :
- Atmega8A Microcontroller
- · 16*2 Lcd Display
- · Piezo Buzzer
- · LEDs (green, red)
- · Resistors (220e , 330e, 1k, 5.6k)
- · Pushbuttons (2* anti-locking, 1* locking)
- · 3V CR2032 Coin Cell Battery (*2)
- Coin Battery Holder (*2)
- · 6pin Relimate (polarized) Connector
Step 2: Making the Circuit
Make the circuit connections as shown in the picture on a veroboard and solder the connections properly
Step 3: Features of the Metronome
The metronome’s interface is mainly occupied by the lcd screen . Above it is the 8A microcontroller placed centrally with the LEDs and buzzer to the right. The three switches and the Relimate connector are placed at the top.
The whole project is powered by two coin cell batteries only (in series @6V 220mAh) with an estimated runtime of 20 days to 1 month (not continuously) . Hence it is moderately power efficient and has a current requirement of 3 – 5 mA.
The self locking switch is placed at the extreme left and is the ON/OFF button. The button in the middle is the Setup button and the button to the right is used to change the values for bpm and beats(per bar).
When the ON/OFF switch is pressed , the lcd turns on and displays the value of beats per bar. It waits for 3 seconds for the user to change the value after which it takes the resultant value as its input. This value ranges between 1/4, 2/4, 3/4 , 4/4.
Then it displays the beats per minute (bpm) and again waits for 3 seconds for the user to alter the value after which it sets the particular value. This wait time of 3 seconds is calibrated after the user alters a value. The bpm values can vary from 30 to 240. Pressing the Setup button during the bpm setup resets its value to 30 bpm which is helpful in reducing the amount of button clicks. The bpm values are multiples of 5.
After the setup is done, the lcd backlight turns off to save battery. The Buzzer beeps once for every beat and the LEDs blink one at a time alternately for each beat. To change values, the Setup button is pressed. Upon doing that, the lcd backlight turns on and the beat prompt appears just as mentioned before with the same procedure afterwards.
The Atmega8A microcontroller consists of 500 bytes of EEPROM meaning that whatever values of beats and bpm are entered, remain stored even after the metronome is turned off . Hence turning it back on , makes it resume with the same data that was entered before.
The Relimate connector is actually an SPI header which can be used for two purposes. It can be used to reprogram the Atmega8A microcontroller to update its firmware and add new features to the metronome. Secondly, an external power supply can also be used to power the metronome for hardcore users . But this power supply must not be greater than 5.5 volts and it overrides the ON/OFF switch. For safety reasons, this switch MUST be off so that the external supply doesn’t short with the inbuilt batteries.
Step 4: Description
This project is made using the Atmel Atmega8A microcontroller which is programmed using the Arduino IDE via an Arduino Uno/Mega/Nano used as an ISP Programmer.
This microcontroller is a lesser featured version of the Atmel Atmega328p which is used extensively in the Arduino Uno. The Atmega8A comprises of 8Kb programmable memory with 1Kb RAM. It is an 8 bit microcontroller running at the same frequency as the 328p i.e. 16Mhz.
In this project , as current consumption is an important aspect, the clock frequency has been reduced and the internal 1 Mhz oscillator is used. This greatly reduces the current requirement to about 3.5 mA @3.3V and 5mA @4.5V.
The Arduino IDE doesn’t have the facility to program this microcontroller. Hence a “Minicore” package (plugin) was installed to run the 8A with its internal oscillator using an Optiboot bootloader. It was noticed that the power requirement of the project increased with increasing voltage. Hence for optimum power utilization , the microcontroller was set to be run at 1 MHz with a single 3V coin battery drawing just 3.5mA. But it was observed that the lcd was not functioning properly at such a low voltage. Hence the decision of using two coin batteries in series was applied to bump the voltage to 6V. But this meant that the current consumption increased to 15mA which was a huge drawback as battery life would get very poor. Also it exceeded the safe voltage limit of 5.5V of the 8A microcontroller.
Hence a 330 ohm resistor was connected in series with the 6V power supply to get rid of this problem. The resistor basically causes a voltage drop across itself to lower the voltage level within 5.5V to safely run the microcontroller. Additionally the value of 330 was chosen by taking into consideration various factors :
- · The goal was to run the 8A at as low a voltage as possible to save power.
- · It was observed that the lcd stopped working below 3.2V although the microcontroller still functioned
- · This value of 330 makes sure that the voltage drops at the extremes are exactly accurate to make full use of the coin batteries.
- · When the coin cells were at their peak, the voltage was around 6.3V , with the 8A receiving an effective voltage of 4.6 – 4.7 V (@ 5mA) . And when the batteries were almost dried out, the voltage was around 4V with the 8A and the lcd receiving just enough voltage i.e. 3.2V to function correctly. (@3.5mA)
- · Below the 4v level of the batteries , they were effectively useless without any juice left to power anything. The voltage drop across the resistor varies the entire time since the current consumption of the 8A microcontroller and the lcd reduces with reducing voltage which essentially aids in increasing the battery life.
The 16*2 LCD was programmed using the built in LiquidCrystal library of the Arduino IDE. It utilizes 6 data pins of the 8A microcontroller. Additionally , its brightness and contrast was controlled using two data pins. This was done so as to not use an extra component i.e. a potentiometer. Instead, the PWM function of data pin D9 was used to adjust the contrast of the screen. Also the lcd backlight needed to be off when not required , so this would not have been possible without using a data pin to power it. A 220 ohm resistor was used to limit the current across the backlight LED.
The Buzzer and the LEDs were also connected to the data pins of the 8A (one for each) . A 5.6 k ohm resistor was used to limit the current across the red LED while a 1k ohm was used for the green one. The resistor values have been chosen by acquiring a sweet spot between brightness and current consumption.
The ON/OFF button isn’t connected to a data pin and is simply a switch that switches the project. One of its terminals connect to the 330 ohm resistor while the other connects to the Vcc pins of the lcd and the 8A. The two other buttons are connected to data pins that are internally pulled up to supply voltage via software. This is necessary for the working of the switches.
Additionally the data pin, the Setup button connects to, is a Hardware Interrupt pin. Its interrupt service routine (ISR) is activated in the Arduino IDE. What this means is that whenever the user wants to run the setup menu , the 8A suspends its present operation of working as a metronome, and runs the ISR which basically activates the Setup menu. Otherwise , the user would not be able to access the Setup menu.
The EEPROM option mentioned before makes sure that the data entered remains stored even after the board is switched off. And the SPI header comprises of 6 pins – Vcc , Gnd, MOSI , MISO, SCK, RST. This is part of the SPI protocol and as mentioned before, an ISP programmer can be used to program the 8A again for adding new features or anything else. The Vcc pin is isolated from the battery positive terminal and hence the Metronome provides the option to use an external power supply keeping in mind the restrictions mentioned before.
The entire project was constructed in a Veroboard by soldering the individual components and the appropriate connections according to the circuit diagram.
4 years ago
This is a cool project, do you have any photos from your build?
Reply 4 years ago
Actually I hadn't taken any photos while making the project, which I realized later. The video which is at the top displays the completed product. But I'll make sure to take photos for the next Instructable I write .