- Introduction
You can use various interrupts to alter the program sequence. In such a way, touch sensors can work in a similar way in terms of interrupt as a push button. It converts any touch signal into an electrical signal. Microcontroller is now able to receive a signal indicating such an interrupt and call a subroutine to acknowledge the call.
- Objective
The aim of this experiment is to help the user:
- To learn how to interface a touch sensor to the microcontroller.
- To blinking led with touch sensor
- Component knowledge
What is a Touch Sensor? A touch sensor is an electronic component that detects physical touch or proximity, typically used to replace mechanical buttons or switches. When a user touches the sensor, it registers the touch and sends an electrical signal to the connected circuit. Many devices like smartphones, elevators, and touch-activated lamps use touch sensors.
Touch sensors work using capacitive or resistive technology:
- Capacitive touch sensors: Detect the electrical charge from a human body.
- Resistive touch sensors: Detect pressure applied to the sensor surface.
Figure: Touch sensor
- Pin Identification of a Touch Sensor
Touch sensors typically have 3 pins:
- VCC (Power): This is the pin where you connect the positive voltage supply, usually 3.3V or 5V.
- GND (Ground): This pin connects to the ground of the circuit.
- OUT (Output): This pin outputs a signal when the sensor detects a touch. The signal could be digital (HIGH or LOW) or analog, depending on the type of touch sensor.
Capacitive Touch Sensor Example (TTP223):
- VCC: Power supply pin (usually 3.3V or 5V).
- GND: Ground connection.
- OUT: The output pin where the signal is sent when a touch is detected.
- How to Test a Touch Sensor
Using a Multimeter (Digital Sensors):
- Connect the VCC pin to a 5V or 3.3V power source.
- Connect the GND pin to the ground.
- Check the output (OUT) pin with a multimeter or an oscilloscope.
- When not touched, the output should typically read LOW (0V or close to 0V).
- When touched, the output should change to HIGH (usually close to the power supply voltage, e.g., 3.3V or 5V).
Testing with an LED:
- Connect the OUT pin to an LED through a resistor.
- When the sensor is touched, the LED should light up.
A touch sensor is a convenient and modern component for detecting touch or proximity. The basic pins of the touch sensor are easy to connect and use: VCC for power, GND for ground, and OUT for signal output. You can test a touch sensor using a multimeter, a microcontroller like Arduino, or by directly driving an LED to observe the response when you touch it.
3. Materials to be used
- Touch sensor
- LED (Light emitting diode)
- Jumper wires
- Arduino microcontroller
- Breadboard
4. Circuit diagram
Figure: Schematic diagram for LED and Touch sensor connection
Figure: Components used to make connection on the board
5. Arduino Codes
6. Code knowledge
The lastState variable tracks the previous state of the sensor (initially set to LOW, indicating it’s not touched), while the currentState variable stores the current reading from the sensor pin.
In this loop function, currentState = digitalRead(SENSOR_PIN)reads the current state of the touch sensor and stores it in the currentState variable.
This block checks if the last state equals LOW (not touched) and the current state equals HIGH (touched). If the condition is true, it prints “The sensor is touched” to the Serial Monitor and turns on the LED at LEDPIN for 1 second.
This block checks if the last state equals HIGH (touched) and the current state equals LOW (released). If the condition is true, the code prints “The sensor is released” to the Serial Monitor and turns off the LED. Expected Output:
7. Results
1. Serial Monitor
- When you touch the sensor (input goes from LOW to HIGH), the Serial Monitor displays: “The sensor is touched.”
- When the sensor is released (input goes from HIGH to LOW) the serial monitor would display: “The sensor is released”
2. LED Behavior (Visible output):
The sensor touch lights up the LED, and releasing the sensor turns it off.
In summary, the program detects a transition (state change) in the sensor input:
- When the input changes from LOW to HIGH, the code prints “The sensor is touched” and turns the LED on.
- When the input changes from HIGH to LOW, the code prints “The sensor is released” and turns the LED off.