Atmega 32u4 Based USB Musical Keyboard

The music keyboard is one of the most common musical instruments. The electronic musical keyboards have been around for a long time. The electronic music keyboards synthesize musical sounds electronically according to MIDI (Musical Instrument Digital Interface) standards. Fortunately, the USB protocol does have provision to implement the MIDI standard under Audio Class Devices. The USB protocol has the MIDI subclass under the Audio Class 1.0.  In this project, the device designed is based on the MIDI subclass and it transmits the MIDI Data Packets using Audio Class of the USB protocol.
On any musical keyboard, there are physical keys pressing which specific musical notes having predetermined pitch and volume are generated. Any electronic music keyboard also works similarly. It also has keys pressing which specific musical notes having a predetermined pitch and volume are generated. The device designed in this project also has keys pressing which specific musical notes having a predetermined pitch and volume are generated but the musical notes are not physically generated instead the MIDI data packet specifying the musical note is transmitted to the computer. On the computer, the musical note can be realized by using any desktop application for music synthesis.
Atmega 32u4 Based USB Musical Keyboard
A controller chip needs to manage the MIDI packets on the device. As controller chip, 8-bit USB AVR – Atmega 32u4 is used in the project. The AVR based Lightweight USB Framework (LUFA) is used as the firmware of the chip which implements the USB protocol and wrap up the MIDI packets for transmission to the computer. With the use of LUFA firmware, the device driver code to implement USB protocol is not needed to be written explicitly. Modifying the firmware code to customize the functioning of the MIDI subclass driver will be what all needs to be done.
The project uses Arduino Pro Micro as the controller board which connects with a personal computer by on-board USB port by an USB cable. The board has tactile switches interfaced to it which function as musical keys.


This project is based on Arduino Pro Micro which has the USB AVR – Atmega 32u4 as the sitting MCU. In order to understand this project, one must have basic knowledge of the AVR microcontrollers and the embedded C programming for AVRs. WinAVR Studio is used to write, edit and compile the project code, so closely following the project shall require familiarizing with the above stated IDE as well. Though LUFA framework takes care of implementing the USB protocol and has APIs to abstract the lower level codes, understanding USB protocol is recommended to understand how actually the project is working. In fact, if anyone has already worked on some other microcontroller, it will not be much pain to understand and follow this project as the project code is about getting digital input at the AVR microcontroller and modifying the LUFA device driver for MIDI subclass to generate customized MIDI data packets.


1. Arduino Pro Micro
2. Breadboard
3. Connecting wires
4. Push buttons
5. Micro USB cable
6. 10K resistors


1. WinAVR Studio
2. AVR Dude
3. LUFA Firmware
4. Anvil Studio


The project uses Arduino Pro Micro as the USB controller chip. A set of seven tactile switches are connected at the port B and D of the Arduino for generating seven different musical notes. The switches are connected at pins 2, 3, 4, 5 and 6 of Port B and pins 0 and 7 of Port D with following musical notes assigned to them.
The Program code for the project is burnt to the Arduino Pro Micro using AVR Dude. The Arduino board is connected to the USB port of a PC by a USB cable.


In this project, the USB protocol is implemented by the LUFA framework. For configuring the controller chip to work as a music keyboard, the MIDI Subclass of the Audio Class Driver of the LUFA framework will be used. The Audio Class 1.0 driver takes care of the transfers between the host device and the audio devices like microphone, speaker and USB Connect-able musical instruments.
When a USB device is attached to the host (PC), the host sends request for configuration details in the form of control transfer. The connected device has to respond with appropriate descriptors to get configured and ready for further operations. Only after configuration, the device can communicate with the host in the form of interrupt, isochronous or bulk transfers for executing the operations for which the device has been made. In case of MIDI keyboard, after configuring with the host device, it has to communicate with the host in the form of bulk transfers as the device will be actually sending music control information to the computer which will be saved to a temporary or permanent audio file for use by the desktop music synthesizer application. The process of identification and configuration of the device with the host is called enumeration.


The musical notes are used for the identification of the music. Like bits and bytes form the digital data, similarly musical notes together create the music. A musical note actually refers to a sound wave having specific frequency. The audible sound has frequency in range from 20 Hz to 20,000 Hz. The musical keyboards generate sound frequencies between 27.5 Hz to 4186 Hz. Between this range, specific frequencies are generated by the musical keyboards which are called the musical notes. Like the musical note A0 denotes 27.5 Hz frequency or 36.36 milliseconds period of sound wave. The note name for musical note can differ in different human languages. Like in English, the musical notes are represented by note names having alphabets A, B, C, D, E, F and G followed by a number. In musical terminology, the frequency of the musical note is referred by the term “Pitch”Another term associated with musical notes or music is volume. The volume refers to the amplitude of the sound wave and signifies the loudness of the sound. In musical terminology, the volume or amplitude of any musical note is referred by the term “velocity”MIDI and Musical Notes.
The MIDI protocol is used to exchange musical control information. In another way, this protocol does not transmit any sound signal, it just transmits the control information that is needed to regenerate the sound. In any MIDI data packet, the protocol transmits two control parameters – Pitch and Velocity of the sound signal to represent a musical note.
Pitch – It is a number between 0 and 127 that describes the frequency of the signal produced. Each pitch has its corresponding frequency. This means a total of 128 different frequency signals can be described by pitch, but not all are used in the actual implementation. For example, pitch number 21 is used to represent the frequency of 27.5 Hz.
Velocity – It is also a number between 0 and 127. It describes the Volume level or Amplitude of the sound produced. Higher velocity means louder sound.
A typical music keyboard has the following MIDI numbers representing the musical notes.
Read More:  Atmega 32u4 Based USB Musical Keyboard

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top