Instructables
  • Arduino
  • Sensor (A0 - A1)
  • Resistor (A0 - GND)
  • Cable (A1 - 5V)
  • Speaker (13 - GND)
 
Remove these adsRemove these ads by Signing Up

Step 1: Code

int entrada = A0;
int fuerza; int salida = 13; int frecuencia; float nota; int duracion = 10;
float DO = 130.81;
float RE = 146.83;
float MI = 164.81;
float SOL = 196.00;
float LA = 220.00;
float DO4 = 261.63;
float RE4 = 293.66;
float notas[] = { DO, RE, MI, SOL, LA, DO4, RE4, 0.00 };
void setup() {}
void loop() {
  fuerza = analogRead(entrada);
  if (fuerza > 10) {
    frecuencia = map(fuerza, 10, 400, 0, 7);
    nota = notas[frecuencia];
    tone(salida, nota, duracion);
  }
}
If you show a photo of the finished product in the first photo, you'll get more views!