Hello. I welcome you to my last experiment before I publish final project. In this forum post I want to explain how you can determine LED strip length without knowing it’s length in advance.
Idea on this is not my own. I first time read about it here: A Nifty Tool For Counting Neopixels
It works in a way that you measured power consumption of LED strip. You hold most LEDs off except one. Idea is that you enable one LED at a time and test if power consumption grows or not.

For demonstration let’s consider 10th LED to be the selected one. You send bright white colour to 10th LED while remain others off. Then you measure power consumption of whole strip and compare it to idle state (all LEDs off). If it grows, it obviously must be caused by 10th LED present in chain and now emitting light with cause increase of power consumption. Now you know that strip is at least 10 LEDs long. If power consumption does not grow, there is no 10th LED on LED and you know your strip is shorter than 10 LEDs. Depending on this observation you try it again with higher or smaller LED index and sooner or later you find boundary when turning LED on increases power consumption while one LED later it does not. This is the length of LED strip.
It is more complex in strip with BI pin where you may hit possibly broken LED in the middle of chain. I will take this into account in final project, but for simplicity, I will omit it this time.
For measuring current, I used MAX40080 Click Board. It is the same Current Sense Amplifier which I used in Experimenting with Current Sense Amplifier back in 2022. If you are interesting for more detail details about it, you can follow my long series of blog posts which I wrote at that time. For my current experiments with LEDs, I ported my library to PSoC6 which I used for all experiments as far. I wrote slightly more robust error recovery, because I was hitting quite a lot of I2C errors.
Firmware is written in a way, that it measures idle current first. Then it compares to it. It is because of compensating quiescent current which flows even when all LEDs are off. I implemented slightly more efficient algorithm than was used in referred article. I do not go linearly over LEDs, instead I go over powers of two which allows me to find end of LED strip in O(log(n)) time instead of O(n). After finding end, using binary search, I find the exact boundary. Binary search is also O(log(n)) complexity.
For experimenting I did not implement super sophisticated output. After strip length is known, I print its value in binary using first LED on “input” chain. Red means binary zero, Green means binary one. On video bellow, you can see that my first testing strip has 4 LEDs and device blink RRRRRRGRR (R means Red or 0, G means Green or 1) which when converted back to decimal is 4. Then I tried with longer strip of WS2812 (not a Würth LEDs this time) and device determined strip as RRRRGRRRR, which is 16 and it is correct. This strip has 16 LEDs.
Next steps
Now I need to just complete my proposed project: tool for diagnosing strip. I want to implement automatic strip detection, not only length but also types of LEDs. Support strips with broken 48-bit LEDs and identify them. Technically it should be mostly combination of experiments which I already wrote about. I already started working on it and have good progress. Need to finish it and write blog post about it before deadline. Hope you enjoy reading this blog and find method to automatically determine strip length at least somehow interesting. See you in next blog post.
Link to final project post: RGB LED Strip Diagnostics Tool