total newbie here. I was reading this post:

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?


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.

| improve this answer | |

In the second method, you're right, the transistor is simply acting as a switch. The resistor is (almost) required at the base (input) of a bipolar junction transistor like that one. A BJT is basically a current amplifier. You inject a small current into the base (through the resistor), and it allows a much larger current flow from the collector to the emitter. Too much current into the base will damage the transistor and the arduino.

The first method is more subtle. The switch has two states:

  • Closed. This pulls the IC pin strongly to ground.
  • Open. This lets the IC's internal resistor pull the pin gently to 5v.

Now, you could just connect the Arduino directly to the IC pin. The Arduino output has two states:

  • Low. It pulls strongly to ground.
  • High. It pulls strongly to 5v.

The problem comes if you press the button while the Arduino output is high. Now you have the button pulling strongly to ground, and the Arduino pulling strongly to 5v. This is a short circuit and will blow the Arduino's output pin.

The diode prevents this by changing the effect the Arduino has on the IC pin. Now you have:

  • Low. It pulls strongly to ground through the diode.
  • High. The high voltage is blocked by the diode, and the IC pin is pulled gently high by the IC's internal resistor.

If the button is pressed at the same time as the Arduino's pin is high, then the high short circuit current is blocked by the diode, and all is safe.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.