Trouble using cap sensor to light LEDs

Hi all,

I'm new to arduino but I decided its time to jump in and start my first real project. Eventually I'm going to want to incorporate cap sensors into this project so I figured it wasn't a bad place to start. I was able to find the cap sense library here:

I can see on the serial monitor that the switches are being properly recognized but when I try to use the data to light an LED it is very dim. If I drive the LED instead with an npn transistor I get the brightness I want. I therefore assume that my Arduino doesn't have the driving capability to use the cap sensors and light an LED at the same time. Is this something I'm going to have to accept and add the transistor circuit or am I missing something? I realize its not a big deal to add a transistor but I figured I might be able to learn something by asking. Thanks!


No the arduino will drive an LED quite well.

My guess is that you forgot to make the LED pin into an output in the setup function. You need a resistor in line with the LED as well.

My guess is that you forgot to make the LED pin into an output in the setup function.

So you were right that there was something funky going on in the setup and I got it working but just out of curiosity I was wondering if you could add some insight to why this code below that I found on the Arduino site under ForLoop was causing the issue.

for (int thispin = 2; thispin > 13;thispin++){ pinMode(thispin, OUTPUT); }

I found this code here:

My understanding was that this code put in the setup section would pins 2-13 into outputs. When I replaced it with this more unwieldy code it fixed everything:

pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT);

Any idea what was happening?

You miss read the tutorial.

This code is wrong:-

for (int thispin = 2; thispin > 13;thispin++){
    pinMode(thispin, OUTPUT);

The loop will never run through the values because the middle statement is always false and the loop only runs while the middle statement is true.
it should be

for (int thispin = 2; thispin < 13;thispin++){
    pinMode(thispin, OUTPUT);

Oh that’s right >< I was thinking the middle was the condition for which it would stop. Thanks a bundle.