Assignment #3

1) I wanted the LED to light up when the brightness was low and vice versa using the LDR. I had multiple ideas of how to build the circuit, but every-time I tried executing my idea I struggled with actually getting the plan to be successful. One thing I could do better next time is to actually sketch out my idea using diagrams. I looked at an Arduino tutorial to help clarify how I should set the circuit: https://www.youtube.com/watch?v=4fN1aJMH9mM. However, I wired it in a different manner that was more familiar to me.

2) I wanted to take one step further and work on fading the lights in and out instead of the lights abruptly changing every time it was dark and bright. I wanted the LED to vary in brightness depending on how dark the setting was. I implemented the code as seen below, however that only contributed to the dimming of the LED. I did not achieve the results I desired.

3) I learnt that the problem arose from the fact that the ledPin was at 7, which was not an analog output (PWM). Only when I switched it to a PWM would the LED fade. Adham helped me write my code more efficiently (ex. adding a map function instead of doing the analogRead under the loop function in the Example #2). However, even after writing the code efficiently and switching the ledPin two its proper location, the LED would brighten very subtly when it was dark. The change almost appeared non-existent. Only after switching around the values in the map function (by looking at the highest and lowest values from the serial monitor) was I able to see a difference in the fading of the light.

Leave a Reply

Your email address will not be published. Required fields are marked *