Those chips usually have more than just digital/analog IO pins. Usually there is an analog reference pin, analog ground and analog vcc that needs to be connected in a certain way to make the analog sensing work correctly. This really is all explained in the atmega328p-pu datasheet. If you go barebones with a microcontroller circuit then you should read it, or at least the important sections.
Actually, you need to wire up AVcc and AGND even if you aren’t using the ADC; that entire port is powered from it.
At a minimum, you need to wire up Vcc, AVcc, GND, AGND and some bypass caps. If you are using the ADC, add a 100n cap from Aref to AGND. If you are using the crystal and caps or ceramic resonator, wire them up. Then wire up what you need for your circuit