In experiment 3, you got to use a potentiometer, which varies resistance based on the twisting of a knob. In this circuit, you’ll be using a photoresistor, which changes resistance based on how much light the sensor receives. So it is sort of like a potentiometer controlled by light!
If you still have your multicolor LED hooked up:
Very cool. Keep that circuit and just add the photoresistor as shown below. Don’t add another LED.
In addition to the parts needed for your RGB LED, or plain LED you will need:
Again, if you have your RGB hooked up, leave it and ignore the LED in this diagram.
int sensor = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightLevel = analogRead(sensor);
Serial.println(lightLevel);
delay(1000);
}
This will display integers in the serial monitor denoting the brightness level. The possible range is 0 to 1023. Your numbers will like not reach either end of that range. Cover the photoresistor with your hand to make it totally dark and note the number. Use the flashlight app on your phone, shine it on the photoresistor and note that number. For example, my super bright, shining the flashlight app on the photoresistor was a bit over 800, and my totally dark number was around 20.
Make a device when the LED is off when it is dark out. As the light increases the LED gets brighter. This does not require an if
statement.
A device the reverse of the above. When it is bright in the room the LED is off. As the room dims, the LED brightens.
Can you make a device that when it is dark the rgb led is blue; as it gets brighter it turns to indigo; and as it gets bright still, violet.