Arduino Touch Sensor Code

const int touchPin = 2; // the pin the touch sensor is connected to

const int ledPin = 9; // the pin the LED is connected to

void setup() {
pinMode(touchPin, INPUT); // set the touch pin as an input
pinMode(ledPin, OUTPUT); // set the LED pin as an output
}

void loop() {
// read the state of the touch sensor
int touchState = digitalRead(touchPin);

// check if the touch sensor is being pressed
if (touchState == HIGH) {
// turn the LED on
digitalWrite(ledPin, LOW);
} else {
// turn the LED off
digitalWrite(ledPin, HIGH);
}
}

Comments

Popular posts from this blog

ESP32 Wi-Fi Extender Code