Wiring a photoresistor to an analog input pin
Now, we will use a photoresistor, that is, a light sensor, specifically, an electronic component that provides a variable resistor that changes the resistor value based on the incident light intensity. As the incident light intensity increases, the resistance of the photoresistor decreases, and vice versa.
Tip
A photoresistor is also known as an LDR (short for Light-Dependent Resistor) or photocell. Bear in mind that pohotoresistors are not the best components to sense light with great accuracy. However, they are extremely useful to easily determine whether we are in a dark environment when we don't have problems with latencies that can reach one second.
We cannot measure a resistance value with our board. However, we can read voltage values, and therefore, we will use a voltage divider configuration that will include the photoresistor as one of its two resistors. The voltage divider will output a high voltage value when the photoresistor receives...