## Opamp used as a threshold switch

Since VOUT=(Vp-Vn)∙A and A is infinite, it's easy to see that an opamp can be used as a threshold switch: if Vp>Vn then VOUT equals the positive source voltage; if Vp<Vn then VOUT equals the negative source voltage. Take a look at the picture below. Assume P1 is in the middle position. Let's call the top section P1a and the bottom section P1b. In the middle position P1a=P1b=5k => Vp=4.5V. If R1>R2, Vn<Vp and the lamp will be turned on. If R1<R2, Vn>Vp and the lamp will be turned off.

If R1 is a light dependent resistor (LDR), the circuit becomes a switch that turns the lamp on automatically when it gets dark. LDRs have a high resistance in the dark and a lower resistance when light shines on it. So in the dark Vn<Vp and the lamp will be turned on. At dawn, Vn will become greater than Vp and the lamp will be turned off. Use P1 to change the threshold.

But what will happen if Vn=Vp? In that case, the lamp might switch on and off rapidly. Fortunately we can prevent this by adding one resistor: Feedback resistor R3 makes Vp dependent on the state of the switch. Assume again that P1 is in the middle position. When the lamp is turned on, VOUT=9V, so R3 can be considered as parallel-connected to the top section of P1 (P1a): Vp=9V∙P1b/(P1b+[P1a//R3]) = 9V∙5k/(5k+[5k//10k]) = 5.4V. So the lamp will only be turned off when Vn>5.4V. In that case, VOUT=0V, so R3 can be considered as parallel-connected to P1b: Vp=9V∙[P1b//R3]/(P1a+[P1b//R3]) = 9V∙[5k//10k]/(5k+[5k//10k]) = 3.6V. So the lamp will only be turned on again when Vn<3.6V. The difference 5.4V-3.6V=1.8V is called the hysteresis.