Connecting switch to unknown ADC input pin

Thread Starter

Kelvin Lee

Joined Oct 22, 2018
111
Dear Sir/Madam,

I have a Robot Arm with ADC input pin for external control but I don't have any specification information on hands. I only know the Robot Arm can be communication with the Arduino board without a problem.

I want to have a simple circuit to provide a 3.3V input to the ADC input pin. There are two circuits. May I know which one is a good practice if I don't want to waste any resource?

Screenshot 2019-02-14 at 9.27.17 PM.png

Circuit A: Directly connect a switch between a power source and the ADC input pin.

Circuit B: Adding a pull-up resistor to build the circuit and connect to the ADC input pin.

I only know the Arduino board can only provide 3.3V output to the Robot arm as an input voltage.

I heard some experienced engineer that many microcontrollers have internal pull-up resistor, hence an external resistor may be a waste of resources.

Other engineer says that directly connect to 3.3V is too dangerous as we don't know how much current will be flown into the microcontroller and too much current will damage the Robot Arm.

May I know which engineer's suggestion is correct? Could you help to select with explanation?

Best regards,

Kelvin.
 

djsfantasi

Joined Apr 11, 2010
7,756
Both...

The first engineer is definitely correct. But you do have to enable the internal pull-up resistor. And if you are detecting the presence or absence of 3.3V, a pull-up resistor won’t help. You need a pull-down resistor instead. And the Arduino doesn’t have that feature. Note that circuit B switches ground, not 3.3V.

In the second engineer’s comments, a resistor in series will protect the input. So he’s correct. But, directly connecting is done in practice. But in circuit A, a pull-down resistor is needed.

One other observation. In your example, you are connecting either ground or 3.3V to the input pin. In this case, you don’t need an ADC pin. A digital IO pin is all that’s necessary.
 

Thread Starter

Kelvin Lee

Joined Oct 22, 2018
111
One other observation. In your example, you are connecting either ground or 3.3V to the input pin. In this case, you don’t need an ADC pin. A digital IO pin is all that’s necessary.
Thanks djsfantasi, I only know the Robot Arm has the port ADC, PWM, 5V and GND. Should I connect the switch to ADC or PWM?

Regarding the pull-down resistor, why pull-down is a need rather than pull-up? Is pull-up or pull-down just to avoid floating voltage to the pin? Sorry I have limited knowledge in this area.

Best regards,

Kelvin.
 

djsfantasi

Joined Apr 11, 2010
7,756
Thanks djsfantasi, I only know the Robot Arm has the port ADC, PWM, 5V and GND. Should I connect the switch to ADC or PWM?

Regarding the pull-down resistor, why pull-down is a need rather than pull-up? Is pull-up or pull-down just to avoid floating voltage to the pin? Sorry I have limited knowledge in this area.

Best regards,

Kelvin.
Of the ports you listed, ADC appears to be the best choice.

When you connect a switch to a pin, if the switch is open then the pin input is “floating”. Floating inputs are “bad” because they can be interpreted as having any value. Hence, we use a pull-up or a pull-down resistor.

If you are switching the pin to the supply voltage or Vcc (I.e., one side of the switch connects to the Vcc and the other side connects to the pin) then if the switch is open, you want the pin to be at ground. To accomplish this, you connect the pin to the switch AND to a resistor to ground. A pull-down resistor.

If you are switching the pin to ground, then when it’s open you want the pin to be high. This is done with a pull-up resistor. It’s wired like I described in the last paragraph, except the other end of the resistor is connected to Vcc.

Basically, when the switch is connected to either ground or Vcc, then a resistor is required to connect the opposite polarity.

Some micros have internal pull-up resistors. The Arduino does, but even then it must be enabled in code. You’d have to check the documentation for your device. At the worst, a pull-up resistor won’t harm anything.

Update: What Raymond said.
 

Thread Starter

Kelvin Lee

Joined Oct 22, 2018
111
Of the ports you listed, ADC appears to be the best choice.

When you connect a switch to a pin, if the switch is open then the pin input is “floating”. Floating inputs are “bad” because they can be interpreted as having any value. Hence, we use a pull-up or a pull-down resistor.

If you are switching the pin to the supply voltage or Vcc (I.e., one side of the switch connects to the Vcc and the other side connects to the pin) then if the switch is open, you want the pin to be at ground. To accomplish this, you connect the pin to the switch AND to a resistor to ground. A pull-down resistor.

If you are switching the pin to ground, then when it’s open you want the pin to be high. This is done with a pull-up resistor. It’s wired like I described in the last paragraph, except the other end of the resistor is connected to Vcc.

Basically, when the switch is connected to either ground or Vcc, then a resistor is required to connect the opposite polarity.

Some micros have internal pull-up resistors. The Arduino does, but even then it must be enabled in code. You’d have to check the documentation for your device. At the worst, a pull-up resistor won’t harm anything.

Update: What Raymond said.
Thanks a lot. Does it mean I can either use pull-up or pull-down depending on what status of the PIN at the initial stage I want? I can code the Robot Arm to interpret the input and do some movement.
Curious, can you write sketches on the Arduino?

I mean you, personally.
I know how to write code on the Arduino, but this case I will solely use the circuit as input. I only said I know Arduino can work with this Robot Arm. Hope this information help to know more about the Robot Arm.
 

djsfantasi

Joined Apr 11, 2010
7,756
Thanks a lot. Does it mean I can either use pull-up or pull-down depending on what status of the PIN at the initial stage I want? I can code the Robot Arm to interpret the input and do some movement.

I know how to write code on the Arduino, but this case I will solely use the circuit as input. I only said I know Arduino can work with this Robot Arm. Hope this information help to know more about the Robot Arm.
Yes, you can either use a pull-up or pull-down resistor.
 

Thread Starter

Kelvin Lee

Joined Oct 22, 2018
111
Yes, you can either use a pull-up or pull-down resistor.
Thanks a lot, if I use the pull down resistor, although it ensure the initial stage of voltage as low, when I press the switch, will it same as the first circuit, directly connect the Vcc through the switch to the Robot Arm, any problem described from another engineer "directly connect to 3.3V is too dangerous as we don't know how much current will be flown into the microcontroller and too much current will damage the Robot Arm."?
 

djsfantasi

Joined Apr 11, 2010
7,756
Unfortunately, we are unable to check the documentation. This would tell us the current limitations of the current pin, what voltage is needed for the pin and possibly whether it is recommended to use a resistor. On the Arduino, you can safely connect Vcc to a GPIO pin directly. Sorry I couldn’t be of help here. Someone else may be able to answer.
 

Thread Starter

Kelvin Lee

Joined Oct 22, 2018
111
Unfortunately, we are unable to check the documentation. This would tell us the current limitations of the current pin, what voltage is needed for the pin and possibly whether it is recommended to use a resistor. On the Arduino, you can safely connect Vcc to a GPIO pin directly. Sorry I couldn’t be of help here. Someone else may be able to answer.
Understand too many unknown information, I only know Arduino works safe with this, so see whether we can take this as reference.

Regarding to the pull-up or pull-down, I am asking if we don't know how much current limitation to the pin but only know the voltage is 3.3V, then will pull-up is more safe then the pull-down because there is a resistor at pull-up to limit the current? Is it correct if I think at this way?
 

djsfantasi

Joined Apr 11, 2010
7,756
Not having documentation regarding your Robot Arm and specifically the ADC pin, your question cannot be answered.

An Arduino pin configured as an input can be directly connected to Vcc. That is because the pin already has a high resistance in its design (see this).

However, we don’t know if this is the case for your Robot Arm. It may not hurt to put a resistor in series with the input. But without specifics, you’d have to guess at a value.

Selecting a pull-up or pull-down resistor is more based on the input to the pin. If your switch leaves the input floating in one state and switches to ground, then you need a pull-ip. And vice vests. A resistance is chosen based on parameters you don’t have. I’d try something in the range of 2K to 4K. But again, these values are merely an educated guess.
 
Top