Pages: [1]   Go Down
Author Topic: Checking for 12 Volts  (Read 633 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8860
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Edison Member
*
Karma: 5
Posts: 1730
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Ok so this will work?



thanks
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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,

http://en.wikipedia.org/wiki/Voltage_divider
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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,

http://en.wikipedia.org/wiki/Voltage_divider


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
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 02, 2012, 03:13:39 am by Osgeld » Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: