int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor int buzzerPin=8; int keyPin = 9; int frequency, oldfrequency = 0; boolean isOn = false; void setup() { // declare the ledPin as an OUTPUT: pinMode(ledPin, OUTPUT); pinMode(keyPin, INPUT); } void loop() { if (!digitalRead(keyPin)) { // read the value from the sensor: sensorValue = 0; for (int i=0; i<=9; i++) { sensorValue += analogRead(sensorPin); } frequency=(sensorValue/10) * 5 + 220; if (frequency != oldfrequency) { tone(buzzerPin, frequency); oldfrequency = frequency; } } else { noTone(buzzerPin); oldfrequency=0; } }