Arduino Touch Piano




Introduction: Arduino Touch Piano

About: Always learning.....

Welcome to my instructable. This one contains instructions on how to make a musical instrument using arduino. There are many different unique ways to make noises from an arduino and a cheap speaker. In this example I am using light dependent resistors that act like buttons or piano keys. The instructable will cover setting up the light sensors light buttons and making different tones with a speaker. I also added a RGB LED that changes color based on the keys played but i will not focus on that extra part here. Take small bits from here or the whole thing to create your own electronic instrument.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Parts Needed

Arduino Uno
Light Sensor (LDR)
Jumper cables
10k ohm resistors
USB Cable

Optional:220 ohm resistors
Optional: RGB LED

Step 2: Schematic

Step 3: Variables

Here I am assigning variable names. The #define variable lets me write NOTE_C4 instead of 262 which corresponds to the frequency played by the speaker. I named the LDR pins and RGB LED pins so i can keep track of whats what. I also created three variables which will store the reading from each LDR

Step 4: Void Setup() {

Here is where I activate everything I will be using. The speaker Pin and The RGB LED pins are set as OUTPUTS. The LDR pins are set as INPUTS. I also activated the Serial monitor to help with values and bugs. You need to find out what values the LDR reads while covered and uncovered to use in the if statements in the next section of code

Step 5: Void Loop() {

Here is the beginning of the loop function which repeats over and over. The first three lines are used to read and store the values from the LDR's. There are two example if statements shown but there are 7 in total. When a finger is over the LDR the values increase. My values went from around 100 with all light, to around 400 with all darkness. This led me to pick 200 as a nice middle point. Each if statement is for a different combination of keys being pressed. If a statement is true the a special note is played and a color is shown.

Step 6: Void Other Functions (){

These are two simple function created to make life easier. This shows what is really happening when i can playTone or set color. this saves some lines of code but if you would like you can put what is in each of these functions in the if statements.

Teachers Contest 2017

Participated in the
Teachers Contest 2017

Audio Contest 2017

Participated in the
Audio Contest 2017

Be the First to Share


    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020
    • First Time Author Contest

      First Time Author Contest

    3 Discussions


    2 years ago

    This is amazing!!! Best Instructable in the history of the universe!!!!


    Reply 2 years ago

    Thank you, for your kind words stranger