Introduction: How to Use a Photocell to Change the Color of RGB LED

For my Arduino project part 01 my original idea was to use a temperature sensor to turn on and off an LED, but alas my temperature sensor hadn't come yet which left me to chose from the sensors available in the Elegoo starter kit, and wondering if maybe i hadn't forgotten to order my temp sensors in the first place.

With the new plan the idea is simple : Use a photocell to change the color of an LED.


  • 1 x Arduino Uno (or equivalent)
  • 1 x breadboard
  • 4 x resistors
  • 1 x RGB LED
  • 1 x Photocell
  • 7 x MM wires
  • USB cable

All Items used are found in the Elegoo super starter kit. Here

Step 1: Build Your Breadboard

First thing you'll need to do is build your breadboard, connecting the photocell to pins 5V and A5 as show above. When connecting the RGB LED you'll to connect each RGB to a pin and cathode to ground. In this case red to 6, green to 5, and blue to 3.

Step 2: The Code

As im new to this, I've merged code from multiple places in order to get the ending result. The most important steps within this code are defining the variables for the photocell , and each of the LED pin outputs. The original code sources come from multiple arduino tutorial files as well as this tutorial by Luca Mcloughlin found here.

Make sure before coding to test your photocell on its most basic functions to find your set value, for mine it was 1023. This is the value that will be used to change the color in your if, else statement. This is also important as this what tells your LED what it's reacting to. The code mashup I used is attached below

Step 3: Test

After coding you should test to make sure that everything is working properly. If done right the color of the LED should react to the change in light when an object or hand is placed on top or above it, switching from blue to red.