This Circuit will introduce the Buzzer to our electronics toolkit and teach us how to effectively control its volume. A new programming concept called an 'array' is used in this circuit.

Transcript

Hey, Christian here from Core Electronics and today well be doing Project Set 2, Circuit 2A using the SparkFun Inventors Kit for Learning Arduino. So, Project Set 2 focuses on sound in Arduino and to accomplish this we are going to use a buzzer. As well as that we are going to be using LEDs, a potentiometer and we will be using a component called push buttons which will be explored in later circuits. So, with that said let’s get started.

So, the buzzer is a polarized component much like an LED which requires a high potential on one side and a lower potential on the other. So, we will plug the buzzer at J1 and J3 making sure that the side appears at the J1 connection we will connect the potentiometer like we have in our other videos with the flush face sitting towards the insulation strip in the middle. Now at this stage, we cannot that we are going to only use 2 pins of the potentiometer and this is because we not really care about the voltage divide property, we are only caring about the variable part of the resistor. So, from D1 we will connect to G3 which will put that in line with the negative terminal part of the buzzer. From G1 we will connect Pin 10, and from the centre pin from the potentiometer, we will connect that to ground.

Now we can plug in the red board and we will open the IDE, now note that it’s going to run the last program that was on there. So, we will go into the SIK circuit code, a side notes this code is available on our website in the getting started tutorials and we will see here that they have declared right at the start that the speaker pin is a pin 10. They have also declared that this Pin 10 is going to be an output and then there are going to go through this loop, it will go through once and then it will get to "while(true)" which is an infinite loop so that it only plays the code once, otherwise it would continue forever.

So, note here that there is the function called "play” now it is not an Arduino function it a function that plays a character and a beat. Now, this code introduces us to an array. Ones called Notes and the other frequency’s. Each note has its own frequency. So, we use current frequency to compare later in this for loop so that’s just an Int that is used for comparison. Beat length is the length of one beat and can be used to quicken or decrease the tempo of the music sound.

So here is the for loop. The for loop takes 3 arguments and will give a counter and range. So, we start at 0 and we go to "Num notes", num notes is 14 the length of this array and then it will give you an increment. So, we start at 0 and stop at 14 and increase by 1. So here we are matching the current note to the note that was read in and if that matches the frequency of the play it will make a tone.

So, with that said we can upload this code to the Red Board and we can use this potentiometer to change the value of the volume. So, now the red board is stuck at its while true loop, so it will only play once so we need to use the reset button and it will play.

So that is Circuit 2A from Arduino and we will get started on 2B on the next video.

SKU:KIT-14265 https://core-electronics.com.au/sparkfun-inventors-kit-v4-0.html
CAT: https://core-electronics.com.au/arduino.html

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.