Digital sound control

Hello there, I am trying to use my arduino to control how loud the sound is, the piezo makes. I tried using a potentiometer, but I didn't have any Idea, how to cennect it to the controller and the piezo. I tried controlling it using code. I also didn't know how to. I am trying to make the arduino be able to know, how loud the speaker is, because I want it to display it in Persent.

This is my hardware recreated in tinkercad, so its easier to see. I am trying to read out the bottom potentiometer and use it to control the loudess of the piezo. (I can change cabeling, if needed.)

PS.: I am not that good at english so please excuse errors

oh, your English is just fine, but knowing what it is you call your piezo would help and just a schematic of the Arduino and piezo connection would help.

1 Like

The code should be like this:

// Define the pins
const int potPin = A0;
const int buzzerPin = 8;

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Read the value from the potentiometer
  int potValue = analogRead(potPin);

  // Map the potentiometer value to a range for controlling the volume
  int volume = map(potValue, 0, 1023, 50, 255); // Adjust the range as needed

  // Output the volume value for debugging
  Serial.println(volume);

  // Generate a tone with the calculated volume on the buzzer pin
  tone(buzzerPin, 1000, volume); // Adjust the frequency (1000 Hz) as needed
}

For the hardware, I believe your circuit needs some resistors for the button and the piezo buzzer.

Nice part connection diagram but it is not a schematic and without the parts I have to look each one up. The writing is fuzzy at best. I do not have that amount of time. Putting it in the language of electronics, schematics, makes it much easier for us to follow.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.