Banana switch (literally!), dies randomly

Here's the original post, where I described the general idea and got a pointer on how to go about it:,165622.0.html

Esentially I'm trying to switch something on and off using a banana (yeah, a real banana). The idea is to imitate the video in the original post, but without using a Makey Makey board and without any real complicated mail order parts setup. Now I've got a working prototype. Except for a bug I can't figure out.

So here's my solution and test setup:

The PNP collector goes to around 5V, when you touch the banana grounding it. Collector goes into the base of the NPN and makes it pass current. The NPN conducting makes the LED turn on which lets you know it's working. Works great. The PNP is pretty sensitive so you don't need to be touching the GND line to get it to work. Just standing on the ground shoes on or off and grabbing the banana, is enough. It has a little leakage, the LED glows very dim when you're not touching anything, I don't believe that's relevant (though if someone knows how to kill it, it's be great to know).

Now the second part. The NPN works as a switch for an Arduino digital input pin:

It's the same idea as using a pushbutton switch on the Arduino, only with the NPN transistor. The LED gets placed on another digital pin. Via software, I read the high or low signal on the input pin and light the LED when input pin is low (NPN conducting). The LED would get changed later on to a MIDI output to a synth.

Only I have the following problem: I start the Arduino. The whole setup works real nice for about 15 seconds. Then it dies. For example you grab the apple and hold on. The LED goes on, about 10 seconds later it shuts off. Then 20 or 30 seconds later it starts working again, same thing, 10 seconds later it dies. I've looked at the serial output, when it's working the output is what you'd expect (changes when you touch the apple), but all of a sudden it simply goes to a high state and stays there for a while, until it starts working again.

Arduino is powered via USB, transistors are powered from an external DC source. Both GND lines are tied together. There's no sign that I can see that might indicate a short or an overcurrent problem (normally when that happens either my AC adapter or the arduino shuts off, which isn't happening). Why 6V on the external source? It's what I had around. Could just as well be 5V through a 7805 regulator.

In case anyone's curious, here's the sketch I'm using:

So, my question on this forum is, anyone see a problem with the circuit? It works fine with the test LED setup (never dies on that first setup), I don't think it would be much different with the Arduino setup. I'm thinking it's a software problem, but I'd like to rule out circuit problems just in case.

Of course, if anyone sees where the problem with the code is, suggestions welcome too.

Maybe you're losing conductivity through chemical reaction or diminished connectivity.

Don't think so, if it were a problem with conductivity it would show up both in the test circuit as well as the arduino controlled circuit, but it only shows up with the arduino... :drooling_face:

Got it! After a few days of banging my head against the wall I decided to go back to basics, namely the example pushbutton sketch. Looking at it I noticed it was built around a switch that went to +5v when closed. So I built something similar, but around a 2N3906 PNP. The working circuit:

"Touch" contact goes to the vegetable of choice that you´re using as a switch. To operate it, use the pushbutton sketch included with the Arduino IDE. Don´t forget to change the LED pin from 13 to 12.

If I'd known it was that simple...