My project: A RCWL-0516 sensor triggers a led strip which starts an animation, turns to solid light, and fade out after 30 seconds if no one is in the room. This works perfect without Blynk,
But with Blynk with controls for animation time, brightness, a menu for different animations and others there is a problem with turning on and turning off the leds. Sometimes they don’t turn off and sometimes they don’t turn on when they should. The function of the controls in Blynk works perfect, it’s just the on/off of the led that is the problem. It seems like it has something to do with the code doesn’t read the state of the sensor correct when Blynk code is added.
Is there someone who has had the same problems with Blynk and this sensor?
I can post the code but I thought I first could ask if this is a known problem.
Even if someone else has used this sensor with Blynk, they will be using different hardware, different Blynk widgets and data streams, and no doubt have made very different decisions regarding code structure, GPIO Pins etc.
If you want assistance with your specific issue then you’ll need to share your code, along with full details of your hardware, wiring, power sources, etc etc.
Pete.
Well, if this sensor was not recommended to use with Blynk I would have had many replies by now, so I suppose it’s some other problem.
My project:
Hardware
NodeMCU
RCWL-0516 microwave radar motion sensor
WS2811 12v led-strip, 36 leds
12v power adapter → WS2811 led strip and power converter
12v to 5v power converter → nodeMCU USB
node MCU Connections
RCWL out → D1
WS2811 din → D2
RCWL+ → 3V3
RCWL - → GND
WS2811 - → GND
Blynk widgets
Slider V0 - led brightness
Menu V1 - animation mode
Slider V2 - animation time
Slider V3 - on time (after animation)
zeRGBa V4 - end color
Button V5 - test
Code
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial
bool lastSensorState = false;
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <FastLED.h>
// ---------- WIFI ----------
char ssid[] = "";
char pass[] = "";
// ---------- PINS ----------
#define RCWL_PIN D1
#define LED_PIN D2
#define NUM_LEDS 12
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
CRGB leds[NUM_LEDS];
// ---------- TIMING ----------
unsigned long ANIMATION_TIME = 8000;
unsigned long ON_TIME = 30000;
const unsigned long FADE_TIME = 2000;
// ---------- BLYNK VARS ----------
uint8_t brightness = 150;
uint8_t animationMode = 0;
CRGB finalColor = CRGB(255, 80, 0);
// ---------- STATE ----------
bool ledState = false;
bool isAnimating = false;
bool isFading = false;
unsigned long animationStart = 0;
unsigned long lastMotionTime = 0;
unsigned long fadeStart = 0;
// ---------- TIMER ----------
BlynkTimer timer;
// ---------- BLYNK ----------
BLYNK_WRITE(V0) { brightness = param.asInt(); FastLED.setBrightness(brightness); }
BLYNK_WRITE(V1) { animationMode = param.asInt(); }
BLYNK_WRITE(V2) { ANIMATION_TIME = param.asInt() * 1000UL; }
BLYNK_WRITE(V3) { ON_TIME = param.asInt() * 1000UL; }
BLYNK_WRITE(V4) {
finalColor = CRGB(param[0].asInt(), param[1].asInt(), param[2].asInt());
}
BLYNK_WRITE(V5) {
if (param.asInt()) {
Serial.println("Test-knapp");
startAnimation();
}
}
// ---------- SETUP ----------
void setup() {
Serial.begin(115200);
pinMode(RCWL_PIN, INPUT);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
FastLED.clear(true);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Timer tasks
timer.setInterval(20L, readSensorTask);
timer.setInterval(20L, animationTask);
timer.setInterval(30L, fadeTask);
timer.setInterval(200L, timeoutTask);
Serial.println("System klart (BlynkTimer)");
}
// ---------- LOOP ----------
void loop() {
Blynk.run();
timer.run();
}
// ---------- SENSOR ----------
void readSensorTask() {
bool sensor = digitalRead(RCWL_PIN);
// Kun reager på LOW -> HIGH
if (sensor && !lastSensorState) {
// Hvis lyset er av → start animasjon
if (!ledState) {
Serial.println("Bevegelse → start animasjon");
startAnimation();
}
// Hvis lyset er på → forny timer
if (ledState) {
lastMotionTime = millis();
}
// Avbryt fade hvis aktiv
if (isFading) {
Serial.println("Bevegelse → avbryter fade");
isFading = false;
ledState = true;
lastMotionTime = millis();
}
}
lastSensorState = sensor;
}
// ---------- START ----------
void startAnimation() {
ledState = true;
isAnimating = true;
isFading = false;
animationStart = millis();
lastMotionTime = millis();
}
// ---------- ANIMASJON ----------
void animationTask() {
if (!isAnimating) return;
unsigned long elapsed = millis() - animationStart;
float progress = (float)elapsed / ANIMATION_TIME;
if (progress < 1.0) {
rainbowAnimation(progress);
} else {
isAnimating = false;
fill_solid(leds, NUM_LEDS, finalColor);
FastLED.show();
}
}
// ---------- TIMEOUT ----------
void timeoutTask() {
if (ledState && !isAnimating && !isFading) {
if (millis() - lastMotionTime > ON_TIME) {
Serial.println("Starter fade-out");
isFading = true;
fadeStart = millis();
}
}
}
// ---------- FADE ----------
void fadeTask() {
if (!isFading) return;
if (millis() - fadeStart < FADE_TIME) {
fadeToBlackBy(leds, NUM_LEDS, 15);
FastLED.show();
} else {
FastLED.clear(true);
ledState = false;
isFading = false;
Serial.println("LED av");
}
}
// ---------- ANIMASJON ----------
void rainbowAnimation(float progress) {
unsigned long t = millis() - animationStart;
if (progress < 0.7) {
uint8_t shift = t / 20;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(i * 255 / NUM_LEDS + shift, 255, 255);
}
} else {
float p = (progress - 0.7) / 0.3;
uint8_t shift = t / 20;
for (int i = 0; i < NUM_LEDS; i++) {
CRGB c = CHSV(i * 255 / NUM_LEDS + shift, 255, 255);
leds[i] = blend(c, finalColor, p * 255);
}
}
FastLED.show();
}
Thanks for answering.
I don’t know how I could miss that the sensor needed at last 4V, now I have connected + to the VU pin and everything is working fine 
But I can’t understand why it worked without Blynk though, it should have been the same problem… but I suppose we are not ment to understand everything in the world of electronics and coding…
Thank you again.
I assume that the WiFi of the ESP was disabled during your non-Blynk test. If that is correct, then it is quite possible that the 2.4 GHz radiation of the ESP WiFi was interfering with/saturating the input circuitry of the sensor receiver which was already marginally operating on an out of spec power supply.
You are right, there were no wifi connected when I tested without Blynk, and that could have made the sensor to cope with just 3.3v.