‘Smart’ lighting with LEDs and Photocells — my first attempts at programming an Arduino
How have I never played around with hardware before? I’ve had some ideas in the past, but who has the time to sit down and learn electronics? They’re kind of complicated.
I had my first Arduino class about a week ago — two hours of learning that is outside of my wheel house. I have read some basic schematics and can tell the difference between a resistor and a capacitor but actually putting them to practical use and building circuits proved pretty tricky to wrap my head around quickly.
When I walked out of class, I had built my first circuit — a working LED. It was glorious. 3 days later and I sat down to rebuild it at home without instruction and I was perplexed, but I made my way back through it. Feeling a bit more confident, I set out to create 3 new projects in 1 week:
- Make an LED turn on when it’s dark and turns off when it’s bright
- Make an LED get bright when the environment gets bright (and a version that gets bright when the environment gets dark)
- Make an LED blink when the environment gets dark
I didn’t have a dedicated work space for doing this so I had to find a spare TV tray to go next to my desk — which might be its new permanent home.
This is how I got them all working.
Getting an LED setup on the Arduino board is pretty straight forward and adding in a Photocell for lighting detection is almost easier.
Setup the LED
Create a circuit from Pin 13 → Resistor → LED → to Power (and ground it).
The code to get the light to turn on is incredibly simple and included as an example in the Arduino IDE. A quick YouTube search and there are plenty of videos on how to get your LED to blink.
Setup the Photocell
With the photocell, you’re going to connect the Power → Resistor → Photocell → Ground and connect that to the Pin (0) so we can read what values the photocell is receiving.