Hello All About Circuits forum
Have put together a simple circuit that operates
an LED strip, WS2812b using a microcontoller
XIAO SAMD21
SAMD21_to_WS2812b_schematic_250721.jpg

The sketch on the SAMD21 is
WS2812b_Fade_Color_to_Color_250722.ino
Would like to turn on the strip with
PIR (motion detector).
This is the schematic for a simple
PIR circuit.
This the sketch for the simple PIR circuit.
This is the schematic which adds the
PIR to the SAMD21 to WS28212b circuit

Combined the PIR logic with the
WS28212b code in sketch
PIR_to_SAMD21_to_WS28212b_250725.ino
The WS28212b code is
in a function runSAMD21() which is
called by void loop().
PIR_to_SAMD21_to_WS28212b_250725.ino
When the sketch is compiled the IDE
returns
Compilation error: 'leds' was not declared in this scope
at the line
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
Which is surprising because the sketch
WS2812b_Fade_Color_to_Color_250722.ino
has the same line and compiles ok.
It is surmised that 'leds' is found in
the FastLED.h library so does not have to be
defined in WS2812b_Fade_Color_to_Color_250722.ino
But the FastLED.h library is also called by
PIR_to_SAMD21_to_WS28212b_250725.ino
so why does the sketch
WS2812b_Fade_Color_to_Color_250722.ino
compile and the sketch
PIR_to_SAMD21_to_WS28212b_250725.ino
return a compilation error?
Thanks.
Allen Pitts
Have put together a simple circuit that operates
an LED strip, WS2812b using a microcontoller
XIAO SAMD21
SAMD21_to_WS2812b_schematic_250721.jpg

The sketch on the SAMD21 is
WS2812b_Fade_Color_to_Color_250722.ino
Code:
//from
//https://arduino.stackexchange.com/questions/13136/fading-colors-on-a-ws2812-strip
#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 299
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup(){
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop(){
// 256 steps to get from blue to red
// (the most possible with an LED with 8 bit RGB values)
for( int colorStep=0; colorStep<256; colorStep++ ) {
int r = colorStep; // Redness starts at zero and goes up to full
int b = 255-colorStep; // Blue starts at full and goes down to zero
int g = 0; // No green needed to go from blue to red
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
FastLED.show();
delay(10);
}
}
PIR (motion detector).
This is the schematic for a simple
PIR circuit.

This the sketch for the simple PIR circuit.
Code:
//from
//https://circuitdigest.com/microcontroller-projects/arduino-motion-detector-using-pir-sensor
// this sketch works with schematic /PIR_to_Arduino_250725/PIR_to_SAMD21_to_LED_250725.jpg
void setup() {
pinMode(2, INPUT); //Pin 2 as INPUT
pinMode(3, OUTPUT); //PIN 3 as OUTPUT
}
void loop() {
if (digitalRead(2) == HIGH)
{
digitalWrite(3, HIGH); // turn the LED
delay(1000); // wait for 100 msecond
digitalWrite(3, LOW); // turn the LED off
delay(100); // wait for 100 msecond
}
}
PIR to the SAMD21 to WS28212b circuit

Combined the PIR logic with the
WS28212b code in sketch
PIR_to_SAMD21_to_WS28212b_250725.ino
Code:
/* ************************************
PIR_to_SAMD21_to_WS28212b_250725.ino
combines
PIR sensor code from
PIR_to_Arduino_250725.ino
with PIR digitalRead code from
Staircase_Single_Channel_PIR_to_LED_220424.ino
with WS28212b code from
WS2812b_Fade_Color_to_Color_250722.ino
************************************ */
#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 30
#define COLOR_ORDER GRB
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
pinMode(2, INPUT); //Pin 2 as INPUT
}
void loop() {
if (digitalRead(2) == HIGH)
runSAMD21()
}
void runSAMD21(){
// 256 steps to get from blue to red
// (the most possible with an LED with 8 bit RGB values)
for( int colorStep=0; colorStep<256; colorStep++ ) {
int r = colorStep; // Redness starts at zero and goes up to full
int b = 255-colorStep; // Blue starts at full and goes down to zero
int g = 0; // No green needed to go from blue to red
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++){
leds[x] = CRGB(r,g,b);
}
// Display the colors we just set on the actual LEDs
FastLED.show();
delay(10);
}
}
in a function runSAMD21() which is
called by void loop().
PIR_to_SAMD21_to_WS28212b_250725.ino
When the sketch is compiled the IDE
returns
Compilation error: 'leds' was not declared in this scope
at the line
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
Which is surprising because the sketch
WS2812b_Fade_Color_to_Color_250722.ino
has the same line and compiles ok.
It is surmised that 'leds' is found in
the FastLED.h library so does not have to be
defined in WS2812b_Fade_Color_to_Color_250722.ino
But the FastLED.h library is also called by
PIR_to_SAMD21_to_WS28212b_250725.ino
so why does the sketch
WS2812b_Fade_Color_to_Color_250722.ino
compile and the sketch
PIR_to_SAMD21_to_WS28212b_250725.ino
return a compilation error?
Thanks.
Allen Pitts