Intro: Use Comparator As Logic AND Gate
When you've got some comparators either already in your circuit or built into your MCU, there are some handy tricks you can use. The following will show you how you can use a comparator to make a Logic AND Gate.
Resistors 3 and 4 are used to bias the non inverting input while resistors 1 and 2 are used to average the two inputs.
Resistors 1 and 2 must be equal and resistor 4 must be selected to be twice the value of resistor 3. It is also recommended that resistors 3 and 4 are very large values as they will have a constant current draw through them and if a low resistance is chosen they can have a high power usage.
Both inputs will need to be Logic values (either High or Low) for this to work correctly. If you are running analog ranging values through this circuit it will go HIGH at 2/3 V+ rather than at V+ (due to selecting resistor 4 to be 2 times the value of resistor 3). You can obviously select resistors 3 and 4 to make this more accurate for analog signals, but it will never be perfect.
So now, if inputs 1 and 2 both go HIGH (V+), or higher than the input of the non-inverting pin, the output will go HIGH. If either of the inputs are not HIGH the output will stay LOW. You can also switch the pins of the comparator to create a NAND gate.