LED Piano With Display That Shows Note Being Played

by 804611 in Circuits > Arduino

647 Views, 5 Favorites, 0 Comments

LED Piano With Display That Shows Note Being Played

IMG_3129.JPG

I made a LED piano. The display shows "PLAY" when nothing is being presses. LED lights up whenever you press the note and the display shows what note is being played. The last button turns the red LED on and changes the octave up one and the display shows "HI" to indicate the higher octave is active and the key note overrides both PLAY and Hi.

Supplies

IMG_3128.JPG

Connect Power and Ground

IMG_3143.JPG

Connect Ground and power from Arduino to BreadBoard. Bridge the top and bottom rails together.

Connect Wires From Arduino Pins to Buttons

IMG_3142.JPG

Connect all pins from pin 2 all the way till pin 9 to the buttons, connect the opposite ends of the button to ground. Make sure all wires are securely connected and all pins are connected correctly from left to right. Add an extra wire from pin 10 to the right side and leave it for later for the buzzer

Connect the Green LEDs

IMG_3145.JPG
IMG_3146.JPG

Put a jumper cable from the arduino pin row on the breadboard to an empty row on the right. Take a 330 ohm resistor and bridge the jumper cable from the top of the breadboard to the bottom. Finally, connect a green LED from the resistor row to power and do for all 8 buttons. Ensure LEDs are connected to POWER and not ground and ensure all wired are secured properly.

Connect the Buzzer

IMG_3151.JPG

Use the extra wire from before and connect the negative side of the buzzer to the same row as the wire and the positive side of the buzzer (indicated with a "+") to ground on the power rail. Ensure that the buzzer is in the correct orientation or it will not make any sound.

4 Digit 7 Segment

IMG_3154.JPG
IMG_3155.JPG

Connect Pin 11 and 12 all the way to the end of the breadboard, Pin 11 goes to CKL and Pin 12 goes to DIO on the display (The location is written on the back near the pins). To the left of that you have power 5V (VCC) and ground (GND) Connect these to the power and ground rails. This is to connect the 4 digit 7 segment display to show the notes and PLAY and HI

Octave Change Button

IMG_3166.JPG

Connect the analog pin A0 to an open row on the breadboard, conned the button to the same row and connect a jumper cable in that same row too. Connect the other side of the jumper wire to the opposite side of the breadboard, connect a 330 ohm resistor from the cable row to the red LED. This will make sure the LED turns on when the button is pressed. Note: Temporary remove the display to make the wiring easy, then put it back after your done.

CODE

#include <TM1637Display.h>


#define CLK 11
#define DIO 12


TM1637Display display(CLK, DIO);


int buzzer = 10;


int btn1 = 2;
int btn2 = 3;
int btn3 = 4;
int btn4 = 5;
int btn5 = 6;
int btn6 = 7;
int btn7 = 8;
int btn8 = 9;


int highBtn = A0;


int lastKey = 0;


int NOTE_C4 = 262;
int NOTE_D4 = 294;
int NOTE_E4 = 330;
int NOTE_F4 = 349;
int NOTE_G4 = 392;
int NOTE_A4 = 440;
int NOTE_B4 = 494;
int NOTE_C5 = 523;


int NOTE_C5H = 524;
int NOTE_D5H = 588;
int NOTE_E5H = 660;
int NOTE_F5H = 698;
int NOTE_G5H = 784;
int NOTE_A5H = 880;
int NOTE_B5H = 988;
int NOTE_C6H = 1046;


void setup()
{
pinMode(buzzer, OUTPUT);


pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
pinMode(btn3, INPUT_PULLUP);
pinMode(btn4, INPUT_PULLUP);
pinMode(btn5, INPUT_PULLUP);
pinMode(btn6, INPUT_PULLUP);
pinMode(btn7, INPUT_PULLUP);
pinMode(btn8, INPUT_PULLUP);


pinMode(highBtn, INPUT_PULLUP);


display.setBrightness(7);
display.clear();
}


void loop()
{
bool highMode = (digitalRead(highBtn) == LOW);
int key = readKey();


if (key == 0)
{
noTone(buzzer);
lastKey = 0;


if (highMode)
showHI();
else
showPLAY();


return;
}


if (key != lastKey)
{
lastKey = key;
play(key, highMode);
}
}


int readKey()
{
if (digitalRead(btn1) == LOW) return 1;
if (digitalRead(btn2) == LOW) return 2;
if (digitalRead(btn3) == LOW) return 3;
if (digitalRead(btn4) == LOW) return 4;
if (digitalRead(btn5) == LOW) return 5;
if (digitalRead(btn6) == LOW) return 6;
if (digitalRead(btn7) == LOW) return 7;
if (digitalRead(btn8) == LOW) return 8;
return 0;
}


void play(int n, bool highMode)
{
if (!highMode)
{
if (n == 1) { showC(); tone(buzzer, NOTE_C4); }
if (n == 2) { showD(); tone(buzzer, NOTE_D4); }
if (n == 3) { showE(); tone(buzzer, NOTE_E4); }
if (n == 4) { showF(); tone(buzzer, NOTE_F4); }
if (n == 5) { showG(); tone(buzzer, NOTE_G4); }
if (n == 6) { showA(); tone(buzzer, NOTE_A4); }
if (n == 7) { showB(); tone(buzzer, NOTE_B4); }
if (n == 8) { showCH(); tone(buzzer, NOTE_C5); }
}
else
{
if (n == 1) { showC(); tone(buzzer, NOTE_C5H); }
if (n == 2) { showD(); tone(buzzer, NOTE_D5H); }
if (n == 3) { showE(); tone(buzzer, NOTE_E5H); }
if (n == 4) { showF(); tone(buzzer, NOTE_F5H); }
if (n == 5) { showG(); tone(buzzer, NOTE_G5H); }
if (n == 6) { showA(); tone(buzzer, NOTE_A5H); }
if (n == 7) { showB(); tone(buzzer, NOTE_B5H); }
if (n == 8) { showCH(); tone(buzzer, NOTE_C6H); }
}
}


void showC() { uint8_t s[4] = {0b00111001,0,0,0}; display.setSegments(s); }
void showD() { uint8_t s[4] = {0b01011110,0,0,0}; display.setSegments(s); }
void showE() { uint8_t s[4] = {0b01111001,0,0,0}; display.setSegments(s); }
void showF() { uint8_t s[4] = {0b01110001,0,0,0}; display.setSegments(s); }
void showG() { uint8_t s[4] = {0b00111101,0,0,0}; display.setSegments(s); }
void showA() { uint8_t s[4] = {0b01110111,0,0,0}; display.setSegments(s); }
void showB() { uint8_t s[4] = {0b01111100,0,0,0}; display.setSegments(s); }
void showCH() { uint8_t s[4] = {0b00111001,0b01110110,0,0}; display.setSegments(s); }


void showHI()
{
uint8_t s[4] = {0b01110110,0b00000110,0,0};
display.setSegments(s);
}


void showPLAY()
{
uint8_t s[4] = {
0b01110011,
0b00111000,
0b01110111,
0b01101110
};


display.setSegments(s);
}



This is the entire code for the circuit. First set variables to pin number and item, for example: int buzzer = 10;. THis means that the buzzer pin is pin 10 on the arduino, do that for all the pins/buttons. Then set the frequencies that the buzzer will play for each note. Since we are also using a higher octave, we need to set the higher octave frequencies too. Then use Input pullup for all buttons to ensure that no inputs are misread. Then display brightness to 7 for highest brightness. Then show play on the display until a button is pressed. If a button is pressed, then it will show the note being played instead of "PLAY". Then it will show the note being played on the screen with the code and for the display to understand you need to use binary to turn on and off segments. Finally the last 4 rows of binary are to show the word PLAY in binary. This is all the code for the circuit.


Credit for original code and inspiration HERE

Play and Enjoy

IMG_3134.JPG
IMG_3133.JPG
IMG_3131.JPG
IMG_3130.JPG

Now you can play and enjoy your own piano that you made

HELP Center/Works Cited