How to dim/brighten LED(WS2811) depending on brightness of room.

I want my LED(WS2811) to dim when the room is bright and [the led] to brighten up when the room is dark. (preferably a linear/smooth transition)

I smushed two builds together. One was how to make a photoresistor work and how to make a LED(WS2811*)* to work.

1)Arduino Elegoo (Arduino Uno but cheaper knock-off version.)
2)Breadboard (big and will post a photo)
3)jumper cables
4)100 microFarad capacitor
5)220 resistor
6)10k resistor
7)WS2811 LED lights (the 5v individual light controlled ones)

Pictures: (NOTE: Orange/Red wires are power, Yellow are data/analog, Black/White are ground)
Whole-

Analog side-

GND & data side-

Photoressitor circuit part-

LED connections-

Here is my code. I got rid of the things that I tried to make the lights dim or brighten depending on the values of the photoresistor. Also if you have feedback just note you have to talk in BABY words because I do not know how to code, I just know very basic concepts.
Also, I got my photoresistor code from this link: https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb
I got my LED sketch from FastLED library by Daniel Garcia, and this link: https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb

[code]#include <FastLED.h>
int value = analogRead(A0);

#define LED_PIN     13
#define NUM_LEDS    144
#define BRIGHTNESS  64

#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
 
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100





CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;


void setup() {
    Serial.begin(9600);//photorissitor part of code
    
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(   BRIGHTNESS   );
    
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;

    
}
void PhotoResistor()
{
  int value = analogRead(A0);
  Serial.println("Analog value : ");
  Serial.println(value/8);
  
  
  }

void loop()
{
    PhotoResistor();
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1 / UPDATES_PER_SECOND);

    
  
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; ++i) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}




void ChangePalettePeriodically()
{
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 10;
    
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand == 5)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND;  }
        
    }
}





// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,// 'white' is too bright compared to red and blue
    CRGB::Green,
    CRGB::Green,
    CRGB::Black,
    CRGB::Black,

    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,// 'white' is too bright compared to red and blue
    CRGB::Green,
    CRGB::Green,
    CRGB::Black,
    CRGB::Black,

   
};[code]

[/code]

Also, I forgot (sorry) thanks in advance for helping me and it means a lot, this is the first time using a forum of any kind, thank you!!

Karma point for properly posting code.

The second line of the code posted is spurious.

If you connect the LDR between an analog pin and ground, use pinMode of INPUT_PULLUP and you have an approximate 47k pullup already.

You need a test program to print the values to the serial monitor. When you know what the actual values are for the threshold of darkness and adequate illumination and you have used another test program to identify the appropriate "BRIGHTNESS" values for these conditions (presumably, you want to use 255 as the maximum :grinning: ), you can use a "map" function to translate the LDR reading to "BRIGHTNESS".

I do not know why you would have an "UPDATES_PER_SECOND" per second parameter. You only ever update addressable LED strings when you wish the pattern to change. No change in pattern, no update. The LEDs retain the data.

When using RGB and setting 1,0,0 the color of the light will be?

When using RGB and setting 10,0,0 the color of the light will be?

When using RGB and setting 100,0,0 the color of the light will be?

When using RGB and setting 200,0,0 the color of the light will be?

Perhaps it will be red but what will be the difference then?

Paul__B I really appreciate the advice, but just going to say this, im a middle schooler so I partially understood what you are saying. (really appreciate a follow-up to this)

So first you said the second line is not useful or correct. (totally didn't search up what it meant)

Then if I put the photoresistor between analog and ground I should use pinMode of INPUT_PULLUP and I have around 47k pullup already. Could you show me how to use it in my code? (if you don't mind could you also tell me exactly what it does in baby words because I searched up what it does and I sort of get it but would appreciate a further explanation.)

Also, I did make sure it worked the photoresistor, when I put my finger over it the serial thing displayed around 100 and when I took my finger off it displayed around 400. And yes the max brightness according to the code was 255. I divided that by like 8 because I thought the brightness level was 64)

Finally, how do I use the map function in my code?

I really appreciate your time for trying to help me, Thank you.

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