???? Sorry but no potentiometer is visable in Your post, no chematics, no datasheet link to the sensor.....
Thanks for posting formatted code in code tags!
Know that the UNO is a 5 volt logics device. I suspect the ESP32 is a 3.3 volt device. That opens up for mistakes and difficulties.