Inaccurate IR Sensor Reading

Fortunately, the issue has been solved. Apparently, there was an issue with the servo motor I was using. After replacing it with another one, following your suggestions to buy a separate 5V 2A adapter, and finally connecting its grounds both to Arduino and the adapter terminals, it worked fine. Thank you all for your help!