I have successfully made a mini piano with arduino uno r3 and sensor kit base and coding in arduino ide with chat gpt, connect the buzzer in the D5 of the shield, here the code:
//ARDUINO UNO ALPHASINTAURY SERIAL PIANO
#define BUZZER 5 // Collega il buzzer al pin 5 del kit di sensori Arduino
void setup() {
pinMode(BUZZER, OUTPUT);
Serial.begin(9600); // Inizializza la comunicazione seriale
}
void loop() {
if (Serial.available() > 0) {
char note = Serial.read();
playNote(getNoteFrequency(note), 500);
}
}
void playNote(int frequency, int duration) {
tone(BUZZER, frequency, duration);
delay(duration + 50);
noTone(BUZZER);
}
int getNoteFrequency(char note) {
switch (note) {
case 'c':
return 262;
case 'd':
return 294;
case 'e':
return 330;
case 'f':
return 349;
case 'g':
return 392;
case 'a':
return 440;
case 'b':
return 494;
case 'C':
return 523;
default:
return 0; // Nota non valida
}
}