Tutorial | Using a Touch Sensor [external link]

Hello everyone! I may be a Newbie on the Forum but I have over 1.5 years of experience in Arduino...The Touch Sensor is a sensor which sends a HIGH signal to your Arduino when you touch it or if you have not touched it sends a LOW signal to your digital pin.

I am posting this cause not all people know there is a touch sensor. A touch sensor acts similar to a button...Actually it is basically a button but just that you don't need to press anything just touch the middle of the small sensor.

Check out my new Arduino Tutorial on YouTube :-

So the touch sensor has 3 pins - VCC, GND, SIG.

VCC - 5V, 3.3V
GND - Ground Pin
SIG - Any Digital Pin ( using pin 9 in this case )

I feel that this sensor is way easy to connect and work with than a button...

Here, I'm going to turn on an LED when the touch Sensor you know, is touched. The code is same as a button's code :-

int touchPin = 9; // Touch Sensor's Pin
int touchState; // The state of the Sensor
int ledPin = 13; // The LED Pin

void setup() {

   pinMode ( ledPin, OUTPUT );
   pinMode ( touchPin, INPUT );

}
void loop() {
    
   touchState = digitalRead ( touchPin );

   if ( touchState == HIGH )
   {
       digitalWrite ( ledPin, HIGH );
    }
    else
    {
       digitalWrite ( ledPin, LOW );
     }
}

Please reply your reviews and do see the video :slight_smile:

...and if you're not getting paid by the LOC

const byte touchPin = 9;
const byte ledPin = LED_BUILTIN;

void setup() 
{
   pinMode ( ledPin, OUTPUT );
   pinMode ( touchPin, INPUT );
}
void loop() 
{
  digitalWrite ( ledPin, digitalRead (touchPin) );
}

Yep....