Project Set 2 – Sound
Welcome to the second Project Set from the Sparkfun Inventors Kit V4.0 Guide! In our last Project Set, we explored the basics of the Arduino IDE, some electrical and electronic concepts and looked at various electrical components such as LED’s, Potentiometers and Photoresistors. In this Project Set, we will explore the area of sound through the use of a Buzzer (Piezoelectric Speaker), Push-Buttons and some interesting new functions for control. I highly recommend downloading the Sparkfun Code if you haven’t already as the program code for the Circuits in this set is quite tedious.
A Buzzer Breakdown
The Buzzer included in the Sparkfun Inventors Kit is a Piezoelectric speaker. This means it utilises the Piezoelectric effect to produce vibrations, which we hear as sound. Changing the current through the Speaker changes the volume of the output; a higher resistance results in a lower volume. In this Project Set, we will use a Potentiometer to control the series resistance.
The Sparkfun Code uses a function called play() which reads in a note and a duration before using the tone() function to play it. The tone() function is used to write a PWM signal (discussed in the previous Project Set) to the Buzzer’s input pin which will control the frequency (or pitch) that is produced by the Buzzer.
Project 2 - Circuit 2A
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. An array is a 1-dimensional matrix that stores a list of values of the same datatype. Following along with the Sparkfun code for this Circuit will allow us to understand how arrays are declared and accessed. We are also introduced to a 'for loop' for the first time. A 'for loop' is a good way of counting through an array and is often used for sorting or scrolling. A lower bound is set, an upper bound is set and then an increment and direction of cycling are decided upon. They will be revisited in circuit 2C to control numerous LED's that have their pins stored in an array.
Important notes:
- Disconnect the RedBoard from the computer before connecting anything to the Power Bus
- Make sure that the Buzzer is connected with the correct polarity
- Ensure the middle pin and one side pin are used through the potentiometer such that an actual connection exists.
Project 2 - Circuit 2B
This Circuit expands on the Buzzers versatility by introducing Push-Buttons to control when notes are played. A Push-Button is a mechanical switch that allows for current to flow across its terminals when it's physically pressed in. Buttons aren't polarised however they are connected such that they require a resistor to stop a direct connection of power to GND. This resistor will be in the form of a pull-up resistor, a digitally programmed resistor that is connected to the output pin and +5V.
A pull-up resistor is designated in the pinMode() function when declaring a pin's operating mode. Its declaration looks like this:
Since the resistor is a pull-UP resistor to +5V and not a pull-DOWN resistor to GND, we must check for the digital pin it is connected to to go to a LOW state. This is done by means of digitalRead() in an if statement. The pull-up resistor is useful because it lessens the number of components (such as wires and resistors) required to build the Circuit than if we assembled it using a normal 'INPUT' configuration.
Important notes:
- Disconnect the RedBoard from the computer before connecting anything to the Power Bus
- Make sure that INPUT_PULLUP is selected as the pinMode for the Push-Button such that a direct +5V to ground connection isn't made
- Make sure the Buzzer is connected with the correct polarity
Project 2 - Circuit 2C
Similarly to the last Circuit of the first Project Set, this final Circuit will include a little bit of everything from Project Set 2 and will also incorporate the use of some LED's to play a game. The Circuit will also introduce the millis() function which is useful for timekeeping and time comparison. The other new introductions are Boolean Variables (true and false) as well as the randomSeed() function to allow a 'reshuffle' element for the memory game. Whilst not truly random it's obscure enough for the purposes of this game.
Important notes:
- Disconnect the RedBoard from the computer before connecting anything to the Power Bus
- Make sure that INPUT_PULLUP is selected as the pinMode for the Push-Button such that a direct +5V to ground connection isn't made
- Make sure the Buzzer is connected with the correct polarity
Congratulations! You have now completed Project Set 2 and are onto the next stage in the Sparkfun Inventors Kit. Project Set 3 explores the use of Servo Motors and Ultrasonic Rangefinders, two useful components for producing and measuring movement in an electronics environment. Project Set 1 introduced light into our Arduino Projects through the use of LEDs and is worth reviewing before the next tutorial set.