ESP32 KY-036 Metal Touch Sensor Module
Overview
The KY-036 is a metal touch sensor module that detects touch via its metal tip, offering both analog and digital outputs. With adjustable sensitivity, it's ideal for interactive applications and touch-based controls.
About KY-036 Metal Touch Sensor Module
The KY-036 Metal Touch Sensor Module detects touch through its metal tip, providing both analog and digital outputs. The module features an LM393 comparator and a potentiometer to adjust sensitivity, making it suitable for interactive projects and touch-based controls.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
+V:
Connects to the power supply, typically 3.3V or 5V.GND:
Connects to the ground of the circuit.Digital Signal:
Outputs a high signal when touch is detected.Analog Signal:
Provides the direct analog measurement from the sensor.
Troubleshooting Guide
Common Issues
❌ No Response from Sensor
Issue: The sensor does not respond to touch.
Solutions:
- Ensure the module is properly powered with the correct voltage.
- Verify all connections are secure and correctly wired.
- Adjust the sensitivity using the onboard potentiometer.
⚠️ False Triggering
Issue: The sensor triggers without being touched.
Solutions:
- Reduce the sensitivity using the potentiometer to prevent false triggers.
- Ensure the environment is free from electrical noise or interference.
- Check for any conductive materials accidentally touching the sensor's metal tip.
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
Code Examples
Arduino Example
int analog_input = A0; // Analog output of the sensor
int digital_input = 3; // Digital output of the sensor
void setup() {
pinMode(analog_input, INPUT);
pinMode(digital_input, INPUT);
Serial.begin(9600);
Serial.println("KY-036 Touch Recognition");
}
void loop() {
float analog_value = analogRead(analog_input) * (5.0 / 1023.0);
int digital_value = digitalRead(digital_input);
Serial.print("Analog voltage value: ");
Serial.print(analog_value, 4);
Serial.print(" V, Threshold value: ");
if (digital_value == 1) {
Serial.println("reached");
} else {
Serial.println("not yet reached");
}
Serial.println("----------------------------------------------------------------");
delay(1000);
}
This Arduino code initializes the analog and digital input pins connected to the KY-036 sensor. It reads the analog voltage and digital state, printing the analog voltage and whether the threshold set by the potentiometer has been reached to the serial monitor every second.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "driver/gpio.h"
#define ANALOG_PIN ADC1_CHANNEL_6 // GPIO34
#define DIGITAL_PIN GPIO_NUM_15
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ANALOG_PIN, ADC_ATTEN_DB_11);
gpio_set_direction(DIGITAL_PIN, GPIO_MODE_INPUT);
printf("KY-036 Touch Sensor Test\n");
while (1) {
int raw = adc1_get_raw(ANALOG_PIN);
float voltage = raw * (3.3 / 4095.0);
int digital_state = gpio_get_level(DIGITAL_PIN);
printf("Analog Voltage: %.2f V, Threshold: %s\n", voltage, digital_state ? "reached" : "not yet reached");
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
This ESP-IDF code configures GPIO34 as an analog input and GPIO15 as a digital input for the KY-036 sensor. It reads the analog voltage and digital state, printing the voltage and whether the threshold has been reached to the console every second.
ESPHome Example
sensor:
- platform: adc
pin: GPIO34
name: "KY-036 Touch Sensor Analog"
update_interval: 1s
filters:
- multiply: 3.3
- lambda: |-
return x * 1000; // Convert to millivolts
binary_sensor:
- platform: gpio
pin:
number: GPIO15
mode: INPUT_PULLUP
name: "KY-036 Touch Sensor Digital"
This ESPHome configuration sets up the KY-036 sensor with both an analog and digital sensor. The analog value from GPIO34 is converted to millivolts, while the digital sensor on GPIO15 acts as a binary sensor to indicate touch detection.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define ANALOG_PIN 34
#define DIGITAL_PIN 15
void setup() {
pinMode(DIGITAL_PIN, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("KY-036 Touch Sensor Test");
}
void loop() {
int raw_value = analogRead(ANALOG_PIN);
float voltage = raw_value (3.3 / 4095.0) 1000; // Convert to millivolts
int digital_value = digitalRead(DIGITAL_PIN);
Serial.printf("Analog Voltage: %.2f mV, Digital State: %s\n", voltage, digital_value ? "Touched" : "Not Touched");
delay(1000);
}
This PlatformIO code sets up GPIO34 as an analog input and GPIO15 as a digital input for the KY-036 sensor. It reads the analog voltage and digital state, logging the voltage and touch detection status to the serial monitor every second.
MicroPython Example
import machine
import time
ANALOG_PIN = machine.ADC(machine.Pin(34))
ANALOG_PIN.atten(machine.ADC.ATTN_11DB)
DIGITAL_PIN = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP)
while True:
analog_value = ANALOG_PIN.read()
voltage = (analog_value / 4095) * 3300 # Convert to millivolts
digital_value = DIGITAL_PIN.value()
print("Analog Voltage:", voltage, "mV", "| Digital State:", "Touched" if digital_value == 1 else "Not Touched")
time.sleep(1)
This MicroPython script configures GPIO34 as an ADC input and GPIO15 as a digital input for the KY-036 sensor. It continuously reads the sensor values and prints the voltage and touch state every second.
Conclusion
The ESP32 KY-036 Metal Touch Sensor Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.