# RaspberryPi touch sensor using transistor

I built the following circuit. When I touch the rogue transistor base wire and GPIO is outputting, the LED lights up (still not quite sure why, so if someone could explain this, that'd be helpful, too.)

But now instead of the LED showing the state, I want to use a GPIO input to send it to the Pi. However when I replace base with GPIO.IN, the LED loses a lot of voltage, and thr GPIO only reads 0 (off). If you couldn't tell, I'm new to all this, so a bit more detail could prove helpful.

Your body is an antenna and when you touch the base of this transistor some amount of electricity is coupled into that input of the transistor. This transistor is setup as an "emitter follower" which means that it will attempt to keep the voltage at the emitter (Ve) at the same level as the voltage at the base (Vb).

So clearly you are raising Vb to a potential that is high enough to turn the LED ON.

Try a circuit like this to read the GPIO input when your transistor base is touched:

simulate this circuit – Schematic created using CircuitLab

The idea here is that when an input is present on the base of the transistor, it will turn the transistor ON. When that happens current flows in the collector which will pull the GPIO pin LOW. Keep in mind that the collector current, Ic, is the base current Ib times the hfe value of the transistor. For most small-signal transistors hfe is in the 100s or even 1000s. So you get a sizeable collector current with very little base current.

• That is already very helpful to understand, thanks! Concerning the rest of the question, do you know why the GPIO pin doesn't read the voltage. I could imagine the resistance increasing as the GPIO becomes the ground, but admittingly I don't know at all
– mdre
Feb 16 at 12:43
• GPIO read what voltage? It's not at all clear what else you are asking or what you are trying to do. Feb 16 at 12:51
• Currently the diode leads to a ground connection, from which I cannot read whether the base is touched ( / the LED is on). So I connected another GPIO Pin after the LED, instead of the Ground. However, the LED is dimmed and the GPIO in pin shows a LOW value..
– mdre
Feb 16 at 12:57
• that's because your circuit is not able to pull the GPIO pin (which I assume is setup for input) to a low enough voltage (i.e. Vil) that is will read a logic 0. Feb 16 at 13:15
• Okay, if I didn't misunderstand that, your saying the voltage arriving at the GPIO.IN pin is too low, no? So could I switch the 330 Ohm resistor for say 100 without hurting the LED since our resistance overall has increased?
– mdre
Feb 16 at 13:20