Assignment 6.3
Post date: Jul 26, 2010 7:12:3 PM
I just looked at edline and realized I forgot to do 6.3 from way back when... Obviously pretty late but it's better than nothing. I like using the photoresistor because it has a lot of interesting real world applications (my favorite probably being the one in my macbook that tells the keyboard to light up in the dark.) In as complete darkness as I could manage, the lowest value I could get from the resistor was around 190 and the highest was just under 400, so I set the "map" parameters accordingly. Also I'd be interested to know if they measure strictly from the visible spectrum, because my UV light seemed to have little effect on it.
ARDUINO CODE:
const int photo1 = 5; // select the input pin for the photoresistor
const int led1 = 13; // select the pin for the LED
void setup() {
pinMode(led1, OUTPUT); // declare led1 as an OUTPUT
Serial.begin(9600);
}
void loop() {
// read and map the value from the resistor
int val = map(analogRead(photo1), 180, 400, 0, 1023);
Serial.println(val, DEC); // print val to serial (for debugging purposes)
digitalWrite(led1, HIGH); // turn led1 on
delay(val); // delay for 'val' milliseconds
digitalWrite(led1, LOW); // turn led1 off
delay(val); // delay for 'val' milliseconds
}