OK, I think I see the (a) problem with the transistor circuit. You have your transistor on the high side -- if you have an NPN transistor, or an N-channel MOSFET, you want your switching to be low-side. That is, the emitter or source of the transistor is connected to ground, the collector or drain connected to one side of the relay coil, and the other side of the relay coil connected straight to the positive supply. Also, it'd be great if you could say which hall sensor part number, and which transistor part number, and which relay (or at least what the voltage of the relay coil is, and what resistance the coil is). This way we can be sure that the parts are suitable for each other.
Hall 3144
Transistor 2n3904
5vDC relay SRD-05vdc-sl-c
That works perfectly. Thank you for your help. I come from automotive aftermarket, and we never do anything with transistors, so this is challenging.
Do I need a quenching diode to protect against the spike when the relay opens?
And do I just connect it between 85 and 86, or am I supposed to diode each leg in the appropriate direction?
You get spikes when opening circuits to an inductive load, because inductive loads "want" to maintain a constant current -- if you open a switch that's supplying that current, the inductor will spike with a huge voltage when its current is cut off suddenly. In the case of a relay, it's the coil that's inductive, not the switch side. So you may* want to connect a diode across the coil terminals "pointing away from the transistor".
* I don't know whether your relay coil has enough inductance for this to be an actual necessity -- other people might have nice general rules.
EDIT: Sorry, didn't read your earlier messages before. A diode doesn't help at all with the surge from an incandescent bulb turning on. It only helps with inductive loads, which a light bulb certainly is not. If you're using
this relay, you don't need to worry because your relay is rated for 7A; a 100W light bulb only consumes 1A steady (0.5A in countries with a proper mains voltage
) and nowhere near 7A surge. The only place you might need any attention is on the coil side, as I mention above.
Also, the relay requires 71.4 mA. This is fine for the 2n3904 to handle, but you do need to provide enough base current (which is controlled by your 10k resistor) for it to work well. From the datasheet, the current gain of the 2n3904 is only guaranteed to be at least 30 when collector current is upwards of 50 mA, so you want 71.4 mA / 30 = 2.38 mA base current. That means the resistor should be at most (5 - 0.7)V / 2.38 mA, so at most 1.8k (anything down to 1k is fine if you don't have a big selection to work with). You could use a N-channel mosfet instead of the transistor, in which case at 10k (or more) resistor would be fine, so your circuit would consume less standby power (for zero standby power, use a reed relay).