Turn Environmental Light Conditions Into a LED Power Switch

This tutorial allows you to turn environmental data, in this case the amount of light in the setting you are working in, into an on/off switch for LED lights. This tutorial is a precursor to a more complicated setup that will be deployed for turning data gathered by a weather shield into conditions for selecting functions on a Raspberry Pi.

Tutorial Parts List:

  • Arduino UNO (1)
  • Breadboard (1)
  • Photo resistor (1)
  • Jumper wires (7)
  • 10k Ohm resistor (1)
  • 330 Ohm resistor (2)
  • Red LED (1)
  • Yellow LED (1)

Arduino Setup:

Let’s start by setting up the hardware on our Arduino board. Note: the short leg (the negative side) of the LED lights should be below the long leg (the positive side) in this setup. Use the following diagram to guide your setup:



You may also find the following circuit diagram helpful for your setup:



Once you have your board set up, it’s time to enter our code into Arduino. What we are looking to accomplish here is getting our Arduino to sense the level of light in the environment, and use that input to determine which LED light should turn on or off. This tutorial could be altered in many ways, you could use only one LED, and simply have that light turn on/off according to light level. You can also alter the level of brightness/darkness Arduino will use to determine whether the LED(s) should be turned on or off.


The following video illustrates what you should see when you are finished! I used a small keychain light to demonstrate the change of the LED lights under different light conditions. As mentioned earlier, you can alter the light level needed to switch the LEDs on/off in the code.


Leave a Reply

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