Introduction: Keypad Module Piano With RGB LED

About: Just a highschool student building stuff.

Intro

Hello ladies and gentleman, welcome to my very first instructable! Today, I will be teaching you how to create a piano with main components being a keypad module and a piezo buzzer and have it able to play DO-RE-MI and so on.

The keypad module most often intended purpose, is to be a keypad combined with an arduino RFID to create a safe box for valuable items. In this case I changed the keypad, instead of protecting something I decide to use to speak the simple joy and music.

Idea Concept

The idea concept for this creation, evolve from a simple happy memory while playing the xylophone when I was younger in music class. The amount of joy and excitement running through my body was at its peak, I mean every kid was easily satisfied and my satisfaction was playing the xylophone.

Research

After your idea light bulb above lights up, a little research must be done. After browsing the web for sometime, I can came across my idea I initially thought of! A keypad module turned piano, someone has created the same project video here. Thinking ahead I needed to add a separate component that would further enhance the project but make it more engaging and be able to call it my own.

Step 1: Materials Needed

Materials List

Material list is in-order with pictures above.

Step 2: Building Time!

4x4 Keypad Module & Piezo Buzzer

Theory

As the 4x4 keypad module and piezo buzzer contain so many individual pin input and I'll decide to split the components used into two pairs. Focusing on the keypad, usually used as a input. The SunFounder 4*4 Matrix Keypad Module is a matrix non- encoded keypad consisting of 16 keys in parallel, The keys of each row and column are connected through the pins outside – pin Y1-Y4 as labeled beside control the rows, when X1-X4, the columns.

Purpose

Purpose of these components to the entire project, is to allow the user to press a button which is set to a specific sound created by the piezo buzzer through frequency in hertz.

Matrix Module Pin - Arduino Pin

  • 4 - 2
  • 3 - 3
  • 2 - 4
  • 1 - 5
  • 5 - 6
  • 6 - 7
  • 7 - 8
  • 8 - 13

Piezo Buzzer - Arduino Pin

Black - GND

Red - Power

My most difficult task in this build is figuring out where each wire is plugged into. Above I provide you and quick and easy how to way of the wire locations, as long as followed top to bottom, tip is take your time and make sure every pin is correctly inserted into the right slot.

*Tip is to follow where each wire is location from one end to another.

All Tinkercad sketch of the specific component wires are colour coded correctly so follow along carefully.

Step 3: Sound Sensor Module and RGB LED

Sound Sensor Module and RGB LED

Theory

The sound sensor module allows you to detect when sound has exceeded a set point you select. Sound is detected via a microphone and fed into an LM393 op amp. Once sound level exceeds the set point, an LED on the module is illuminated and the output.

Purpose

Purpose of these components to the entire project, is to obtain a sound/volume reading of the sound sensor module and through that reading an RGB LED will activate the correct colour pertaining to sound.

Sound Sensor Module - Arduino Pin (Use 3 Pin Jumper Wire)

  • Output - A0 Analog Pin
  • GND - Any open GND pin slot
  • VCC - 3V

RGB Common Anode (+) LED - Arduino Pin

  • Red - 9
  • Power - 5V
  • Green - 10
  • Blue - 11

Keep in mind to wire, each individual wire through a 330 ohm resistor. Use the picture above as reference.

My most difficult task in this build is figuring out where each wire is plugged into. Above I provide you and quick and easy how to way to of wire locations, as long as followed top to bottom, tip is to take your time and make sure every pin is correctly inserted into the right slot to prevent future debugging.

*Tip is to follow where each wire is inserted either way.

All Tinkercad sketch of the specific component wires are colour coded correctly so follow along.

Step 4: Code

Code

This code allows all the components to work together by using newly defined function to contain all the many controls a single component that has many changeable variables those components were the RGB led and using rgb colour to change the colour while on and the piezo buzzer and the sound it would make depending on the button push.

A must have within this code was the keypad library

Link here: https://playground.arduino.cc/uploads/Code/keypad....

Once downloaded add the new library into the arduino, afterwards insert the single line of code needed to activate it.

Difficulties I had during the code was where to place the newly defined functions as through trial and error I figured out it had to be in the setup and not the loop.

Code

#include // Keypad Library

int greenPin = 11; //RGB Green Pin connected to digital pin 9

int redPin= 10; //RGB Red Pin connected to digital pin 9 int bluePin = 9; //RGB Blue Pin connected to digital pin 9 int speakerPin = 12; // speaker connected to digital pin 12 const byte ROWS = 4; // four rows const byte COLS = 4; // four coloums const int soundPin = A0; //sound sensor attach to A0

char keys[ROWS][COLS] = { {'a','b','c','d'}, {'e','f','g','h'}, {'i','j','k','l'}, {'m','n','o','p'} }; // Visualization of keypad module

byte rowPins[ROWS] = {2, 3, 4, 5}; // connect to the row pinouts of the keypad byte colPins[COLS] = {6, 7, 8, 13}; // connect to the colum pinouts of the keypad

Keypad keypad = Keypad ( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Creates keys

void setup(){

pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output pinMode(redPin, OUTPUT); // sets the red pin to be an output pinMode(greenPin, OUTPUT); // sets the green pin to be an output pinMode(bluePin, OUTPUT); // sets the blue pin to be an output

Serial.begin (9600); } void setColor(int red, int green, int blue) // New defined function to allow RGB to display colour through RGB code { #ifdef COMMON_ANODE red = 255 - red; green = 255 - green; blue = 255 - blue; #endif analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); }

void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds){ // the sound producing functions int x; long delayAmount = (long)(1000000/frequencyInHertz); long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2)); for (x=0;x

void loop (){ char key = keypad.getKey(); int value = analogRead(soundPin);//read the value of A0 Serial.println(value);//print the value

if (key != NO_KEY) { Serial.println(key); } if (key=='a'){ beep(speakerPin,2093,100); setColor(218, 112, 214); } if (key=='b'){ beep(speakerPin,2349,100); setColor(218, 112, 214); } if (key=='c'){ beep(speakerPin,2637,100); setColor(218, 112, 214); } if (key=='d'){ beep(speakerPin,2793,100); setColor(218, 112, 214); } if (key=='e'){ beep(speakerPin,3136,100); setColor(218, 112, 214); } if (key=='f'){ beep(speakerPin,3520,100); setColor(218, 112, 214); } if (key=='g'){ beep(speakerPin,3951,100); setColor(218, 112, 214); } if (key=='h'){ beep(speakerPin,4186,100); setColor(218, 112, 214); } if (key=='i'){ beep(speakerPin,2093,100); setColor(230, 230,0 ); } if (key=='j'){ beep(speakerPin,2349,100); setColor(180,255,130); } if (key=='k'){ beep(speakerPin,2637,100); setColor(130,255,130); } if (key=='l'){ beep(speakerPin,2739,100); setColor(130,220,130); } if (key=='m'){ beep(speakerPin,3136,100); setColor(0,255,255); } if (key=='n'){ beep(speakerPin,3520,100); setColor(0,220,255); } if (key=='o'){ beep(speakerPin,3951,100); setColor(0,69,255); } if (key=='p'){ beep(speakerPin,4186,100); setColor(255, 0,255 ); } }

Attachments

Step 5: Final Thoughts

Final Thoughts

Final thoughts of this project is its intended purpose is to be a toy, to bring fun and simplistic joy. As this project is a complete and working on, I believe this build and can furthered with maybe more components such as a recording element, or copy/simon says element, or even LCD with the notes appearing to play a specific song.

I would love to know your opinion about the Keypad Module, what components you thought could have been added. Are you going to use it in any of your projects? Please post your ideas in the comments section below.

Please make sure to share if you enjoyed this arduino project.