Using an op amp as a voltage comparator

AKRichard:
. . .

One of your replies mentioned current limiting resistors to the transistors. I do not have them anywhere around the transistors. The relays are only pulling like 250 ms or so as they are just running the coils, do I need resistors? And do IIjust need them at the base (that's only taking like 5 volts). Or do I need them at the emitter of the second transistor that is receiving the 12 volts?

Yes, you need current limiting resistors on both of the transistor bases. You probably also need new transistors if you ran the circuit you've drawn without them.

Without knowing the characteristics of the relay, it's nominal current in particular, I've drawn a circuit with resistors below. This was done in the online circuit simulator at http://www.falstad.com/circuit/circuitjs.html which you might want to take a look at.

In this drawing the 40 Hz square wave represents the Arduino pin. The 270 Ohm resistor limits the NPN transistor base current and the Arduino pin current to about 16 mA1 to stay within the Arduino 20 mA spec. The 150 Ohm emitter limits the PNP base current to about 75 mA2 to prevent either of the transistors going up in smoke. The 50 Ohm resistor represents a relay with 250 mA current draw. The diode is flyback protection for the PNP transistor switching an inductive load.


1 - (5V - 0.7V base-emitter drop) / 270 Ohms = 16 ma
2 - (12V - 0.7V emitter-base - 0.2V collector-emitter saturation) / 150 Ohm = 75 mA, this may not be optimum for your particular relay.