How does work touch sensor with Arduino

How does work touch sensor with Arduino

Hello guys, Welcome back to my SriTu Hobby blog. Today we will learn about the touch sensor.

What is a touch sensor?

These sensors can be simply described as electronic devices that detect the touch of the human body. They also operate in the form of electronic switches. Also, these sensors are activated on factors such as touch and pressure. Many of the devices we use every day include a touch sensor. For example, we can take a smartphone.

There are two main types of these sensors.

  • Capacitive touch sensor.
  • Resistive touch sensor.

Capacitive touch sensor

These sensors are activated using capacitance measurements. These sensors are integrated into portable devices. They are also designed to be durable and robust. These sensors include two parallel conductors and an insulator between them. Therefore, these sensors are acting as a capacitor. When this is touched by the fingers, our finger acts as a conductive object. When this happens, the value of the capacitor increases. Therefore, the circuit that measures the capacitance value of the sensor detects it and outputs a signal. These sensors are included in mobile phones and iPods.

Resistive touch sensor

These sensors are activated by measuring the pressure applied to the surface. Also, these sensors include two indium tin oxide-coated conductors. The two conductors are separated by a very small distance. Also, a voltage is applied to the two conductors. When we touch this sensor, the upper conductive membrane touches the lower conductive membrane. Then a voltage drop occurs. It is then detected by a controlling circuit and a signal is generated. These sensors include keypads, touchscreens, and musical instruments.

Okay, we will learn how a touch sensor works with an Arduino Uno board. The required components are as follows. You can buy these items online. For that, use the links below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Let’s do this project step by step.

Step 1

Firstly, identify these components.

Step 2

So let’s connect these components using the circuit diagram below.

How does work touch sensor with Arduino

Step 3

Okay, now look at the code below.

  • The complete program of this project – Download
/*Touch sensor with Arduino.
  Serial monitor readings.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creation
*/
 
#define touchPin 2
#define LEDpin  3
 
bool val;
bool lightON;
bool touch;
 
void setup() {
  Serial.begin(9600);
  pinMode(touchPin, INPUT);
  pinMode(LEDpin, OUTPUT);
 
}
 
void loop() {
 
  val = digitalRead(touchPin);
  if (val == 1 && lightON == 0) {
    touch = 1 - touch;
  }
 
  lightON = val;
 
  if (touch == 1) {
    Serial.println("LED ON");
    digitalWrite(LEDpin, HIGH);
 
  } else {
    Serial.println("LED OFF");
    digitalWrite(LEDpin, LOW);
 
  }
}

First, the sensor pin and LED pin are defined, and then three Boolean variables were created.

#define touchPin 2
#define LEDpin  3
 
bool val;
bool lightON;
bool touch;

This code sets the touchPin as an input pin and LEDpin as an output pin.

void setup() {
  Serial.begin(9600);
  pinMode(touchPin, INPUT);
  pinMode(LEDpin, OUTPUT);
 
}

The following code reads the sensor value and inserts it into the “val” variable. Then, it is tested using the if condition, the LED bulb turns on if the touch variable is equal to 1, and the LED bulb turns off if the touch variable is equal to 0.

void loop() {
 
  val = digitalRead(touchPin);
  if (val == 1 && lightON == 0) {
    touch = 1 – touch;
  }
 
  lightON = val;
 
  if (touch == 1) {
    Serial.println(“LED ON”);
    digitalWrite(LEDpin, HIGH);
 
  } else {
    Serial.println(“LED OFF”);
    digitalWrite(LEDpin, LOW);
 
  }

Step 4

OK, now select the board and port correctly. Then click the upload button.

OK, enjoy this project. The full video guide is below. So we hope to see you in the next project.

How does work touch sensor with Arduino.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *