I guess if the power wire is 5m the other signals have the same length. These signal wires shouldn't be more than 0.5-1m at most.
Why do you power the unit with 5V? That means the output signal also has 5V which damages the D1 mini, at least if it's treated so for a longer time frame.
Anyway, in your post I miss a complete wiring diagram. If I'm wrong and the hardware is correctly wired we need your code to look for errors there.