Base Input

๐Ÿ‘† Touch

๐Ÿ“Œ Description

The Touch key module is like a magic button. Instead of pressing it, you just touch it with your finger, and it reacts. It senses the touch using electricity in your skin.

๐ŸŽฏ Use

In our projects, the touch key is used to:

  • Turn lights or devices on and off with a simple touch.
  • Replace mechanical buttons with a smoother, modern option.
  • Make robots more interactive and fun to use.

๐Ÿ‘‰ Think of the touch key as the robotโ€™s touchscreen button โ€” you donโ€™t press, you just touch.

ย Module parameters

Pin name Description
G GND (Power Input)
V VCC (Power Positive)
S Digital signal pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 3P terminal
  • Installation method: screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine

pin25 = machine.Pin(25, machine.Pin.IN)    # Touch sensor input
pin26 = machine.Pin(26, machine.Pin.OUT)   # LED output

while True:
    if pin25.value() == 1:                 # If touch is detected
        pin26.value(1)                     # Turn LED ON
    else:
        pin26.value(0)                     # Turn LED OFF
    print(pin25.value())                   # Show sensor value (1 = touched, 0 = not touched)

Step by Step

  1. import machine โ†’ Tools to control pins.
  2. pin25 = machine.Pin(25, machine.Pin.IN) โ†’ Pin 25 reads the touch sensor (input).
  3. pin26 = machine.Pin(26, machine.Pin.OUT) โ†’ Pin 26 controls the LED (output).
  4. while True: โ†’ Loop that repeats forever.
  5. if pin25.value() == 1: โ†’ Checks if the sensor is touched.
  6. pin26.value(1) โ†’ Turns the LED on when touched.
  7. else: โ†’ If not touchedโ€ฆ
  8. pin26.value(0) โ†’ Turns the LED off.
  9. print(pin25.value()) โ†’ Shows the sensorโ€™s state (1 or 0) on the computer screen.

๐Ÿ‘‰ Together, this program makes the LED light up when you touch the sensor.


โœ… Conclusion of the Test

  • If touching the sensor turns the LED on, and releasing it turns the LED off, the program is working correctly.
  • This test shows how the robot can sense touch and react with an output (LED).
  • Later, instead of just controlling a light, the touch sensor could be used to start motors, change modes, or trigger sounds.
On this page