Hi There. I am trying to create an LED strip that lights up as you move closer and further away. I have taken the code from a video on you tube.
I am using a Elegoo Mega 2560 R3, an HC-SR04, and a WS2812B 5meter strip from BTF-lighting. in the diagram below the LED strip is powered off the breadboard where i have an external 5v 40A power supply connected, and there is a capacitor in line. the DATA to the LED strip is from PWN 6.
Sorry I have no idea why it would not work, and no idea how to get it to work so any advice would be helpful. I feel like i may just be missing something really simple.
Many thanks
#include <Adafruit_NeoPixel.h>
#include <HCSR04.h>
#define PIN 6 // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS 29 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
UltraSonicDistanceSensor distanceSensor(9, 10); // Initialize sensor that uses digital pins 9 and 10.
int current_Last_LED=0;
void setup()
{
pixels.begin();
}
void loop()
{
pixels.clear(); // Set all pixel colors to 'off'
current_Last_LED=distanceSensor.measureDistanceCm()*0.8;
for(int i=0; i<current_Last_LED; i++) // For each pixel in strip...
{
pixels.setPixelColor(i, 0,0,255);
}
pixels.show(); // Send the updated pixel colors to the hardware.
}
I mean it looks fairly simple when all the code is there and basically it seems hes provided everything but it just does not work.
do i need to enter any details into the code where he has "()"
yes. the GND of the power supply is in the breadboard and it comes off the BBoard into GND 1 and the HC-SR04 GND into the GND2 on the Elegoo. There are 2 GND PINS on the Elegoo.
it all looks like this.
again the button is the power supply, and the LED is the strip.
also the is a capacitor where the5v and GND come off the board into the strip.
#include <Adafruit_NeoPixel.h>
#include <HCSR04.h>
#define PIN 6 // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS 29 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
UltraSonicDistanceSensor distanceSensor(9, 10); // Initialize sensor that uses digital pins 9 and 10.
int current_Last_LED=0;
void setup()
{
pixels.begin(); pixels.
setPixelColor(i, 0,0,255);
pixels.show();
delay (300)
pixels.clear();
}
void loop()
{
}
sorry like i said i am new to this i dont know where to set the color or which pixels.
Got a lot to learn.