Touch sensor isn't lighting up LED

Brand new to Arduino. Currently trying to make a LED light up with a touch sensor. I believe the coding is in order since it's copied from the Arduino website. The sensor responds to my touch but it doesn't translate into the LED. New components, I've made the LED light up in the past. Can anyone help?`#touchsensor #LED #Breadboard

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-touch-sensor-led
 */

const int TOUCH_SENSOR_PIN  = 2; // Arduino pin connected to the OUTPUT pin of touch sensor
const int LED_PIN           = 3; // Arduino pin connected to LED's pin

void setup() {
  Serial.begin(9600);               // initialize serial
  pinMode(TOUCH_SENSOR_PIN, INPUT); // set arduino pin to input mode
  pinMode(LED_PIN, OUTPUT);         // set arduino 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
  }
}

;; there should only be one there.

Change the LED_PIN to pin 13, and see if the onboard LED lights up.
Leo..

1 Like

The wire from the touch sensor appears to be plugged into pin 7, not pin 2.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.