Arduino Capacitive Touch Setup

1.9K20

Intro: Arduino Capacitive Touch Setup

Hey everyone, in this tutorial I'll be showing you guys how you can use the capacitive sensor library to make an Arduino nano-based TOUCH SENSOR to toggle a LED WITHOUT USING TTP223 touchpad sensor module.

STEP 1: SCHEMATIC

here's the SCH, wire everything just like this and you'll be good.

connect the copper plate to pin 4, this will be our touchpad.

I've added mosfet to this setup so we can trigger loads like a motor, relay etc but you can remove it and connect an LED instead.

STEP 2: CODE

download the library before using this code.

https://github.com/arduino-libraries/CapacitiveSen...

Here's the code

#include<CapacitiveSensor.h>

CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4); // 1M resistor between pins 2 & 4, pin 4 is sensor pin, add a wire and or foil

int in = 2;

int out = 4;

int state = LOW;

int r;

int p = LOW;

long time = 0;

long debounce = 200;

void setup()

{

pinMode(4, INPUT);

pinMode(3, OUTPUT);

}

void loop()

{

r = digitalRead(4);

if (r == HIGH && p == LOW && millis() - time > debounce)

{

if (state == HIGH) state = LOW;

else state = HIGH;

time = millis();

}

digitalWrite(3, state);

p = r;

}

STEP 3: THIS WILL NOT WORK UNLESS

this project has a flaw, which is the ground problem.

this will not work unless your laptop or computer is connected to the power plug which has an earth connection.

just plug in your laptop charger and test this setup, it will work..

GOOD LUCK