In this video I show you how to make a mini piano with Arduino.
Devices and components
Arduino Uno Rev3
Jumper wires (generic)
Buzzer
Breadboard (generic)
12mm push button switch
Materials and tools
Soldering iron (generic)
Project description
Step 1: Parts and Hardware
Step 2: Connections
Step 3: The Code
Step 4: Play!
How the project works
arduino
The Code is attached
1//Arduino Piano
2/*
3
4Visit the Channel for more interesting projects
5
6https://www.youtube.com/channel/UCks-9JSnVb22dlqtMgPjrlg
7
8*/
9
10#define
11 T_C 262
12#define T_D 294
13#define T_E 330
14#define T_F 349
15#define T_G
16 392
17#define T_A 440
18#define T_B 493
19
20const int C = 10;
21const int
22 D = 9;
23const int E = 8;
24const int F = 7;
25const int G = 6;
26const int
27 A = 5;
28const int B = 4;
29
30const int Buzz = 11;
31const int LED = 13;
32
33void
34 setup()
35{
36 pinMode(LED, OUTPUT);
37 pinMode(C, INPUT);
38 digitalWrite(C,HIGH);
39
40
41 pinMode(D, INPUT);
42 digitalWrite(D,HIGH);
43
44 pinMode(E, INPUT);
45
46 digitalWrite(E,HIGH);
47
48 pinMode(F, INPUT);
49 digitalWrite(F,HIGH);
50
51
52 pinMode(G, INPUT);
53 digitalWrite(G,HIGH);
54
55 pinMode(A, INPUT);
56
57 digitalWrite(A,HIGH);
58
59 pinMode(B, INPUT);
60 digitalWrite(B,HIGH);
61
62
63 digitalWrite(LED,LOW);
64}
65
66void loop()
67{
68 while(digitalRead(C)
69 == LOW)
70 {
71 tone(Buzz,T_C);
72 digitalWrite(LED,HIGH);
73 }
74
75
76 while(digitalRead(D) == LOW)
77 {
78 tone(Buzz,T_D);
79 digitalWrite(LED,HIGH);
80
81 }
82
83 while(digitalRead(E) == LOW)
84 {
85 tone(Buzz,T_E);
86 digitalWrite(LED,HIGH);
87
88 }
89
90 while(digitalRead(F) == LOW)
91 {
92 tone(Buzz,T_F);
93 digitalWrite(LED,HIGH);
94
95 }
96
97 while(digitalRead(G) == LOW)
98 {
99 tone(Buzz,T_G);
100 digitalWrite(LED,HIGH);
101
102 }
103
104 while(digitalRead(A) == LOW)
105 {
106 tone(Buzz,T_A);
107 digitalWrite(LED,HIGH);
108
109 }
110
111 while(digitalRead(B) == LOW)
112 {
113 tone(Buzz,T_B);
114 digitalWrite(LED,HIGH);
115
116 }
117
118 noTone(Buzz);
119 digitalWrite(LED,LOW);
120
121}
122
123
Project submission
arduino
The Code is attached
1//Arduino Piano
2/*
3
4Visit the Channel for more interesting projects
5
6https://www.youtube.com/channel/UCks-9JSnVb22dlqtMgPjrlg
7
8*/
9
10#define T_C 262
11#define T_D 294
12#define T_E 330
13#define T_F 349
14#define T_G 392
15#define T_A 440
16#define T_B 493
17
18const int C = 10;
19const int D = 9;
20const int E = 8;
21const int F = 7;
22const int G = 6;
23const int A = 5;
24const int B = 4;
25
26const int Buzz = 11;
27const int LED = 13;
28
29void setup()
30{
31 pinMode(LED, OUTPUT);
32 pinMode(C, INPUT);
33 digitalWrite(C,HIGH);
34
35 pinMode(D, INPUT);
36 digitalWrite(D,HIGH);
37
38 pinMode(E, INPUT);
39 digitalWrite(E,HIGH);
40
41 pinMode(F, INPUT);
42 digitalWrite(F,HIGH);
43
44 pinMode(G, INPUT);
45 digitalWrite(G,HIGH);
46
47 pinMode(A, INPUT);
48 digitalWrite(A,HIGH);
49
50 pinMode(B, INPUT);
51 digitalWrite(B,HIGH);
52
53 digitalWrite(LED,LOW);
54}
55
56void loop()
57{
58 while(digitalRead(C) == LOW)
59 {
60 tone(Buzz,T_C);
61 digitalWrite(LED,HIGH);
62 }
63
64 while(digitalRead(D) == LOW)
65 {
66 tone(Buzz,T_D);
67 digitalWrite(LED,HIGH);
68 }
69
70 while(digitalRead(E) == LOW)
71 {
72 tone(Buzz,T_E);
73 digitalWrite(LED,HIGH);
74 }
75
76 while(digitalRead(F) == LOW)
77 {
78 tone(Buzz,T_F);
79 digitalWrite(LED,HIGH);
80 }
81
82 while(digitalRead(G) == LOW)
83 {
84 tone(Buzz,T_G);
85 digitalWrite(LED,HIGH);
86 }
87
88 while(digitalRead(A) == LOW)
89 {
90 tone(Buzz,T_A);
91 digitalWrite(LED,HIGH);
92 }
93
94 while(digitalRead(B) == LOW)
95 {
96 tone(Buzz,T_B);
97 digitalWrite(LED,HIGH);
98 }
99
100 noTone(Buzz);
101 digitalWrite(LED,LOW);
102
103}
104
105
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.