Arduino Mega 2560 and capacitive sensor issue

Good Day

Last week i was using the capacitive sensor library and it works fine and fast, today i used it again but it is working too slow, i read some topics in this forum but no answer. i used the example and nothing change it works slow. i put another examples (serial and other and the arduino is working fine.

Someone knows what is wrong??

#include <CapacitiveSensor.h>


  • CapitiveSense Library Demo Sketch
  • Paul Badger 2008
  • Uses a high value resistor e.g. 10M between send pin and receive pin
  • Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
  • Receive pin is the sensor pin - try different amounts of foil/metal on this pin

CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example

void loop()
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long total2 = cs_4_6.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 windown spacing

Serial.print(total1); // print sensor output 1
Serial.print(total2); // print sensor output 2
Serial.println(total3); // print sensor output 3

delay(10); // arbitrary delay to limit data to serial port

I had reinstall the arduino IDE and the library without change in the speed, i attach a pictures with the times of eash read


Hello, I am having the same problem. I am also, using arduino mega. Did you find what the problem was?