Hi,
I am fairly new to Arduino and looking for help with my project. I am making a proximity sensor using Bare conductive paint.
My circuit is- Pin 2 (sensor pin) to breadboard. Pin 4 (receiver) to breadboard. On breadboard, these are bridged with 10m resistor. Pin 2 connected to conductive paint via wire with paperclip soldered on.
The code was copied directly from the CapSense code example on this site and is as follows:
#include <CapacitiveSensor.h>
/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10 megohm between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of foil/metal on this pin
* Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
*/
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long total2 = cs_4_5.capacitiveSensor(30);
long total3 = cs_4_8.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug window spacing
Serial.print(total1); // print sensor output 1
Serial.print("\t");
Serial.print(total2); // print sensor output 2
Serial.print("\t");
Serial.println(total3); // print sensor output 3
delay(10); // arbitrary delay to limit data to serial port
}
It uploaded successfully and has been successfully verified so am sure there is nothing wrong with the code itself.
The problems I am having are with the data being displayed/ understanding what I am looking at:
Serial Monitor in the tutorial I followed on the BareCondusctive website printed 1 column of data (2 figure numbers) which displayed a new line of data every half second or so and the numbers increased to the thousands when close to sensor.
Mine has 4 columns of data (think this is due to the Serial.print("/t") command!?) but a new line of data is displayed every 4 second even if i change the delay.
I am unsure what these 4 columns mean- could someone please advise?
Columns look like this:
3903 0 -2 -2
3895 62 -2 -2
3885 0 -2 -2
3884 21 -2 -2
3883 0 -2 -2
3882 56 -2 -2
3881 0 -2 -2
3881 0 -2 -2
3881 86 -2 -2
3881 79 -2 -2
As you can see, the second column changes significantly but not in relation to the sensor! (The above data was recorded with nothing near the sensor) I believe the -2 figures I am getting is due to “capacitiveSensor and capacitiveSensorRaw will return -2 if the methods timeout. This is caused by the count exceeding the value of CS_Timeout_Millis, which is set at a default value of 2000 milliseconds (2 seconds). This is most often caused by a missing resistor or the resistor in the wrong pin. It could also be caused by a sensor that is grounded or connected to +5 V.” but I have checked my resistor and it is in the right place, isn’t missing and neither pin is grounded (apart from usb to computer)
I have looked on YoutUBE, Google etc and can’t seem to find any help. Would really appreciate it if someone could help me out here.
Thanks