Gustavo Silveira is a composer, multimedia artist, and maker. Silveira holds a Bachelor's degree in music composition from the Federal University of Pelotas and a Master's degree in Music and Technology from Georgia Southern University in the United States.

Since 2015, Gustavo has been creating musical interfaces with Arduino, such as MIDI controllers and synthesizers, and has created the blog Músico Nerd, where he shares various open source projects and tutorials in the field.

In 2018, he was a finalist in the Guthman New Music Instrument Competition, the world's most important competition for new musical instruments, with the XT Synth. In 2019, he worked as a Human-Computer Interaction Electronics Designer at the IDIA Lab at Ball State University in the United States, creating interactive audiovisual installations.

Gustavo has presented his work as a maker at major Maker Faires such as the Bay Area Maker Faire in San Francisco and the World Maker Faire in New York, and his work has been featured on specialized websites such as Gearnews, DJ Tech Tools, and the Arduino website.


Learn how to build your MIDI controller in the easiest a fastest way possible.


Watch my latest YouTube video here!👇


Access my projects!👇


blog image

3# How to Code Buttons (Complete Guide) - MIDI Programming for the Arduino

February 06, 20243 min read


Greetings makers! Welcome to another installment of our MIDI programming series for Arduino. In today's tutorial, we will delve into the fascinating world of utilizing buttons to send MIDI notes with your Arduino. This is a crucial skill as we continue our journey in crafting custom MIDI controllers from scratch. Before we dive in, make sure you've caught up on the basics covered in previous classes, such as understanding the Integrated Development Environment (IDE) and implementing the MIDI USB Library. These foundational elements are essential for transforming your Arduino into a plug-and-play MIDI controller. Additionally, we'll touch on vital Arduino concepts like variables and arrays, so if you're not already familiar, I encourage you to explore those aspects. Now, let's embark on this exciting coding adventure!

Understanding Buttons

Before we proceed with the coding magic, let's revisit the concept of buttons. A button is essentially a switch that allows the flow of current when pressed. In our case, we're working with push buttons. If you need a refresher on buttons and Arduino basics, check out my detailed workshop on DIY MIDI controllers here.

Coding the Button

Let's jump into the code. We'll start by creating variables for the button and LED pins, establishing the necessary connections, and ensuring proper functionality.


This code segment establishes the foundation for our button functionality, including pin declarations, serial communication initiation, and updating the LED state based on the button's condition.

Wiring the Circuit

To ensure our code translates into tangible results, we need to set up a physical circuit. In this section, we'll explore the wiring process and employ a pull-down resistor to prevent unintended button presses.

  1. Connect one button leg to pin 2 on the Arduino and the other to 5 volts.

  2. Add a resistor from the button's second leg to ground, creating a pull-down resistor configuration.

  3. Connect the ground of the Arduino to the ground rail of the breadboard.

  4. Finally, link the built-in LED of the Arduino to pin 13.

Simulating the Circuit

To visualize our setup before implementation, we'll use Tinkercad. Follow the link provided, create an account, and replicate the described circuit with an Arduino, breadboard, button, and necessary connections.

Advanced Features: Debouncing and MIDI Integration

To enhance the button's functionality, we introduce a debouncing algorithm to mitigate button bouncing issues. This algorithm ensures reliable button readings by considering the time elapsed since the last press.

Moreover, we elevate our project by integrating the MIDI USB Library. This addition allows us to send MIDI messages with each button press, providing a richer user experience.


This enhanced code section demonstrates the integration of MIDI capabilities. MIDI notes are sent when the button is pressed and released, elevating our Arduino project to new heights.

Testing and Conclusion

With the code finalized, upload it to your Arduino, open a MIDI monitor app, and verify the correct transmission of MIDI messages. For a more immersive experience, connect your Arduino to Ableton Live, add a MIDI instrument, and witness the magic as your buttons trigger notes.

Congratulations! You've successfully coded your Arduino to use buttons for sending MIDI notes. I trust this tutorial has been enlightening. Should you have any queries, don't hesitate to reach out. Happy coding, and stay tuned for more maker-centric content!


🎛️ Download the Arduino Sketch: https://go.musiconerd.com/files-download

🎹 Nerd Musician Pro: https://go.musiconerd.com/nerd-musician-pro

🎛️ DIY MIDI Controller Workshop: https://go.musiconerd.com/diy-midi-controller-workshop

🎹 Curso Fazendo Música com Arduino em Português: https://go.musiconerd.com/fazendo-musica-com-arduino

🎛️ Join the Tinkercad Class: https://www.tinkercad.com/joinclass/5L69NZQG2

diy midi controllerarduino midi controllerhow to code a buttonnerd musician

Gustavo Silveira

Back to Blog

By Gustavo Silveira

Gustavo Silveira is a Brazilian multimedia artist, music technologist, and maker. A DIY freak. Gustavo holds a master’s in Music Technology – from Georgia Southern University – and his work has been featured on many specialized websites, Maker Faires, competitions, etc. In 2018 Gustavo won the Averitt Award in excellence in instruction by Georgia Southern University and was a finalist at the Guthman New Musical Instrument Competition, the biggest competition for new musical instruments in the world!