Copy and paste the code below into a new Arduino sketch. Then, compile and upload it to your metro.
// CIRC09 - Light
int lightPin = A0;
int ledPin = 9;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int lightLevel = analogRead(lightPin);
lightLevel = map(lightLevel, 0, 700, 0, 255);
analogWrite(ledPin, lightLevel);
}
If you're having issues with the Photo Sensor: flip it around, chances are the orientation is backwards.
LED Remains Dark
This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist.
It Isn't Responding to Changes in Light.
Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place.
Page last edited January 22, 2025
Text editor powered by tinymce.