From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Programming an LED that reacts to brightness

Solution: Programming an LED that reacts to brightness - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Solution: Programming an LED that reacts to brightness

- All right. Let's take a look at solving this challenge. First, I will connect one side of the photo sensor to power and the other side to analog zero. I will also attach one side of a 10k resistor to analog zero and the other side to ground. This resistor acts as an alternate path to ground. When the resistance of the photocell drops, electricity will flow freely. The resistor will fill up and the additional electricity will flow to analog zero. As resistance increases, the flow of electrons will slow until all of the energy can flow through the resistor. I used the calibration example as the beginning for my sketch. So that I can better see what's going on, I also added code to print a few things to the serial monitor. Lastly, I added a delay of one second to slow down the serial monitor. When I upload the code, I will cover and expose the photo sensor during the calibration phase. When I open the serial monitor, I see the constrained value is 255. When I place my hand over the…

Contents