Issues with Millis function and sensors

Random behaviors come sometimes from power issues. How did you wire everything?

You are summing 6 values (index 2 to 7), your formula seems weird to calculate voltage