Arduino Project 06 - Light Theremin
In this project I got to make some noise! To do so, the book breaks out the piezo, which is a kind of speaker that works using the piezoelectric effect. What is the piezoelectric effect, you ask—and who is Piezo? Well, the piezoelectric effect is where the application of an electric current through a special material causes a compression of the material; and piezo is just the Greek word meaning “to squeeze.” Inside a piezo is one of these special plates hooked up to wires such that when we run a current through the piezo, it causes the plate to deform, creating a sound wave. So by switching the current from on to off at a frequency of, say, 261.63 Hz (the frequency of a middle C on a piano), we can begin to make some music!
This project, however, calls for the use of a photoreceptor as a way of setting the frequency of the piezo. The finished result was a theremin-type device whereby waving your hand around the photoreceptor you would cause varying light levels to be read, thereby changing the frequency output by the piezo.
Again, with this project the Arduino IDE gives you a very friendly function, tone(), which isn’t available over in Rust world, where I am using the arduino_hal crate. However, once I saw an example, it actually wasn’t too hard to create a square wave at a certain frequency simply by toggling the pin between specifically timed delays.