Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

/*

* This ESP32 code is created by esp32io.com


*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit
https://esp32io.com/tutorials/esp32-touch-sensor-led
*/

#define TOUCH_SENSOR_PIN 33 // ESP32 pin GPIO33 connected to the OUTPUT


pin of touch sensor
#define LED_PIN 17 // ESP32 pin GPIO17 connected to LED’s pin

Void setup() {
Serial.begin(9600); // initialize serial
pinMode(TOUCH_SENSOR_PIN, INPUT); // set ESP32 pin to input mode
pinMode(LED_PIN, OUTPUT); // set ESP32 pin to output mode
}

Void loop() {
Int touchState = digitalRead(TOUCH_SENSOR_PIN); // read new state

If (touchState == HIGH) {
Serial.println(“The sensor is being touched”);;
digitalWrite(LED_PIN, HIGH); // turn on
} else if (touchState == LOW) {
Serial.println(“The sensor is untouched”);
digitalWrite(LED_PIN, LOW); // turn off
}
}

You might also like