Analog sensor value influenced by other variable

(it's just for testing, so don't expect any complete or optimized code)

That's not how you get problems solved. Please post a complete sketch showing the issue.

You wouldn't take a photo of a car like yours to the garage to be fixed, you take the car
with the problem that needs fixing.