Categories
TUTORIALS

Controlling an “Addressable” LED Strip with Any Sensor

In this tutorial, I will demonstrate how to control an Addressable LED Strip using any arduino sensor.  The examples I will show below will use a potentiometer and a photo cell.

Needed parts include:

  • An Arduino
  • A breadboard
  • An addressable LED strip
  • Any sensor
  • About 8 wires
  • External power supply (if using a long portion of the LED strip)

The board set up is as follows:

Keep in mind that you could replace the potentiometer with virtually any other sensor which returns an analog range of numeric values back to the arduino (light cell, distance sensor,  dust sensor, etc.)

Creating a “Moving Light”

Creating a moving light is easy, thanks to the FastLED library.  Copy and Paste the code below into a sketch:

Upload the code to your arduino, and viola! You can now control a traveling light on your LED strip with a potentiometer or any other sensor you may have chosen.

Next, let’s make the code a bit more complicated by transforming our traveling light into a traveling pack of lights. The more lights the better, everybody loves lights!

Harry’s Pal: “No! Harry, no! Don’t look at the light!”
Harry: “I can’t help it! It’s so beautiful!” [Gets electrocuted] “Waaaahooooo-ow!”

Creating a “Traveling Light Pack”

The code for creating a light pack is slightly more complex, and we will use for loops to decide the position of every pixel in the strip.  Copy the code below into your sketch:

 

Great! Now let’s add a little more bells and whistles to the code.

Controlling Colors

In this example, we will add an additional sensor, a button, to control the color of our lights.

Notice that I switched the potentiometer with a photo cell for kicks. For this more advanced set up, you will also need:

  • One 330 ohm resistor
  • One 10k ohm resistor
  • Photo cell (or any sensor that returns analog numeric values)
  • Button

The new wiring scheme is as follows:

 

Once you have your board wired correctly. Copy and paste this code into your sketch:

Your LED strip now reacts to light levels in the room (ironic??) and can switch colors at a touch of a button.

 

 

Thanks for reading!

3 replies on “Controlling an “Addressable” LED Strip with Any Sensor”

Hi, i try to make a simple game where a player must push a button rapidly to lighten up each led on a strip one after one… If the player slows down, the lights goes back to the first one (to win: light up the led strip until the last led)
Could you help me? Thanks.

Could you please send a wiring diagram for a capacitive sensor (like a metal plate) controlling an addressable LED strip? And the programm…

Leave a Reply

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