Mini Tone Adjusting Piano Keyboard
The aim for this project was to learn and play around with a microcontroller-based device using various types of inputs, outputs, and features of the Arduino using C/C++; not the Arduino in-built functions. I had fun experimenting with this and actually ended up learning some cool things about how to play with vibrations for the buzzer to make different noises and how then to program it!
The device is a piano keyboard which uses user-friendly interactive hardware, such as a potentiometer to adjust volume and frequency of notes and pushbuttons switches to change between modes and sound piano keys. These are complemented with a piezo buzzer to produce tones, an LCD screen to display messages and values, as well as an LED light to signal whether the keyboard is active or not. The purpose of this device was to mimic a practicing tool/ music creating instrument.
How to Use
Once the device is turned on, the user is prompted to select between using either pre-set values for volume and frequencies, or to set them manually. This is done through serial communication by typing either ‘Y’ or ‘N’ (this is prompted both through the LCD screen and UART). If the user decides to use pre-set values (‘Y’), the piano enters directly into ‘free-play piano mode’ and the keyboard is active. However, if the user decides to manual tune values (‘N’), the device enters ‘adjustment mode’ and can be tuned using the potentiometer. When tuning the values, they are displayed on the screen in real time and can be selected using the mode button. Once all parameters are set, the user enters ‘free-play’ piano mode.
When in ‘free-play’ piano mode, an LED is lit up to signal that the keyboard keys are active and will sound when pressed. The user can play the keyboard freely and create music by pushing down on the keys. The values for volume and frequencies of each note are displayed on the LCD screen when the respective piano keys are pressed. Once exiting this mode, the user is displayed with the amount of time passed in ‘free-play’ piano mode. A final press of the mode button returns the user to the original prompt to select pre-set values or manually set values for volume and frequencies and the cycle begins again.
Device Features
Digital I/O Switches & Interrupt Based Debouncing
The device uses multiple pushbutton switches. The ‘mode button’ -on the far right- is used to select/ switch between modes. This button features an interrupt base debouncing which ensures that multiple clicks are not counted. This is highly important as when setting initial values for volume and frequencies of notes, if modes are skipped over, the process would need to be restarted to set values again.
Digital I/O LED
There are two LEDs used in this device. The first is the LCD screen backlight which allows for improved readability when viewing the LCD screen. The second is a red LED placed beside the keyboard. When the red LED is low, this signals that the keyboard has no functionality and when the LED is high, this signals that the keyboard is active and ready to play.
Analog Input – ADC
The device uses two analog input pins. The first is for the keyboard pushbuttons, which takes advantage of a resistor ladder to read different voltages when different pushbuttons are pressed (keyboard switch matrix). This allows for the ability to read multiple pushbuttons with only one input pin. This is especially useful as with the LCD screen uses 6 I/O pins which limits the number of remaining pins. The second is for a potentiometer. This is used to set the volume of the buzzer and adjust frequencies of each key. This allows for an easy way to adjust these values, increasing user friendliness.
Analog Output – PWM
The device uses an analog output on two different PWM I/O pins to create tones on a piezo buzzer. The two PWM signals produce a push and pull between the two pins creating an alternating current (AC) like signal. This also allows for greater volume on the piezo as, normally with PWM output, the loudest tone that can be made is at a 50% duty cycle. Which at 5 volts is like sending 2.5 volts. However, with both pins out of phase, the piezo is receiving a 5-volt average, rather than a 2.5-volt average. Doing this also increases the piezo’s life as the transducer disc is now deforming uniformly, rather than on one side and maintains sound quality for longer.
Serial I/O – UART
Serial I/O – UART is used in the project initially to select between pre-set values for volume and frequencies or to select manual tuning. The user is prompted to type into the serial com to do so. This gives the option to the user to minimise the amount of time in setting initial values and jumps straight to ‘free-play piano mode’. The serial communication is also used throughout the project as a second screen to display values, this is particularly useful when debugging the device.
LCD Screen
The LCD screen is used for several different purposes. Overall, it provides a user-friendly platform to integrate with the rest of the hardware. Primarily it is used to display values read from the potentiometer when setting the volume and frequencies of the keys. It also provides suggestions of common piano frequencies when setting the frequency notes. This is done through using LCD direct write coding.
Timers
All timers on the ATMEGA328 are used in this project. Timer 0 for button debouncing and Timer 1 for two PWM outputs. Timer 2 is used to calculate the amount of time passed when in ‘free-play piano mode’. This number is then displayed to the user once they exit this mode and allows the user to know how long they have been playing the piano.
That’s it for this project!
Asier :)