Touch sensor with LED and Buzzer

 

What is a Touch Sensor?

Touch Sensors are the electronic sensors that can detect touch. They operate as a switch when touched. These sensors are used in lamps, touch screens of the mobile, etc… Touch sensors offer an intuitive user interface.

Touch Sensor

Touch Sensor


Touch Sensor Working Principle

These sensors are sensitive to any pressure or force applied or touch. The principle of touch is similar to that of a switch. When the switch is closed, the current flows otherwise there is no chance of the current to flow. Similarly, when the touch sensor senses the touch or proximity is captured then it acts like a closed switch otherwise it acts as an open switch.  These sensors are also known as ‘Tactile Sensors’.









Hardware required:

Arduino UNO or Genuino UNO
USB 2.0 cable type A/B
Touch Sensor
Jumper Wires


const int TOUCH_SENSOR_PIN  = 2; // Arduino pin connected to the OUTPUT pin of touch sensor

const int LED_PIN           = 12; // Arduino pin connected to LED's pin


void setup() {

  Serial.begin(9600);               // initialize serial

  pinMode(TOUCH_SENSOR_PIN, INPUT); // set arduino pin to input mode

  pinMode(LED_PIN, OUTPUT);         // set arduino pin to output mode

}


void loop() {

  int touchState = digitalRead(TOUCH_SENSOR_PIN); // read new state


  if (touchState == HIGH) {

    Serial.println("The sensor is being touched");;

    digitalWrite(LED_PIN, HIGH); // turn on

  }

  else

  if (touchState == LOW) {

    Serial.println("The sensor is untouched");

    digitalWrite(LED_PIN, LOW);  // turn off

  }

}


Final output 👇




Comments

Post a Comment