Cap Sense Project going haywire!

This is only my second Arduino project - so apologies in advance for all the "Newbie-Speak"...


I'm building a simple project as follows:

Arduino Nano with 9V power supply from a transformer plugged into mains.

Cap Sensing as per:

Arduino Playground: CapSense

Basically:

1M resistor acros pin 9 and 11
Sensing wire connected to pin 9
Piece of tinfoil connected to the sensing wire

Relevant code:

#include <CapacitiveSensor.h>

CapacitiveSensor cs_11_9 = CapacitiveSensor(11,9);
int led = 13;
int state = HIGH;

void setup() {

cs_11_9.set_CS_AutocaL_Millis(20000); //Calibrate the sensor...
pinMode(led, OUTPUT);

}

void loop() {

long total1 = cs_11_9.capacitiveSensor(30);

if (total1 > 400){state = HIGH;}
else {state = LOW;}

if (state == HIGH) {digitalWrite(led, HIGH);}
else {digitalWrite(led, LOW);}

delay(20);
}


Here's the problem:

When the Arduino is plugged into my PC with a USB cable (for upload only as the 9V is still supplying power) everything works 100%.
The values sensed by my foil sensor is fairly stable and entirely predictable.
With no touch, they vary between about 30 and 160.
With touch, they shoot up to around 1000.

However, as soon as I unplug the USB cable, the values go beserk.
Sometimes it's stuck at 0 for a while then randomly spikes into the 1000s, then back down again.
Behaviour is also different every time I reset the Nano.
There is also no discernible difference between touch and no touch.


Question:

Am I having grounding issues here?
Quote from above link:

Grounding and other known issues

The grounding of the Arduino board is very important in capacitive sensing. The board needs to have some connection to ground, even if this is not a low-impedance path such as a wire attached to a water pipe.

Capacitive sensing has some quirks with laptops unconnected to mains power. The laptop itself tends to become sensitive and bringing a hand near the laptop will change the returned values.

Connecting the charging cord to the laptop will usually be enough to get things working correctly. Connecting the Arduino ground to an earth ground (for example, a water pipe) could be another solution.

Another solution that seems to have worked well on at least one installation, is to run a foil ground plane under the sensor foil (insulated by plastic, paper, etc.), and connected by a wire to ground. This worked really well to stabilize sensor values and also seemed to dramatically increase sensor sensitivity.

There are no Earth on the 9V Transformer.


Really not sure what to do here. Except buying a different touch sensor perhaps.
Any comments / suggestions are highly appreciated!

Am I having grounding issues here?

Yes.

Wire up a ground pin to your power supply.

Hi GM

Thanks for the response.

Im not sure what you mean though.

I have the pos terminal of the 9V transformer connected to Arduino Vin pin and the neg terminal connected to GND pin (pin 29).

If you are saying I should connect pin 29 to my 9V power supply neg terminal, then that is already done.
Apart from haywire readings, the Nano is functioning fine. (I have all output readings displaying on a 5510 LCD with no problems on 9V supply only).

Regards

No that is not what I am saying.
Take the ground pin from the wall outlet and connect it to the groundling of the Arduino.

Sorry Mike, my knowledge is this field is terrible!!

When you say "Ground Pin from wall outlet", I take it to mean the earth terminal from a wall socket.
As in the Green&Yellow wire in the mains circuit.

But what does "grounding of the Arduino" mean?

Should I connect the earth terminal of a wall outlet to pin 29 (GND) of the arduino?
I hesitate because the Neg terminal from the transformer is already connected there.

Sorry for my lack of basic knowledge on this.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Especially your 9V power supply from a transformer.

A picture of your project would help also as layout will have an effect on your results.

Tom....... :slight_smile:

When you say "Ground Pin from wall outlet", I take it to mean the earth terminal from a wall socket.
As in the Green&Yellow wire in the mains circuit.

Yes.

I hesitate because the Neg terminal from the transformer is already connected there.

Are you very very sure. This would be a very strange thing to do and would not meet EU regulations if it did.
If it is already connected then you are just duplicating the connection anyway.

Should I connect the earth terminal of a wall outlet to pin 29 (GND) of the arduino?

Where is this "pin 29" coming from? An Arduino processor only has 28 pins and there is nothing marked as Pin 29 on a Uno.

Hi Mike

I'm using an Arduino Nano (30 pins).
Pin 29 is marked GND.

If the negative terminal of my power supply is not suppose to go to the GND pin on the Nano, where should it go then?

In other words :

There are only two wires coming from my 9V transformer.
Pos (+) goes to Arduino VIN pin.
Neg (-) goes to?

OK, so as I said connect the mains earth to the Nano's ground as well as the Neg pin from your power supply.

Grumpy_Mike:
No that is not what I am saying.
Take the ground pin from the wall outlet and connect it to the groundling of the Arduino.

Bad Idea. There is a possibility for getting killed here. Just take a wire and wrap it around the threads of the screw that hold on the face plate and then screw the wire back in.

Oh yeah and you could also zap your nano... Not fun...

Bad Idea. There is a possibility for getting killed here.

Absolute and utter rubbish. How can you get killed connecting anything to ground. Most electrical devices do it as a matter of course. My scope is connected to mains earth and when I connect the ground clip to an Arduino ground I am doing exactly the same thing. No risk no zapping.

Just take a wire and wrap it around the threads of the screw that hold on the face plate and then screw the wire back in.

And that is supposed to be sensible is it?

Oh yeah and you could also zap your nano

Tosh.

Please do not post rubbish advice.

Not fun...

True bad advice like this is not fun.

Grumpy_Mike:
Absolute and utter rubbish. How can you get killed connecting anything to ground. Most electrical devices do it as a matter of course. My scope is connected to mains earth and when I connect the ground clip to an Arduino ground I am doing exactly the same thing. No risk no zapping.
And that is supposed to be sensible is it?

Tosh.

Please do not post rubbish advice.
True bad advice like this is not fun.

The meaning for that 3rd pin is that if a device malfunctions and shorts it will short to that wire. All metal enclosures get connected to that wire in devices. If a device shorts and your nano or you is touching that wire you could become a path to ground... ~120 volts and 10+ amps is not fun...

See WHY THREE PRONGS? Electrical ground, stray voltage. You don't want to be in the path of the safety ground if something shorts especially if you have a delicate device like an arduino as more than +5v on that pin will cause it to malfunction...

The meaning for that 3rd pin is that if a device malfunctions and shorts it will short to that wire. All metal enclosures get connected to that wire in devices. If a device shorts and your nano or you is touching that wire you could become a path to ground... ~120 volts and 10+ amps is not fun...

You seem to have a fundamental lack of a clue about how electricity works.
Yes if there is a malfunction then the live wire can be connected to ground. Therefore how can a device that is connected to the same potential possibly become live? It can't plain and simple. Any faulty connection voltage is therefore shorted to ground. That means that the ground wire never becomes anything else but the ground potential. What happens in the event of a fault is that current flows from the live to ground and therefore blows the fuse thus disconnecting the mains.

So according to you it would never be safe to touch anything connected to ground. That is the biggest load of nonsense I have heard on this forum ever. That is simply not what happens to electricity.

Your "advice" is totally bogus.