Table of Contents
Photo Blink
Here we add a photoresistor to the Blink circuit. We use this to sense the amount of light in the room, and adjust the blink rate – the darker the room, the faster the LED blinks.
Breadboard Layout
Code
- photo_blink.ino
const int ledPin = 3; // LED connected to pin 3 const int sensorPin = 0; // photoresistor on analog 0 // minimum and maximum blink rates const int minDuration = 100; const int maxDuration = 1000; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { int rate = analogRead(sensorPin); Serial.println(rate); // rate = map(rate, 0, 800, minDuration, maxDuration); digitalWrite(ledPin, HIGH); delay(rate); digitalWrite(ledPin, LOW); delay(rate); }
