Project tutorial
How to make music with an Arduino

How to make music with an Arduino © CC BY

In this video I explain how you can use an Arduino to make music using just a speaker and a resistor.

  • 30,628 views
  • 10 comments
  • 30 respects

Components and supplies

Apps and online services

About this project

In this video I explain how you can use an Arduino to make music using just a speaker and a resistor.

Like many similar projects, this one generates tones that match the notes of a piano. Unlike many of these projects, however, this one does not use a lookup table to obtain the frequencies. Instead, the tones are generated using a calculation. The calculation accepts a number from 1 through to 88. This number correlates to a key on an 88-key piano.

The Arduino library offers a tone() function which can be used to generate square-wave tones, but this function is unable to generate tones under 31Hz. An 88-key piano has a few notes with frequencies that fall below 31Hz. So, if you’d like to generate the full range of notes from an 88-key piano, the tone() function cannot be used. Instead, I will show you how to generate square-wave tones using a simple delay.

This project works at a microsecond level. A microsecond is one millionth of a second. This project makes extensive use of the Arduino library’s delayMicroseconds() function, but therein lies another minor issue, as it cannot reliably delay for more than a few thousand microseconds, which this project sometimes needs to do, so I will show you how to overcome this too.

One last thing about this project is that, despite the issues described above, the code for the project is really rather small, as the code just about fits onto a single screen (your resolution may vary!). To be fair, that is without any code comments, but a link to fully commented code is available in the video description.

I hope you enjoy this project!

How to install the Arduino IDE in Ubuntu

Code

Project code

Schematics

Wiring
Connect speaker to GND and pin 12 via a resistor.
Wiring2 eq7zwj0hnr

Comments

Similar projects you might like

Arduino as Waveform Synthesizer for Music

by Doctor Volt

  • 19,828 views
  • 12 comments
  • 53 respects

Newbie Music Player

Project in progress by Michael Marinis

  • 8,299 views
  • 4 comments
  • 17 respects

New Electronic Music Instrument Design

Project showcase by cpeckmusic

  • 10,150 views
  • 1 comment
  • 30 respects

Control Music Volume and Ledbar Using Slider of 1Sheeld

Project tutorial by ahmed ismail

  • 3,492 views
  • 2 comments
  • 14 respects

Music With Arduino and Relay

Project tutorial by edison science corner

  • 2,606 views
  • 1 comment
  • 1 respect

Music Spectrum Visualizer with Arduino Nano

Project tutorial by Rahul Mohoto

  • 5,123 views
  • 0 comments
  • 12 respects
Add projectSign up / Login