#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_8 = CapacitiveSensor(4, 8); // 1M resistor between pins 4 & 8, pin 8 is sensor pin
const int ledPin = 7; // Pin to which the LED is connected
int ledState = LOW;
unsigned long lastTouchTime = 0;
const unsigned long debounceDelay = 1000; // Adjust the debounce delay as needed
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
long touchValue = cs_4_8.capacitiveSensor(30); // Adjust the threshold value as needed
// If touchValue is above the threshold and debounce delay has passed, toggle the LED state
if (touchValue > 1000 && (millis() - lastTouchTime) > debounceDelay) {
ledState = 1 - ledState;
digitalWrite(ledPin, ledState);
lastTouchTime = millis();
}
}