![]() ![]() The tone function is used generating tone on the given frequency and to read more about the tone function read the guide here. We have scalarized to this range because values within these ranges are accepted by the analog pins of the Arduino.įurthermore, we have generated the sound of the scalarized values using the tone function. In the loop function we have first obtained the values of potentiometer using the analogRead() function and then to convert those values to frequency we have used the map function.īy using the map function, we have scalarized the values of the potentiometer having the range of 0 to 1023 to the range of 0 to 255. Next we have declared the variable for storing the values of potentiometer.Ĭoming to the setup function we have set the baud rate for communication and assigned the buzzer to operate in the output mode. To alter the sound of the buzzer using the potentiometer we have written the code in such a way that first we have assigned the Arduino pins for the potentiometer and the buzzer. Serial.print (frequency ) // displaying the frequencyĭelay ( 500 ) // time after which the loop function will start again ![]() Serial.print ( "Frequency of the buzzer: " ) Serial.println (POTValue ) // displaying the POT values Serial.print ( " \n Value of the potentiometer: " ) ![]() Tone (BUZZER,frequency ) /*using tone function to generate the tone of the frequency given by POT */ Int POTValue = analogRead (POT ) // read the input on analog pinįrequency=map (POTValue, 0, 1023, 0, 255 ) /* scalarizing the value of the potentiometer into PWM values */ PinMode (BUZZER, OUTPUT ) /*Assigning the buzzer the Output mode */ Serial.begin ( 9600 ) // initializing the serial communication Int frequency // variable for storing the frequency Int BUZZER = 7 // Arduino pin assigned to Buzzer Int POT = A3 // Arduino pin assigned to Potentiometer The Arduino code for controlling the buzzer sound frequency is given Arduino code for controlling the buzzer sound frequency by potentiometer To supply the voltage and grounding the components we have used the 5 volts and the ground pin of the Arduino Uno. Next the green wire connects the buzzer to the digital pin 4 of the Arduino and the output pin is connected with the analog pin A3 of the Arduino using the pink wire. We have connected the components in such a way that first we have placed the potentiometer and the buzzer on the breadboard. The image posted below is the hardware assembly diagram to further give a clear picture of the circuit connections: ![]() Hardware assembly for altering the buzzer sound frequency by potentiometer We have posted an image of the schematic of the circuit that controls the frequency of the buzzer: The components required for altering the frequency of the buzzer are: Since it’s an analog device its values range from 0 to 1023 so we have used it for varying the frequency of the buzzer. The potentiometer is an analog device which is used in the electrical circuits to alter the resistance of the circuit. How to control buzzer frequency using potentiometer with Arduino Uno In this guide, we have controlled the frequency of the buzzer with the help of potentiometer and Arduino Uno. There are a number of projects that can be created using Arduino Uno by interfacing different devices. Arduino Uno is the most common board used by high school and college students because of its simplicity and compatibility. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |