Need Help w/ Pulsing LED Strip Controlled by Analogue Input

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Need Help w/ Pulsing LED Strip Controlled by Analogue Input

Post by Withencroft »

Hi there,

Using an Arduino Uno. I am working on a project for my spouse's birthday and having a hard time. I am trying to make some lights turn on and pulse when the lights in the room dim or turn off. I have edited a code that works to make the lights the right color and pulse. Then I made another circuit to get input from the monitor to see what the photoresistor is picking up, and that gave me some numbers to work with. Then I followed someone else's tutorial for a nightlight setup, and got that to work with the numbers I found for the room, but only using a regular, classic style LED.

So my question is,

A. How do I go about taking my current set up and editing it for an LED strand,
and
B. How do I edit these code's to combine them?

Below are the codes that have been working for me, Attached is a picture of the circuit that works for the regular LED bulb. I am hoping to stay close to that circuit as I am a total newbie and I need to get this done by tomorrow night. The strip is a 5V strip with Ground, Power and DataIn cut to only use about 9 LEDs.

nightlight

Code: Select all

int led = 13;
int ldr = A0;

int value;

void setup() {

pinMode(led, OUTPUT);

pinMode(ldr, INPUT);

}

void loop() {

value = analogRead(ldr);

if (value < 500){

digitalWrite(led, HIGH);

}

else{

digitalWrite(led, LOW);

}

delay(100);

}
Teal Pulsing Light:

Code: Select all

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN         6
  
#define NUMPIXELS   60 

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  //#if defined (__AVR_ATtiny85__)
  //  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
 // #endif // defined __AVR_ATtiny85__

  // Initialize the library
  strip.begin();

  // Send updates to the strip
  strip.show();
  
  // Set color to teal
}

void loop() {
  // whatever number is here, divide by 2
  // that's about how long it should take for the loop to complete
  pulse(16);
}

// @param wait  the time to wait between the brightness updates (in milliseconds)
// @param color the color to pulse
void pulse(uint8_t wait) {
  fadeIn(wait);

  // uncomment this if you want it to stay bright for some time
  delay(5000);
  
  fadeOut(wait);

  // uncomment this if you want it to stay dim for some time
  delay(5000);
}

// When brightness is updated, not all pixels get the update sometimes
// This makes sure it does
void rerenderStrip(uint16_t accumulator) {
  for (uint16_t i = 0; i < strip.numPixels(); ++i) {
    strip.setPixelColor(i, strip.Color(0, accumulator & 255, accumulator & 255));
  }
  strip.show();
}


// @param wait  the time to wait between the brightness updates (in milliseconds)
void fadeIn(uint8_t wait) {
  for (uint16_t i = 0; i < 256; ++i) {
    // Rerender the full strip so to ensure all pixels are updated
    rerenderStrip(i);
    delay(wait);
  }
}


// @param wait  the time to wait between the brightness updates (in milliseconds)
void fadeOut(uint8_t wait) {
  for (uint16_t i = 255; i >= 0; --i) {
    // Rerender the full strip so to ensure all pixels are updated
    rerenderStrip(i);
    delay(wait);
  }
}
Thank you for your time and consideration.
Attachments
20220129_192356.jpg
20220129_192356.jpg (592.4 KiB) Viewed 1110 times

User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Withencroft »

Just feeling a bit overwhelmed and discouraged at the moment. Any input is appreciated.

User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Withencroft »

Update. After sort of combining the codes to this point, I don't have errors anymore, but the lights are not coming on when the sensor is activated (I can see the light on the board activating when I make it dark for the sensor) So I think maybe now it's the wiring or maybe a small issue in the code I am missing?

New code:

Code: Select all

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN         13
  
#define NUMPIXELS   60 

int ldr = A0;
int value;

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  //#if defined (__AVR_ATtiny85__)
  //  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
 // #endif // defined __AVR_ATtiny85__

  // Initialize the library
  strip.begin();

  // Send updates to the strip
  strip.show();
  
  // Set color to teal
}

void loop() {
  
value = analogRead(ldr);

if (value < 500){

(strip, HIGH);

}

else{

(strip, LOW);

}

delay(100);
  // whatever number is here, divide by 2
  // that's about how long it should take for the loop to complete
  pulse(16);
}

// @param wait  the time to wait between the brightness updates (in milliseconds)
// @param color the color to pulse
void pulse(uint8_t wait) {
  fadeIn(wait);

  // uncomment this if you want it to stay bright for some time
  delay(5000);
  
  fadeOut(wait);

  // uncomment this if you want it to stay dim for some time
  delay(5000);
}

// When brightness is updated, not all pixels get the update sometimes
// This makes sure it does
void rerenderStrip(uint16_t accumulator) {
  for (uint16_t i = 0; i < strip.numPixels(); ++i) {
    strip.setPixelColor(i, strip.Color(0, accumulator & 255, accumulator & 255));
  }
  strip.show();
}


// @param wait  the time to wait between the brightness updates (in milliseconds)
void fadeIn(uint8_t wait) {
  for (uint16_t i = 0; i < 256; ++i) {
    // Rerender the full strip so to ensure all pixels are updated
    rerenderStrip(i);
    delay(wait);
  }
}


// @param wait  the time to wait between the brightness updates (in milliseconds)
void fadeOut(uint8_t wait) {
  for (uint16_t i = 255; i >= 0; --i) {
    // Rerender the full strip so to ensure all pixels are updated
    rerenderStrip(i);
    delay(wait);
  }
}
Attached is a picture of the wiring as it is now. Like I said before I am a total beginner so I am mostly flying blind. Thanks again for any input anyone has.
Attachments
20220129_225237.jpg
20220129_225237.jpg (604.92 KiB) Viewed 1095 times

User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Withencroft »

Here is the original schematic that I followed. I just hooked up the negative and positive to where the anode and cathode of the LED were, and then the Din to pin 13 where the led was originally linked to... Maybe that will help make it clearer than my image of wires and stuff.
Attachments
Screenshot 2022-01-29 230146.png
Screenshot 2022-01-29 230146.png (473.1 KiB) Viewed 1094 times

User avatar
Franklin97355
 
Posts: 23903
Joined: Mon Apr 21, 2008 2:33 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Franklin97355 »

Try and test with an example code like strandtest after downloading the neopixel library.

User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Withencroft »

Okay, unhooked everything and ran the strand test, just to make sure the strip was still okay. It lit up as it should. Rewired up the circuit with the sensor, and uploaded strand test with the data pin set as 13 in the code and the strand did not light up. So I am assuming this means I've done something wrong with the wiring? Any thoughts? (The same circuit still works with a regular LED and the nightlight code) But when using strand test for code and this current circuit, it does not light up.

Thank you for your reply.

User avatar
Withencroft
 
Posts: 8
Joined: Sun Sep 26, 2021 9:21 pm

Re: Need Help w/ Pulsing LED Strip Controlled by Analogue In

Post by Withencroft »

Update. I have played with the circuit after realizing the strip was not getting enough direct power. However, the strip behaves erratically on strand test (is fine when it's plugged in alone, so its not broken). I am starting to think maybe the strip doesn't have enough power? I'm really throwing darts at a board here and hoping something sticks. I should probably be taking an in person class rather than trying to learn online.

Attached is a picture of the new layout/wiring.

Still very open to any input anyone has. Stopping for the day feeling defeated.
Attachments
20220130_012340.jpg
20220130_012340.jpg (587.12 KiB) Viewed 1081 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”