Hello. I am working with ESP32 and LED strip WS2813. I have cut an LED strip and currently using just 6 LEDS
The function that I use:
I simply read the proximity sensor and turn on an LED when I detect a humand hand
When the sensor detects a hand:
when hand is no longer detected:
It works almost okay - I put my hand in front of the sensor and the LED strip lights in purple (the colour magenta that I have set). When I take hand away from the sensor, 95% of the time, the led strip will clear and turn off. The remaining 5% off the time, the LED will glitch and turn ON a random led random colour. Most of the time its either first LED or the last LED colour green or blue.
Is this expected behaviour from WS2813 LED strip? Is there any way to overcome this problem
The function that I use:
Code:
void Read_sensor(){
//IF ITEM ACTIVATED, SET GREEN LIGHT AND WAIT FOR PERSON TO TOGGLE THE DEVICE
if(number_to_pick>0){// LED TURNS GREEN IF WE NEED TO TAKE ITEM FROM THE BOX
digitalWrite(LED_GREEN,1);
}
sensor=digitalRead(SENSOR);//ALWAYS TAKE SENSOR READING EVERY 50MS
if(sensor==LOW && sensor_prev_state==HIGH){ // IF SENSOR IS TRIGGERED ON
sensor_prev_state=LOW; // set the previous state to LOW
Serial.print("sensor triggered\n"); // output serial monitor
if (number_to_pick==0){ // IF NUMBER TO PICK ITEMS IS 0, SET RED LIGHT TO SHOW OPERATOR WRONG BOX
digitalWrite(LED_RED,1); //if the sensor active flag is 0 (item not activated), set the RED light on to indicate the wrong selection
//tone(BUZZER, frequency);
pixels.fill(magenta, 0, 6);
pixels.show(); // Send the updated pixel colors to the hardware.
}
}
else if(sensor==HIGH && sensor_prev_state==LOW){ //sensor deactivated
if(number_to_pick > 0){ // if we still need to take items from this box after
char buffer2 [33];
digitalWrite(LED_GREEN,0); //turn off GREEN LED // set the green LED off and reset the flag
number_to_pick--;
item_inside.quantity--;
itoa (number_to_pick,buffer2,10);
client.publish(number_to_pick_topic, buffer2); // publish a message that the sensor has been triggered
create_JSON_object(); // publish item_inside topic to update quantity
//OLED_display(item_inside.quantity,number_to_pick);
Serial.print("number_to_pick=");
Serial.println(number_to_pick);
sensor_prev_state = HIGH;
delay(200);
if(number_to_pick==0){ // if we finished collecting items from this box, blink yellow LED to notify operator
client.publish(status_topic,"DONE");
client.publish(number_to_pick_topic,"0");// respond to topic that 0 items lef }
}
}
else{
sensor_prev_state = HIGH;
digitalWrite(LED_RED,0);
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
//noTone(BUZZER);
}
}
}
When the sensor detects a hand:
Code:
pixels.fill(magenta, 0, 6);
pixels.show(); // Send the updated pixel colors to the hardware.
Code:
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
It works almost okay - I put my hand in front of the sensor and the LED strip lights in purple (the colour magenta that I have set). When I take hand away from the sensor, 95% of the time, the led strip will clear and turn off. The remaining 5% off the time, the LED will glitch and turn ON a random led random colour. Most of the time its either first LED or the last LED colour green or blue.
Is this expected behaviour from WS2813 LED strip? Is there any way to overcome this problem