Photocell and Piezo

Use a photoresistor(photocell) to create different tones with the piezo speaker.

what is a photoresistor? how does light affect it? Use the multimeter, measure resistance, see what happens in full light vs. darkness.

Refer to the Ladyada Tutorials, under Sensors, CDS Photocell: http://www.ladyada.net/learn/sensors/cds.html

Use analogRead(0) | can be any ANALOG IN pin, 0-5… | to read the Photocell, and use the Serial.print( ) function to print that reading to the serial monitor. The most simple code to do this follows:

/* Photocell simple testing sketch. Connect one end of the photocell to 5V, the other end to Analog 0. Then connect one end of a 10K resistor from Analog 0 to ground For more information see www.ladyada.net/learn/sensors/cds.html */

void setup() {

Serial.begin(9600); // We'll send debugging information via the Serial monitor

}

void loop() {

Serial.println(analogRead(0)); // print the raw analog reading

delay(1000);

}

What is the range of the photoresistor?

Use tone(pin, frequency) to generate a tone, the effective range here seems to be 0-8000, but experiment with different frequencies to find whih ones work best.

How can you store the value from the sensor? Use a variable.

Use if ( ) statement to set up conditions:

If ( Sensor < 10) { do something;}
If ( Sensor > 10) { do something else;}

How can we use this sensor to affect the output live(continuously)? You must be able to match the range of the photocell to the range of the tone function, so you may have to use simple math to adjust the variable accordingly. ie: if our tone range is 0-8000 and our sensor range is 0-1000, I need to take a reading from the photocell, multiply times 8, and then feed that variable into the tone function.