What does this LM393N circuit do?
The inverting input(pin 6) to the comparator is a voltage reference of 3V. This is what you are comparing the non-inverting input(pin 5) to. When the non-inverting input is greater than the inverting input, the output(pin 7) will be high.

Notice that there is a feedback resistor from the non-inverting input to the output. This is for hysteresis. It will keep the voltage at the non-inverting pin slightly higher when the output is high, and keep the voltage slightly lower when the output is low. This will prevent the output from toggling when both inputs are at very similar voltage levels.

This is basically what a schmitt trigger does.

It gives you a nice digital output for your microcontroller.

Bonus: There are two comparators on the LM393N. One is simply not used.