Electronic – arduino – Triggering buttons with a diode

arduinobuttondiodesintegrated-circuit

total newbie here.
I was reading this post:
http://dduino.blogspot.com/2012/02/trigger-buttons-with-arduino.html

It is basically trying to trigger a button in an IC from an arduino(green) pin.

enter image description here

I understand how the second method works, it just bypasses the button from one side to the other using the transistor as a switch, although not sure what the resistor is for.
I am not sure if I understand how the first method works. I understand that the action gets triggered when the IC pin is connected to GND.

Now, I think that the arduino pin is connecting the diode to a pin as an Output Low( 0V? GND?) and that triggers the IC pin to GND so that the action gets taken.
To switch it off it sets the arduino pin to Input and it just works? How?

Will this work if the IC and the arduino are connected to different power sources?

Best Answer

The blogpost doesn't say what the IC is, but if it's a CMOS IC (a logic IC or a microcontroller) the pin needs a pull-up resistor. 100k\$\Omega\$ is a good value. If you don't place the resistor the input will be undefined when the switch is open. The resistor will make the input high.

First the transistor. A PNP transistor has two current flows: a small current from emitter to base and a (possible) larger current from emitter to collector. The emitter-collector current will normally be a multiple of the emitter-base current, but may be limited by external components. The current ratio is defined by the transistor's \$H_{FE}\$, which is often more than 100 for small signal transistors. So 1mA from emitter to base will allow 100mA from emitter to collector.

The emitter-base junction is actually a diode, and has the same voltage drop as a common diode at low currents, about 0.7V. So the base will be at 2.3V (3V - 0.7V). If you would connect the Arduino without the resistor and make its output low you have a problem. You would directly connect a point at 2.3V with another point at 0V which means a short circuit, and the high current may damage your Arduino and the transistor. By placing a resistor you limit the current. A 2200\$\Omega\$ resistor will limit it to about 1mA (2.3V / 2200\$\Omega\$ = 1mA). So a low output on the Arduino will allow minimum 100mA to flow to the collector. The input impedance of the IC will be very high, however, and the actual current will be limited to a few \$\mu\$A. Nevertheless, that's enough to make the collector's voltage close to the emitter, so near 3V, and the IC's input will be high. Note: just like the other schematic needs a pull-up resistor, this one needs a pull-down resistor to have a defined level when the switch is open.
If the transistor's base is high there won't be any base current, hence no collector current, and the pull-down resistor will pull the IC's input low. Note: I understand the Arduino operates at +5V, then making the output high will make the base 2V higher than the emitter. You normally don't want to do that, because the emitter-base junction can only survive a small reverse voltage. 2V will still be acceptable, though.

Then the diode. If the Arduino's output is high there is no voltage drop across the diode, so it won't conduct any current, and the pull-up will make the input high. If the Arduino's output is low there will flow current from +3V through the pull-up resistor and the diode to ground. The diode's anode will be about 0.7V above the cathode, so at 0.7V. Most logic ICs will see this as a low level.

The reason you need the diode: If you would directly connect the IC to the Arduino with the Arduino's output high, closing the switch would short-circuit the output to ground.