Light Theremin
#Concept
A Theremin is an instrument developed 1920 by Leon Theremin that is being played without touch but through the position of the hands in relation to two antennas to controls the pitch and the volume. Watch Leon Theremin playing his own instrument.
In this exercise we want to build a “fake” theremin based on a light sensor (or LDR= light dependent resistor) and a piezo buzzer (sound module).
By moving your hands over this photoresistor you’ll change the amount of light that is getting detected by the sensor. This then will change the voltage on the analog pin and further controls the frequency note played by the piezo buzzer.
1 Place a piezo buzzer and one light sensor on your breadboard and connect the pins to your Arduino.
2 Open a new sketch and write your code.
- Use SerialBegin(9600); in the void setup() and SerialPrintln(sensorPin); in the void loop() to be able to read the incoming analog values of the light sensor.
- Void loop(): Read the sensor value with analogRead().
analogRead(pin);
- Introduce a new integer to store the value resulting from the map() function, which you use to map the incoming analog values to the frequencies in Hertz of the piezo buzzer. The Arduino can generate frequencies from 31 Hz up to 65.535 Hz.
int pitch= map(pin, fromLow, fromHigh, toLow, toHigh);
- use tone(pin, frequency, duration) function to play 8-bit sounds according to your mapping on your piezo buzzer. Update the pin of your piezo buzzer, the name of your mapped integer and decide on a tone duration in milliseconds.
tone (pin, pitch, duration);