Input voltage level

Shadow1976

New Member
Hi all,
I know that you can tie the input to a switch to 5v through a 1k and 10k resistor, but can you tie it to 12v using different resistors and if so what resistor can you use.
regards
steve
 

westaust55

Moderator
You can "tie" an input to a higher voltage using two resistors as a potential divider in a ratio that with the two resistors across 12Vdc that the node between the two resistors does not exceed 5 Vdc.

Are you trying to do analog/ADC measurements?
If not why "tie" or pull-up the input to 12 Volts?

As a potential divider you can use say a 6.8 kOhm as the top resistor to 12V and a 4.7 kOhm resistor for the low side to ground and connect the PICAXE input to the node between the two resistors. The PICAXE will have 4.9 Volts where the top of the potential divider is at 12Vdc.
 

AllyCat

Senior Member
Hi,

In practice, you can normally use a single high value resistor (perhaps 100k ohms+) to most PICaxe pins. This is because most pins have a "catching" diode from the pin to the supply rail (Vdd), to prevent the input voltage rising much higher (e.g. to protect against static electricity). There is much debate if this is a "safe" method (IMHO it is), so you could add an external diode ("pointing" away) from the pin to Vdd, to avoid arguments. A cheap diode (e.g. 1N4148) should be fine, but a "Schottky" type (which has a lower forward voltage drop) would ensure that the internal diode never conducts any current.

However, the "Input Only" pin on most PICaxes (Leg 4 with most M2s) does NOT have an internal diode (because the manufacturer can intentionally take it to a higher voltage to program the chip), so you MUST put the external diode on that pin.

Finally, beware that if the 12 volt rail is still present when you (try to) disconnect the PICaxe's Vdd supply, then current may flow through the catching diode and keep the chip powered (but not necessarily running properly). This can occur whether or not you use an external diode and even if you use a potential divider as suggested by Westy.

Cheers, Alan.
 

Goeytex

Senior Member
The attached diagram shows how to connect a 12V switch input to a Picaxe operating at 5V.

R1 is a pulldown resistor that keeps the input pin low when the switch is open. R2 is a current limit resistor that limits the input current to ~ 250 microamps @ 12V. Diode D1 is a Schottky type that clamps the voltage at the input pin to about 5.2V. The clamping will not be effective without the current limiting resistor. 47K is just a suggested value. Consider that the Picaxe programming circuit uses a 22K resistor and the internal ESD diodes to clamp +15 / -15 RS232 voltages with no ill effects.

While most Picaxe input pins have internal ESD clamping diodes, adding an external Schottky takes over the clamping duties from the internal diodes and protects any Picaxe pin that does not have internal ESD diodes.

Of course a voltage divider could be used as well. But the clamping circuit can be used with a wider range of input voltages without having to change resistor values.

Another way to use a 12 switch input is to use an OPTO isolator (such as a 4N25 or PC817) between the switch and the Picaxe. This completely isolates the 12v from the Picaxe.
 

Attachments

Last edited:

Axel87

Senior Member
The attached diagram shows how to connect a 12V switch input to a Picaxe operating at 5V.

R1 is a pulldown resistor that keeps the input pin low when the switch is open. R2 is a current limit resistor that limits the input current to ~ 250 microamps @ 12V. Diode D1 is a Schottky type that clamps the voltage at the input pin to about 5.2V. The clamping will not be effective without the current limiting resistor. 47K is just a suggested value. Consider that the Picaxe programming circuit uses a 22K resistor and the internal ESD diodes to clamp +15 / -15 RS232 voltages with no ill effects.

While most Picaxe input pins have internal ESD clamping diodes, adding an external Schottky takes over the clamping duties from the internal diodes and protects any Picaxe pin that does not have internal ESD diodes.

Of course a voltage divider could be used as well. But the clamping circuit can be used with a wider range of input voltages without having to change resistor values.

Another way to use a 12 switch input is to use an OPTO isolator (such as a 4N25 or PC817) between the switch and the Picaxe. This completely isolates the 12v from the Picaxe.
Would this circuit suffice for use with the Picaxe as well?
http://i773.photobucket.com/albums/yy17/touring-snowbird/MOTOR_OPTOCOUPLER_small.jpg

I notice in this circuit he uses a Hall sensor, could this be omitted?
 

Dippy

Moderator
That carefully drawn circuit could be simplified.
Do NOT simply remove the "Hall IC" and shove 12V across it!!!
An opto (4N3x) is just an LED and a phototransistor in a box.
The circuit is simple but I wouldn't use the one you linked to.
For clean 12V you just need a resistor to limit the current to that LED. Read Data Sheet.
If you read Opto-coupler Data Sheets and Application Notes they will give better example circuits.

You don't give us any details of the 12V source.... battery? clean PSU? or nasty old automotive?
If nasty and noisy you may need extra components for protection.
If nice and clean then a simple opto variant is fine or Geoytex's suggestion , variants of which are often used.
(Some background information can be obtained in Microchip's App Note AN521)
You didn't comment on or acknowledge his suggestion so is opto preferred? Why?

Please let us know your electronics skill level to help people explain things.
And give us a clue on the application as this will affect simplest designs.
 

Axel87

Senior Member
I do not want to hijack original posters thread, but I was intrigued with the idea of using an optocoupler.
For my application, it would be an automotive 12V source. So probably alot of noise.
The noise and isolation is why I was looking at using this idea.

The Datasheet I am viewing-
http://www.fairchildsemi.com/ds/4N/4N35M.pdf
Figure 11 is the circuit we need correct?
Please help me with figuring out the calculations?

My research, i found this formula for the current limiting resistor-
R = V - VLED / ILED
If(avg) =60mA

Is the Ic the minimum "turn on" current? (2mA)?
Would a small resistor (say 120 ohm) would as a value for RL?

Any help with these calculations or diagrams that anyone may have handy would be awsome!
Thanks
 
Top