Hi all,
I tried to venture into new territory this week and explore photoresistors in hopes of making a smarter reading light.
I have been inspired by my summer challenge to read more, which I have found myself doing before bed. While I love relaxing with a book before falling asleep, I dislike that I have to get up to turn my lights/lamp off.
I realized quickly while experimenting that I knew nothing about photoresistors and thresholds, which was crucial to this piece of code. I researched and borrowed quite a bit, but still know only very little about thresholds and would like to know more!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
int lightPin = 0; int threshold = 550; void setup(){ Serial.begin(9600); pinMode(3, OUTPUT); } void loop(){ Serial.println(analogRead(lightPin)); if(analogRead(lightPin) > threshold ){ digitalWrite(3, LOW); Serial.println("high"); }else{ digitalWrite(3, HIGH); Serial.println("low"); } delay(100); } //*sourced/based off code from nakkaya.com |
Ideally this would be a lot more light than two LEDS, hence the name.
Thanks!