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
}
}
