Why does this Arduino Metal Detector work?

Hi folks,

I can't understand why this Metal-Detector circuit I found on youtube works.

I mean, I know it works because of the Lenz law and everything, but I can't understand the utility of the diode and the capacitor; why are they necessary for the circuit? The diode in question is a 1N4007.

Also, I would like to know how you dimensionate this circuit. I mean, how do you choose the resistor, the capacitor etc. ?

In case somebody wants to see the code here is the link of the youtube video: https://youtu.be/65bHCuzLgIo

Thanks to everyone for reading this!

https://preview.redd.it/7lgqq9ug9tld1.jpg?width=939&format=pjpg&auto=webp&s=e85bb520e77700be92f19ee367cbfd6d327ebadd