Checking for 12 Volts

I need to look for 12v when a switch is pressed. In the schematic the H-12v is my sense line. I'm looking for a high on pin 2 of the Ardurino Mini. Could I get some feedback on this design and is this a good approach for solving the problem?

Thanks in advance.

I think that transistor is going to invert the signal. The pull-up resistor will keep Pin 2 high unless the transistor conducts. A high signal on the transistor base will cause the transistor to conduct and drag Pin 2 to Ground. HIGH on input == LOW on output.

You don't need R16, it does nothing useful. You can also omit R17 if you enable the internal pullup resistor in the microcontroller. I would increase R18 to 10K or more.

A simpler approach is to feed the +12V via a 100K resistor direct to the microcontroller input. The pin protection diode will protect the mcu, and the 100K resistor limits the input current to a safe value.

Are use a 7v zener to drop it to less than 5 but > 3, or a simple resistor voltage divider

Why not just use a 12V:5V voltage divider, 15K feeding into 10K.

oric_dan(333):
Why not just use a 12V:5V voltage divider, 15K feeding into 10K.

Ok so this will work?

thanks

The nice thing about that sucker is, the input pin isn't floating when the sensor is
not connected.

oric_dan(333):
The nice thing about that sucker is, the input pin isn't floating when the sensor is
not connected.

Oh I didn't know that. So I can eliminate the pull down?

kajmaya:
Ok so this will work?

Yes, but for better protection against transients on the 12V signal I would use higher value resistors, e.g. 100K and 68K.

So I can eliminate the pull down?

No, the pulldown is what keeps the input from floating, and also produces 5V to the pin.
As dc42 says, higher value Rs can be used, just keep the same ratio.

Read the part on figure 2,

oric_dan(333):

So I can eliminate the pull down?

No, the pulldown is what keeps the input from floating, and also produces 5V to the pin.
As dc42 says, higher value Rs can be used, just keep the same ratio.

Read the part on figure 2,

Voltage divider - Wikipedia

Yea, I just read my posted then slapped my self in the head. I need both resistors. Dumb on my part. I will go with the higher values.

Thanks

However, also see the following thread, in regards the R values getting too large,

http://arduino.cc/forum/index.php/topic,135169.0.html

dc42:
The pin protection diode will protect the mcu, and the 100K resistor limits the input current to a safe value.

ya know, I just dont trust those things

I just did a one off design to read optical switches @ 24 volts on a plc in parallel to arduino to pipe over USB to windows, and as much as I fought myself to trust the protection diodes, I ended up with 0.5 watt zeners and some fat resistors to limit everything down to about 1ma (ea * 8 channels) if all hell broke loose.

Simply based on the fact that no one can really nail down the numbers on them, and little glass diodes has to be more robust than a microscopic chip feature buried in epoxy

is this a good approach for solving the problem?

It matters a lot if you want to detect the presence of a voltage, or you want to detect the presence of 12v.

In the 1st case, the simplest would be to stuck a resistor (10k for example) between the H_12v line and your mcu pin.

This approach has its drawbacks: it doesn't sense a particular voltage and it is sensitive to interference. You can then use a pull-down resistor to alleviate that. a 47k pull down is fairly good but I typically use a 22k pull down. With that, it produces a 1->0 when the input voltage is less than 1v * (22k+10k)/22k and 0-> when the input voltage is greater than 4v * (22k + 10k) / 22k. So by adjusting the value of the 10k / 22k resistors, you can get it to trip at 12v.

Quote from: dc42 on December 01, 2012, 11:57:09 AM
The pin protection diode will protect the mcu, and the 100K resistor limits the input current to a safe value.

ya know, I just dont trust those things

I'm with you on this.

If the input is a known voltage, then a voltage divider as described works fine. If the
voltage can be about anything > 5V, within reason, a resistor [10K, 22K, etc] feeding
onto a zener diode is probably better. For something dangerous, like 120VAC, I'd go with
a properly designed optoisolator ckt.