The CapacitiveSense library is the key to my project. A custom art touch lamp. Arduino CapacitiveSensor Library

It works great with the Arduino UNO but the Nano Every has vastly different performance and issues with exactly the same code and HW. The Arduino is just too large for my project so I had high hopes that the Nano E would be a compatible fit.

My HW setup is per the example. Using a high value Resistor between pins 7 and 8 for Send and Receive(sensor). Works for the Uno but the Nano E just outputs a -2. Even though I tried resistor values 56K to 2M!. Realize the error -2 can mean a missing resistor. So I then tried the Threshold 3 way switch example code which suggests that just using pin 8 as an antenna is possible. I have a small steel plate (3"x4") connected directly to pin 8. Again Arduino Works great. By that I mean that I can adjust the parameters labeled in the code as a, b and c to get a repeatable trigger output to the serial monitor. The Nano Every with the same code though gets vastly different readings for cs and they don't stabilize. By vast , I mean Arduino returns cs numbers in range 100 to 200;s while the Nano E returns in the 33000's. Now I can make the code recognize those numbers for a trigger but subsequent touches range all over the place (1000's to 50000's) making touching the plate highly random with triggers. I have made large tables (many hours) trying to dial the parameters in on the Nano with no success while it took me about 10 mins to dial in on the Arduino for reliable operation. Why would the Nano Every be so different from the Uno?

The Threshold example code (bottom of page) in the library reference is perfect my setup as it is described as a used for a 3 way switch. The example code is below.

#include <CapacitiveSensor.h>
CapacitiveSensor cs_7_8 = CapacitiveSensor(7,8); //10M Resistor between pins 7 and 8, you may also connect an antenna on pin 8
unsigned long csSum;

void setup() {

void loop() {

void CSread() {
    long cs = cs_7_8.capacitiveSensor(80); //a: Sensor resolution is set to 80
    if (cs > 100) { //b: Arbitrary number
        csSum += cs;
        if (csSum >= 3800) //c: This value is the threshold, a High value means it takes longer to trigger
            Serial.print("Trigger: ");
            if (csSum > 0) { csSum = 0; } //Reset
            cs_7_8.reset_CS_AutoCal(); //Stops readings
    } else {
        csSum = 0; //Timeout caused by bad readings

Serial Output with Uno board with nice triggers. parameters cs>700, csSum>=1500, samples are 10,

799 812 Trigger: 1161

I realize this is a lot of detail in this question. But I've searched this and other boards for anything on getting Capacitive Sensor to work reliably on any other board beside Uno and haven't found anything. I'm also aware of the grounding issues talked about in relation to touch sensing. I had a previous post here about that using the Trinket M0 but abandoned that due to grounding issues with it. I still have issues whether the Nano is connected via USB or an independent AC-DC power supply with 12vdc going to Nano. I don't see any grounding issues with both the Arduino Uno and nano every with either USB power or independant AC-DC 12v power Any insights appreciated.

  • 1
    You may have more luck with the plain Nano (not the Every), as it is built around the same MCU (ATmega328P) as the Uno. Nov 20, 2021 at 18:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.