NeoPixels / LED strip + LDR + arduino

I am new to this so bear with me.

I am wanting to connect a sort of light strip system that can be connected to a LDR all powered by a DC power cord to a plug in to the wall, either NeoPixels or LED strips. I want to set up the light strip to be able to turn on as the room becomes dark and automatically turns off once the light comes back in the morning. I am designing a table with the lights inside of them in a boxed off area underneath with glass blocks, and an inch thick piece of wood over top with cutouts in the wood for the glass blocks to go, also where the LEDS will shine through. The design is a cube 27x27x27 inch with a 5 inch height in space to be able to fit the arduino, lights, and LDR. I am only needing to produce a yellow/white light, nothing crazy or really any other colors.

I am seeking any help or assistance on what I will need to do to connect the strip of lights to the LDR.

How to power the lights by a plug in the wall safely as well as not overheat.

The coding setup for both the lights and the LDR

Supplies that I will need besides Arduino, lights, LDR photoresistor.

Anything helps!!!!!!!!!!!!!!!!!! I feel like this is a pretty simple project I just do not know much about the exact design for the connection of the lights and LDR.

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!

What is LDR do you use?
Please provide the model number or link to the purchase.

I am not sure which kind I should use, do you have any you recommend. I want to be able to extend it through the top of the box and level with the top of the table so the sensor can be exposed to the outside light. I assumed that could be done via a wire or other sort of wire that can extend the LDR about a 8 inches away from the breadboard.

I had such a task only once - I used

See schematic and code examples there

LDR

I meant like one of these. I also would like to know if there is a way to extend that LDR to farther away from the board itself.

If you want just on and off control a run of the mill Light Dependent Resistor (LDR) would work. Extend it to where you want it with wires. Wire it to an analog input so that the threshold can be adjusted. Wire a 0.1uF cap between the input and ground to help to bypass noise picked up by the longer wires.

If you use a NeoPixel strip or a WS2812 type of strip then that can be directly controlled by an Arduino output, though it will need an external 5V supply. How much light do you need?

Then the program is simply, read the LDR, compare to the set threshold and control the strip accordingly.

yes, you can easily extend it with wires
The typical resistance of this type LDR is 20-100KOhms, so the resistance of wires doesn't matter

Here is a simple LDR controlling a WS2812 strip on and off depending on light level through an Uno. If you build the real deal, a Nano or Pro Mini would be a better choice due to size.

Simple code. Note that I use the internal pullup for the LDR load resistor to reduce part count. An external resistor can be used if the sensitivity can't be adjusted correctly by the threshold setting while using the internal resistor. Hysteresis added to prevent chatter around the threshold

// WS2812 on off with LDR by c goulding aka groundFungus
// ldr connects to A0 and ground.  LDR load resistor internal pullup
// WS2812 strip connects to pin 4 through 330Ω resistor
// WS2812 strip has 1000uF cap across its power input
// hysteresis added to prevent chatter around the threshold.

#include <FastLED.h>

#define NUM_LEDS 32

const byte DATA_PIN = 4;
const byte ldrPin = A0;

const int lightThreshold = 512;
const int hysteresis = 20;

CRGB leds[NUM_LEDS];
CRGB color = {255, 255, 0};

void setup()
{
   Serial.begin(115200);
   pinMode(ldrPin, INPUT_PULLUP);
   LEDS.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
   LEDS.setBrightness(120);
   setColor(CRGB::Black);  // turn all LEDs off
   FastLED.show();
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 200;
   if (millis() - timer >= interval)
   {
      timer = millis();
      int lightValue = analogRead(ldrPin);
      Serial.println(lightValue);
      if (lightValue > lightThreshold + hysteresis)
      {
         setColor(CRGB::White);
         FastLED.show();
      }
      else if (lightValue < lightThreshold - hysteresis)
      {
         setColor(CRGB::Black);
         FastLED.show();
      }
   }
}

void setColor(CRGB color)
{
   for (byte n = 0; n < NUM_LEDS; n++)
   {
      leds[n] = color;
   }
}

You will need a 5V supply that can safely handle the current required by the strip. To know that value, multiply the number of pixels in the strip by 60mA (0.06A). Then buy a supply with at least 20% more capacity. If it were me I would double it. I do not especially trust Chinese specifications.

You can refer to this project https://arduinogetstarted.com/tutorials/arduino-light-sensor-triggers-led
And replace LED in the above tutorial by a https://arduinogetstarted.com/tutorials/arduino-neopixel-led-strip

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.