12 to 24V input

I want to be able to apply both 12 and 24VDC to an input pin though a switch.
I'm switching to ground/0V.

Using a couple of resistor as a voltage divider, I have the following questions:

  1. do I need a resistor between the Arduino pin and the voltage divider as well ?
  2. what is the input pin impedance ?
  3. and does pin impedance change if it is a selected as an input or output

Trying to keep the smoke in :slight_smile:

K

fiddler:
I want to be able to apply both 12 and 24VDC to an input pin though a switch.
I'm switching to ground/0V.

Not sure I understand the 'switching' part statement, can you post a drawing?

Using a couple of resistor as a voltage divider, I have the following questions:

  1. do I need a resistor between the Arduino pin and the voltage divider as well ?

No
2. what is the input pin impedance ?

An input pin is very high impedance, many megohms.

  1. and does pin impedance change if it is a selected as an input or output

Oh yea. Once pin is programmed to be a output pin, it becomes a active current source or sink, rated at up to 40ma absolute maximum. Be sure you never make a pin an output by mistake. The AVR chip cannot prevent damage from brain farts. Upon power up or reset condition all I/O pins are set to input mode. They only switch to output mode as a result of program code. :wink:

Trying to keep the smoke in :slight_smile:

And that is always a good rule to follow. :wink:

K

Okay, I haven't posted a pic or file before, but here we go

Note sure that circuit will work or not. Also your voltage divider uses equal size resistors, so it cuts voltage in half, so 24vdc = 12vdc, which is still higher then the maximum allowed input voltage to a input pin, +5.5vdc?

I would change the lower resistor size and then first measure the voltage that the arduino pin will see in each switch state with a digital multimeter before wiring it to arduino pin. Again the arduino pin must 'see' less then 5.5vdc to be safe.

Lefty

You need to divide the voltage down to the 0..5V range, thats a factor of 5, not 2

Okay

here are 2 schematics with one being from a control board we use at work (uses a Freescale chip, not AVR)
I have transfered it over for the Arduino board, but as said it has to be a factor of 5.

So, how come this other one works when there are essentially two 330K resistor in series between VDD and GND, which should give 6 to 12V on the chip pin when the switch is O/C ?

The "IN 0-7" connector goes straight to the chip pin
CN8 connect to the outside world. Input is ON the switched to GND
VDD is 12-24VDC

K

So, how come this other one works when there are essentially two 330K resistor in series between VDD and GND, which should give 6 to 12V on the chip pin when the switch is O/C ?

Possibly the are relying on the fact that very little current can flow through a 330k resistor even though the applied voltage is too high and will cause the pins internal clamping protection diode to turn on?
There is even an example given by the Atmel (or was it PIC) showing a direct input pin connection to 120vac, but applied through a high enough series resistor to limit the current such that there is no damage to the input pin. Most people would rather just limit the maximum voltage applied to a input pin to the datasheet maximum allowed voltage, but certainly if you wish to experiment with using high enough series resistance (like the values used in your divider) you may find it works fine for you.

Lefty