const int potPin = A0;    // Analog pin for potentiometer
const int buzzerPin = 9; // Digital pin for the simulated buzzer

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(potPin); // Read the potentiometer value
  int speed = map(sensorValue, 0, 1023, 1, 10); // Map potentiometer value to speed range (1 to 10)

  playSound(speed); // Play sound based on the speed value
  delay(100); // Delay for stability
}

void playSound(int speed) {
  int frequency = 0;

  // Define frequency based on speed value
  if (speed <= 45) {
    frequency = 1000;
  } else if (speed > 45 && speed <= 90) {
    frequency = 1500;
  } else if (speed >90) {
    frequency = 2000;
  }

  // Generate a tone with the specified frequency
  tone(buzzerPin, frequency);
  delay(500); // Play the tone for 500 milliseconds

  // Stop the tone
  noTone(buzzerPin);
}