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.
That is,
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.
/*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 connected pin and LED connected pin of the Arduino was 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.
Step 5
Finally, upload this code. You can watch the full video guide below.
Hello, welcome back. In this tutorial, we will learn how to make a Temperature and Humidity monitoring system using the Thingspeak web application. It mainly uses the Nodemcu board and…
Line following Robot car kit Assembly Hello guys, welcome back to the SriTu Hobby blog. This tutorial includes step-by-step instructions on how to assemble a “Line Following…
Hello, welcome back. In this tutorial, we will learn how to make a DIY Bluetooth control boat using Arduino. It is mainly based on the Bluetooth module known as the…
Hello, welcome back. In this tutorial, we will learn how to work the MPU6050 sensor with a servo motor. Also, From this, we can also understand how the values change…