// Define the pin for the touch button
const int touchButtonPin = 27;
// Define the pin for the buzzer
const int buzzerPin = 5;
void setup() {
// Set the touch button pin as an input
pinMode(touchButtonPin, INPUT);
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read the touch button value (0-255)
int touchValue = touchRead(touchButtonPin);
Serial.println(touchValue);
// Adjust this threshold based on your touch sensor characteristics
int touchThresholdup = 1000;
int touchThresholddown = 200;
// Check if touch pressure is above the threshold
if (touchValue < touchThresholddown) {
// If the touch button is pressed, make a sound (tone) on the buzzer
tone(buzzerPin, 1000); // You can change the frequency (e.g., 1000 Hz)
}
if (touchValue > touchThresholdup) {
noTone(buzzerPin);
}
delay(200);
}