This in-class lab is designed to help you get some experience with the ultrasonic sensors, and to build a musical instrument called a theremin.
You'll need to use the NewPing library in order to make the ultrasonic sensors work. There are a few different versions out there; make sure that you use the version that is downloaded from our Moodle page. You'll find it in the references section at the bottom of our Moodle site, via a link titled "NewPing library: specialized version without timer conflicts". To install it, first follow the link to the NewPing library, which results in a zip file that you should download somewhere to your computer. Then, in the Arduino software, from the menu bar, select "Sketch -> Include Library -> Add .ZIP library." This will allow you to select the NewPing zip file that you downloaded.
This page on the Arduino NewPing library has some instructions on how to connect the ultrasonic sensors to the Arduino, and how to write code that uses them. Use the wiring diagram as a guide, but note that you don't actually need to use a breadboard: you can wire it directly to the pins on the Redback. For the code, look at the version titled "Simple NewPing Sketch."
When plugging in the ultrasonic, connect the VCC pin to any of the voltage pins on the Redback, the GND pin to any ground pin on the Redback, and then choose two digital pins: one for the Trig pin, and one for the Echo pin. You should then be able to use the sample code provided on the above-linked web page.
You should hopefully be able to get the ultrasonic sensor measuring distance to your hand or a book, and printing those distances to the serial monitor.
One challenge that sometimes happens is that the ultrasonic sensor can be noisy. It will sometimes sporadically show a nonsense value. One way to resolve this is to read five values in a row, you can use the ping_median method. (I haven't tested this, but try it!)
A theremin is a musical instrument which measures positions of your hands in space: one hand controls the frequency, the other controls the volume. Here are two different videos of a theremin being used:
https://www.youtube.com/watch?v=K6KbEnGnymk
https://www.youtube.com/watch?v=4kujH0ScAi0
Build an Arduino theremin, using two ultrasonic sensors and the toneAC library. We're using the toneAC library because it allows you to control volume. (toneAC allows you to use two pins for the speaker if you wish in order to get extra volume, but extra volume isn't something we really need. One pin is enough.) toneAC does restrict pin usage, you'll need to plug the speaker into pin 11 or 12. To install the toneAC library, visit this page:
https://bitbucket.org/teckel12/arduino-toneac/wiki/Home
There's a link partway down the page for downloading the library. To install it, follow the same instructions above as for installing the NewPing library.
Connect a beeper to the Arduino as we always have; choose pin 11 or 12, it doesn't matter which one.
The webpage describes how to use toneAC, as well as some sample code. Try out some code first where you change the volume with code you write.
If you can make the above work, connect two ultrasonics, where one should be used to control frequency, and the other to control volume. Do your best to arrange the two ultrasonic sensors to have some distance and point away from each other so they don't interfere.
Ask for help if you need it!