Project 6
Project 6
Assignment:01
1.Light Theremin.
Code:
int sensorValue;
// variable to calibrate low value
int sensorLow = 1023;
// variable to calibrate high value
int sensorHigh = 0;
// LED pin
0
const int ledPin = 13;
void setup() {
// Make the LED pin an output and turn it on
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
// calibrate for the first five seconds after program runs
while (millis() < 5000) {
// save the maximum sensor value
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
// save the minimum sensor value
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
//turn the LED off, signaling the end of the calibration
digitalWrite(ledPin, LOW);
}
void loop() {
//read the input from A0 and store it in a variable
sensorValue=analogRead(A0);
// map the sensor values to a wide range of pitches
int pitch=map(sensorValue, sensorLow, sensorHigh, 50, 4000);
// play the tone for 20 ms on pin 8
1
tone(8, pitch, 20);
// wait for 10ms
delay(10);
}
Summary
In this project we will make a “Light Theremin” which will work
producing a tone depending on the light perceived by the
microcontroller .
We will need a photoresistor (to detect the quantity of light), a piezo
(buzzer) and a 10kΩ resistor to perform our homemade theremin.
First of all, we will start describing the functionality of a buzzer. This
element is used to ring different tones depending on the intensity
received. It must be connected between ground and a digital or
analogical output which will provide the potential difference needed to
play sounds.
The buzzer will be connected as a digital output and the photoresistor
as an analog input. The photoresistor must be plugged in as an analog
input because it will translate the light received to numbers (different
than the states high/low).