You can use another analog device - a Light Dependent Resisitor (LDR) - to meausure how bright it is (light intensity). As you can probably guess from its name. the resistance of an LDR changes depending on how much light falls on it. By making a voltage divider with another resistor, you can measure a voltage that will change depending on how bright it is.
You can then use an array of LEDs to create a visual indicator of light intensity. As the light level increases, the number of LEDs that are on will also increase. Don't foget every LED needs a current-limiting resistor. To make building the circuit easier you can use a resistor array that has a number of resistors linked togther with a common pin.
const int analogPin = A0; // the pin that the LDR is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int barGraph[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached
void setup() {
// loop over the pin array and set them all to output:
for (int i = 0; i < ledCount; i++) {
pinMode(barGraph[i], OUTPUT);
}
}
void loop() {
// read the potentiometer:
int LDRReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(LDRReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int i = 0; i < ledCount; i++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (i < ledLevel) {
digitalWrite(barGraph[i], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(barGraph[i], LOW);
}
}
}