How Does Work Touch Sensor With Arduino

by STEAM-DIY in Circuits > Arduino

59 Views, 0 Favorites, 0 Comments

How Does Work Touch Sensor With Arduino

Screenshot_29-10-2024_15432_srituhobby.com.jpeg

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.

  1. Capacitive touch sensor.
  2. 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.

Supplies

Screenshot_29-10-2024_15732_srituhobby.com.jpeg

 The required components are as follows.

  1. Arduino Uno board x 1
  2. Touch sensor x 1
  3. Led bulb x 1
  4. 180-ohm resistor x 1
  5. Jumper wires
  6. Breadboard x 1


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

How does work touch sensor with Arduino

Okay, now look at the code below.

  1. The complete program of this project – Download
/*Touch sensor with Arduino.
*/
#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);
}



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

How does work touch sensor with Arduino

OK, enjoy this project. The full video guide is below.


So we hope to see you in the next project.