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.

  • 18,925 views
  • 4 comments
  • 25 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

Newbie Music Player

Project in progress by Michael Marinis

  • 5,329 views
  • 2 comments
  • 15 respects

Control Music Volume and Ledbar Using Slider of 1Sheeld

Project tutorial by ahmed ismail

  • 2,119 views
  • 2 comments
  • 14 respects

New Electronic Music Instrument Design

Project showcase by cpeckmusic

  • 6,723 views
  • 1 comment
  • 24 respects

Translightion Board (Controllable Music Visualizer)

Project tutorial by Joshua and Miranda Hansen

  • 2,841 views
  • 1 comment
  • 13 respects

TuneGlass: Can We Make MUSIC Using Our EYES???

Project tutorial by ashraf_minhaj

  • 1,963 views
  • 0 comments
  • 13 respects

Fingerscan: Music at Your Fingertips

Project showcase by touchmysound

  • 11,605 views
  • 6 comments
  • 32 respects
Add projectSign up / Login