Go Down

Topic: Capacitive sensing issue when 220v AC is connected (Read 116 times) previous topic - next topic


Hi all,

I am completely new in using arduino and doing more "advanced" electrical projects.

I therefore, hope some of you experts can help me with my project.
I have an issue trying to make a touch sensitive lamp.

I did make all the wiring and conversion from 220v AC to 12v DC. Everything works perfect when i connect the arduino nano to my computer and test it using the below code.
All values are below 150 pF and when i touch it jumps to above 2000 pF and toggles my relay on/off.

However when i connect the lamp to 220v AC the issue starts. All pF values are jumping up and down toggling the lamp on and off without me touching the lamp.
i use a 1 megohm resistance between the send and receive pin. i also use a capacitor (101) from sensor pin to ground as suggested on: https://playground.arduino.cc/Main/CapacitiveSensor/

I believe the issue may be in the code which can be seen below (based upon the sample from the library). I hope you can help me.

#include <CapacitiveSensor.h>

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
bool toggle = false;

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

void loop()                   
    //long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);

    if(total1 >= 1500)
      if(toggle == false)
        toggle = true;
        digitalWrite(7, HIGH);
        toggle = false;
        digitalWrite(7, LOW);
    delay(10);                             // arbitrary delay to limit data to serial port


It seems you forgot to post your schematic (and use code tags).

Most likely cause of your issue: grounding.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up