Welcome to the Tweaking4All community forums!
When participating, please keep theĀ Forum RulesĀ in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For exampleĀ “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post willĀ not bring you to the same post, in Dutch, as there is no translation for that post!
I used 2 digital pins for LED1 and LED2, instead of the Analog pins.
The meteor function is called 5 times with a for-loop in "void loop()".
Changed the analogPin and ledPIn1/2 to "#define" calls, so things take up less memory.
Reformatted the code a little for readability (always a good idea).
I optimized some code since you're using FastLED anyway ... 😊Ā
The code below had NOT been tested, so things may not work as hoped for, since I do not have the hardware handy ... 😊Ā
Let me know how it worked ...Ā
You stay healthy as well! 😉Ā
/* LDR triggered LED Strip with WS2812B and LED effect "Meteor Rain" (Tweaking4All) */
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#define NUM_LEDS 105
CRGB leds[NUM_LEDS];
#define PIN 6
// Used Define since that does not take up any memory
#define analogPin A0 // LDR pin
#define ledPin1 12 // digital pin that the green LED is attached to
#define ledPin2 13 // digital pin that the yellow LED is attached to
#define threshold 500 // an arbitrary threshold level that's in the range of the analog input
void setup() {
FastLED.addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
// initialize the LED pins for output:
// Note: I picked 2 digital pins for this (#12 and #13) instead of the analog pins you used!
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LDR an PIN A0
pinMode(analogPin, INPUT);
// Initialize serial monitor/port
Serial.begin(9600);
}
void loop() {
// read the value of the ldr:
int analogValue = analogRead(analogPin);
// Did something pass the LDR (= dark?)
if (analogValue < threshold) {
Serial.println("MARBLE PASSED LDR <------");
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
// run meteor rain 5x
for(int i; i<5; i++) {
meteorRain(0xff, 0xff, 0xff, 10, 50, true, 30);
}
} else {
Serial.println("LDR Did not detect anything");
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
}
delay(50); // delay in between reads for stability
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
for (int i = 0; i < NUM_LEDS + NUM_LEDS; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < NUM_LEDS; j++) {
if ((!meteorRandomDecay) || (random(10) > 5)) {
leds[j].fadeToBlackBy(meteorTrailDecay);
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ((i - j < NUM_LEDS) && (i - j >= 0)) {
leds[i - j] = CRGB(red, green, blue);
}
}
FastLED.show();
delay(SpeedDelay);
}
}
I'm not sure where the "=0" is supposed to be placed (I need more coffee to wake up haha). Would you mind posting the full code - this way others may benefit from it as well 😊Ā
It is an element in my fischertechnik marble track. The ball triggers the LDR which starts the sketch on the NANO. Then the Meteor Rain runs 5 times and the module is ready for the next triggering.
Sounds simple? Well, the devil is in the details!
First you have to calibrate the LDR. Depending on the light emission of the LED used and the surrounding light, the resistance of the LDR differs.
So it has to be checked with the serial monitor using an analog output. Depending on that the threshold has to be defined. In this case it is 850.
For the lightbeams I use LEDs between 10000 and 20000 mcd in red. They usually work sufficient.
The green LED indicates the Ready Status of the circuit, the orange one indicates triggering. So if something is wrong you know where to check.
When you load the sketch to the Arduino DISCONNECT the LED strip. Otherwise the Arduino tries to power the strip. With 105 LEDs the Arduino goes up in smoke!
Happy New Year!Ā 😮Ā
And put a 1000uF capacitator between VCC and GND of the powersupply. It protects the strip.
Additionally the resistor for the dataline of the strip is neccessary. The values differ between 330 and 470. Both should be fine.
I split up the strip to create an impact area of 20 LEDs. That meant A LOT of soldering but it was worth it! Be sure to solder VERY preciselly for the soldering points on the
WS2812 are very tiny and lots of short circuits are at hand 🤐Ā
The code is not too complex. Anyway, I needed HansĀ“ help. Again. Thank you Hans. You are the man! 👍Ā
/* LDR triggered LED Strip with WS2812B and LED effect "Meteor Rain" (Tweaking4All) */
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#define NUM_LEDS 105
CRGB leds[NUM_LEDS];
#define PIN 6
// Used Define since that does not take up any memory
#define analogPin A0 // LDR pin
#define ledPin1 12 // digital pin that the green LED is attached to
#define ledPin2 13 // digital pin that the yellow LED is attached to
#define threshold 850 // an arbitrary threshold level that's in the range of the analog input
void setup() {
FastLED.addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
// initialize the LED pins for output:
// Note: I picked 2 digital pins for this (#12 and #13) instead of the analog pins you used!
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LDR an PIN A0
pinMode(analogPin, INPUT);
// Initialize serial monitor/port
Serial.begin(9600);
}
void loop() {
// read the value of the ldr:
int analogValue = analogRead(analogPin);
// Did something pass the LDR (= dark?)
if (analogValue < threshold) {
Serial.println("MARBLE PASSED LDR <------");
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
// run meteor rain 5x
for(int i=0; i<5; i++) {
// meteorRain(0xff, 0xff, 0xff, 10, 50, true, 30);
// colour RED:
meteorRain(255, 48, 48, 10, 50, true, 30);
// hot pink
// meteorRain(255, 110, 180, 10, 50, true, 30);
}
} else {
Serial.println("LDR Did not detect anything");
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
}
delay(50); // delay in between reads for stability
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
for (int i = 0; i < NUM_LEDS + NUM_LEDS; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < NUM_LEDS; j++) {
if ((!meteorRandomDecay) || (random(10) > 5)) {
leds[j].fadeToBlackBy(meteorTrailDecay);
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ((i - j < NUM_LEDS) && (i - j >= 0)) {
leds[i - j] = CRGB(red, green, blue);
}
}
FastLED.show();
delay(SpeedDelay);
}
}
NAPS2 - Not Another PDF Scanner 2 Wonderful simple and reliable scanner application for Windows users. This still depends on your Windows having the proper scanner drivers installed, but it makes scanning to images or PDFs a lot easier.
CleverSubmitter Submits your website for indexing with a truckload of search engines.
RegExr Awesome website to play and experiment with regular expression!
AlternativeTo Great resource when you're looking for alternatives for an application that you'd like to use, but might not be available on your platform or the application you have is just not doing it right.
MalwareBytes Probably one of the best tools to prevent and remove all kinds of malware and viruses on Windows and MacOS X.
Put.io Online disk ruimte met Torrent mogelijkheden!
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
RenameMyTVSeries-2.3.16-Windows-x64-setup.exeDate: 2026-11-21 - Size: 124.3 MBRename My TV Series, for Windows (64 bit), a tool to assist in renaming TV Show episode files. This bundle comes with ffmpeg and ffprobe.
rename-my-tv-series-v2.3.16-macos.dmgDate: 2026-11-21 - Size: 129.2 MBRename My TV Series, for macOS (10.15+, universal binary), a tool to assist in renaming TV Show episode files. This bundle comes wth ffmpeg and ffprobe.
renamemytvseries-qt-2.3.16-1-x86-64.pkg.tar.zstDate: 2026-11-14 - Size: 2.2 MBRename My TV Series, for Linux (Qt5 Pacman package), a tool to assist in renaming TV Show episode files. Dependencies like ffmpeg and ffprobe are handled by the package manager.
renamemytvseries-qt-2.3.16-amd64.debDate: 2026-11-14 - Size: 2.3 MBRename My TV Series, for Linux (Qt5 Debian package), a tool to assist in renaming TV Show episode files. Dependencies like ffmpeg and ffprobe are handled by the package manager.
renamemytvseries-gtk-2.3.16-1-x86-64.pkg.tar.zstDate: 2026-11-14 - Size: 2.3 MBRename My TV Series, for Linux (GTK3 Pacman package), a tool to assist in renaming TV Show episode files. Dependencies like ffmpeg and ffprobe are handled by the package manager.
renamemytvseries-gtk-2.3.16-amd64.debDate: 2026-11-14 - Size: 2.4 MBRename My TV Series, for Linux (GTK3 Debian package), a tool to assist in renaming TV Show episode files. Dependencies like ffmpeg and ffprobe are handled by the package manager.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through theseĀ Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).