Detect 12V from micro

Dec 29, 2005 17 Replies

I'd like to detect whether a line has 12V on it or not and read that into my micro. The 12V will be quite dirty (from a car). I was thinking of just using a transisitor, feeding the 12V into the base (via a resisitor) and using the collector to gnd the micro pin. Will this be enough isolation or should I use an opto isolator?



Thanks, Michael


Assuming you dont mean exactly 12v, an optocoupler is cheap enough and will keep your micro isolated. If you put a zener, say 10v, in series with the dropping resistor to the opto diode there will never be any false indications. Dont forget using a zener will affect the calculation of the limiting resistor.

Regards ......... Rheilly Phoull

that'd work, getting it to treat 8V as "not 12V" could be tricky, if that's not an issue that's probably the easiest way to isolate a single input.

Bye. Jasen

You need to clarify what are the thresholds for a good and bad 12v signal and weather you need hysteresis.

That's fine, I just need to detect if the ignition is on or off. If it's 6V or above then it can be considered on, if it's below that my boards not going to run anyway :-)

Just to be clear, you think it will provide enough isolation using a transisitor? And just using a resistor from the ignition to the transistor would be ok?

Thanks for the reply, Michael

This is just detecting if ignition is turned on in a car so thresholds are not too important, could be say 6V is considered on. Hysteresis is also not important because I'm just setting a timeout after which my device will switch off, if the signal jumps all over the place the countdown will just go back to zero. I'm more concerned about noise being a problem causing damage to the cpu or undesirable results.

Michael

Don't forget to enable the input-pullup in your micro (if it has one, if not, then provide one from the collector to the micro's supply). Put a filter cap across the base-emitter of your transistor.

I'd pick say 100k for the base resistor and 0.1ufd for the filter and 10k for the pullup.

Many micros have inbuilt clipping diodes on their I/O lines, so if you keep the input current low then you won't damage it.

Which micro are you using ?

yeah, something like a 1Meg or 10Meg resistor and an NPN transistor pulling the pin down. you could put a resistor between base and ground too, but it's probably not needed.

another way would be a 4.7V zener diode from the input to ground (assuming

5V VCC) and a 100K resistor to the 12V signal - any voltage that resistor can witstand isn't going to harm the input.

thses schemes will see anything less than about 2V as "off", if the signal if you need the threshold nearer 6v a zener in series with the resistor could help.

what are you using for your VCC supply?

Bye. Jasen

I'm using the phillips p89c668 which is an 8051 derivitive. It has internal pullups on some of the pins.

Michael

VCC is 5V from the standard 7805.

Michael

do you know what a "load dump" is?

it seems automotive electrics can be exttremely hostile... surges of upto 200V

Bye. Jasen

Opto method would seem the safest and less likely to zap the micro. JG

With micro's in general - keep all inputs within the data sheet specifications otherwise weard things can happen. JG

If product is long term..... allow for LED opto fading... JG

----------------------------

Assuming you dont mean exactly 12v, an optocoupler is cheap enough and will keep your micro isolated. If you put a zener, say 10v, in series with the dropping resistor to the opto diode there will never be any false indications. Dont forget using a zener will affect the calculation of the limiting resistor.

-- Regards ......... Rheilly Phoull

Not really but I'm guessing it's when a device puts power back into the system for some reason?

This I'm aware of which is why I asked the original question :-)

Michael

yeah, basicaly the alternator is running full tilt and then the battery goes open circuit for some reason... the regulator stops feeding the altenator field but typically the field still has to wind down on its own.

your 7805 won't like 200V very much. is there other protection before it?

Bye. Jasen

That bit I haven't done yet but was thinking of just using a few ohm resistor with a big cap. Sound ok?

Michael

maybe a 16V zener and a polyswitch?

Bye. Jasen

What is a polyswitch?

Michael

a type of reasonably fast acting self-resetting thermal fuse, but they don't go open circuit but more like a high resistance state

eg jaycar cat RN-3460

probably a bad idea also for the reason that temperatures in automobiles are somewhat unpredictable and often extreme

Bye. Jasen

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required