Hi everyone!
I am developing a capacitive sensor with my Arduino UNO,
but I am having a problem with low sensitivity.
I am already using an 80Mohm resistor (8*10Mohm resistors in series) but the sensor reacts to my hand only at 3,5 inches away, when my goal is at least 20. As far as I can read from the Capsense tutorial and the Bareconductive example stemming from it, a resistor of 40Mohm should sense my hand at least 12 inches away.
What am I doing wrong?
This is my hardware setup:
Pin 2 si connected to Pin 4: between them there is my capacitive sensor and the 80Mohm resistor.
Whenever my hand is in the sensing range, a led fades up. When my hand is away from the sensor, the led fades down and is off. (I avoided mapping the actual readings of the sensor to the led output due to slow performance).
The arduino is powered through an usb port of a laptop plugged into the wall socket (no battery). The sensor is made from an A4 sheet of paper covered with graphite paint (I tried with tin foil and the results are similar). I have tried earthing the Arduino connecting the GND pin to a non-painted water pipe as suggested in the guide, but the sensor doesn't improve its sensitivity. Doing the same to with the sensor doesn't help.
I also tried powering the Arduino with a 9volt battery: the sensor seems to lose its sensitivity, while the metallic part of the Arduino get sensitive. I tried connecting the GND pin to the negative pole of the battery, but to no results.
This is my code:
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); //80M resistor between pins 4 & 2, pin 2 is sensor pin
int outputvalue = 0; //this variable controls the power level of the led from 0 to 255
void setup()
{
Serial.begin(9600); //starting communications
}
void loop()
{
long total1 = cs_4_2.capacitiveSensor(30); //total1 is the value of the capacitive sensor
if (total1 > 4000){
outputvalue +=5;
}
//if the sensor senses my hand, raise the power level of the led, making it fade up.
//4000 is an arbitrary value I chose it because it is indicates a value where my hand is surely there. Without, the any contact, the sensor would fluctuates from 0 to 1000
else { //if the sensor doesn't sense my hand, lower the power level of the led, making it fade down
outputvalue -=5;
}
if (outputvalue > 255) { //max value of the output is 255
outputvalue = 255;
}
if (outputvalue < 0) {//min value of the output is 0
outputvalue = 0;
}
analogWrite (9, outputvalue); //light up the led connected to pin 9 accordingly to the previous script
Serial.print("sensor = " ); //print the values from the sensor and the output
Serial.print(total1);
Serial.print("\t output = ");
Serial.println(outputvalue);
Serial.print("\t output = ");
delay(2);
}
I experimented with 100pF capacitors as suggested in the guide to stabilize my readings but they lower the sensitivity, so I abandoned them.
I appreciate every suggestion: I would really like to make this work from 20-30 inches away and make this battery powered since I would like to hang the results to a wall photo in a lightbox way:)