Dev 2 photoresistor ex 1: LED gradually turns bright when is under a shadow. Video
Dev 2 photoresistor ex 2: LED immediately turns on when is under a shadow. Video
Two-in-one-out device: With a photocell sensor and a button, when there is a bright environment, the button won't activate the LED; when there is a dark environment, pushing the button turns on the LED. Video 1. While the LED is on and shifting the environment from dark to bright, the LED will turn off. Then shifting from bright to dark, the LED will turn on again. Video 2
I wanted to make a lighting device that is meant to save energy. In that regard, the LED can only be activated when the environment is below certain brightness. To achieve that, I used a photocell sensor to detect the brightness and a button to turn the LED on and off. When the room dims, we can manually push the button to turn on the LED. If we activate the button beforehand, when the environment dims, the LED will automatically turn on. Conversely, while the button is activated, when the environment is getting bright, the LED will automatically turn off.
My initial intention is to push the button and the LED will keep being bright. So I added another integer to indicate the previous state of the button. I thought when the buttonState is LOW (button pushed), the lastButtonState equates to LOW, which failed to meet the first if statement so it won't change the LED state anymore until I pushed the button again. Yet, it turned out the code was not working. I still need to figure out the problem.
You can upload files of up to 20MB using this form.