Plays tones based on a sensor reading
uses Tone library by Brett Hagman
http://code.google.com/p/arduino-tone/
circuit:
* photoresistor from +5V to analog in 0
* photoresistor from analog pin 0 to ground
* 8-ohm speaker on digital pin 8
created 10 Sep 2009
by Tom Igoe
*/
#include
Tone noiseMaker; // instance of the tone library
void setup() {
// start the music:
noiseMaker.begin(8);
}
void loop() {
// get a sensor reading:
int sensorReading = analogRead(0);
// map the results from the sensor reading's range
// to the desired pitch range:
int pitch = map(sensorReading, 50, 800, 100, 1000);
// change the pitch:
noiseMaker.play(pitch);
}
In this lab, the diagram shows the analog input as two photocells wired in series. I’m not sure I understand the analog readings produced as a result of this. For example, when both photocells were fully exposed to light the reading was about 200. When the right photocell was covered, the value jumped to 600-800. If only the left photocell was covered, it lowered the reading to about 50. If both were covered, the value leveled out around the same 200 as when they were both fully exposed. I’m not sure I understand the circuit and why these variable resisters were producing these values.
Fun with Tone Output
Arduino Code:
/*
Theremin
Plays tones based on a sensor reading
uses Tone library by Brett Hagman
http://code.google.com/p/arduino-tone/
circuit:
* photoresistor from +5V to analog in 0
* photoresistor from analog pin 0 to ground
* 8-ohm speaker on digital pin 8
created 10 Sep 2009
by Tom Igoe
*/
#include
Tone noiseMaker; // instance of the tone library
void setup() {
// start the music:
noiseMaker.begin(8);
}
void loop() {
// get a sensor reading:
int sensorReading = analogRead(0);
// map the results from the sensor reading's range
// to the desired pitch range:
int pitch = map(sensorReading, 50, 800, 100, 1000);
// change the pitch:
noiseMaker.play(pitch);
}
In this lab, the diagram shows the analog input as two photocells wired in series. I’m not sure I understand the analog readings produced as a result of this. For example, when both photocells were fully exposed to light the reading was about 200. When the right photocell was covered, the value jumped to 600-800. If only the left photocell was covered, it lowered the reading to about 50. If both were covered, the value leveled out around the same 200 as when they were both fully exposed. I’m not sure I understand the circuit and why these variable resisters were producing these values.