Tuesday, May 30, 2017

LM393 Comparator

This post describes a test of a LM393 comparator.  This was my first soldered SMD (surface mount device).  I soldered once with some old flux using the sweep method (see for example https://www.youtube.com/watch?v=JKqgU2Hw3mY).  The comparator didn't work, so I started over with a new LM393 and simply soldered the pins carefully individually.  I used Sparkfun SOIC to DIP adaptors:  https://www.sparkfun.com/products/13655.


To test the comparator, I used the idea of a nightlight which turns on when a light sensitive resistor's resistance drops below a setpoint.  The setpoint can be adjusted with a potentiometer.  The circuit diagram is shown below.

The comparator compares the voltage at pins 2 and 3 and outputs a high on pin 1 if pin 3 exceeds pin 2.  If pin 2 exceeds pin 3, the output on pin 1 is low.  For example, if the LDR is at maximum resistance (in the dark), then V2 = 5V (6 Ohm / 16 Ohm) = 1.9V.  If the LDR is at minimum resistance (in bright light), then V2 is shorted to ground (0V).  Meanwhile, pin 3 may see a constant voltage of 1V (set by the pot).  So in the bright light, V3 > V2 and pin 1 is high so there is no voltage drop across the LED which stays off.  In the dark V2 > V3, pin 1 is low and the LED turns on.

The video linked below shows how the comparator works.  I really like this idea of using electronic components in place of a microprocessor.  It's a technique which may be dated, but is great to know.