Hi. Why a microcontroller? With a comparator and a few components can solve this problem.
It's very easy and cheaper