Controlling LEDs with touch sensortouch sensor

Arduino LED Magic: Unveiling the Touch Sensor Control



Hello Arduino Enthusiasts!

I'm excited to share a captivating project that combines the charm of touch sensors with the enchanting glow of LEDs. In my recent YouTube tutorial, we embarked on an Arduino adventure, creating a sequence of LEDs that respond to the gentle touch of a sensor. If you missed the video or need the code for reference, you're in the right place!


The Project: Touch Sensor LED Control

Picture this: a touch sets off a mesmerizing dance of LEDs, each lighting up in sequence. Thanks to Arduino, this dreamy scenario becomes a reality. The touch sensor becomes our magical wand, and the LEDs respond by lighting up one after another, creating a captivating visual display.


The Code

Here's the Arduino code for the project:


```cpp

const int touchSensorPin = 2;

const int ledPins[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3};

const int numLEDs = sizeof(ledPins) / sizeof(ledPins[0]);

const int delayTime = 500;


void setup() {

  pinMode(touchSensorPin, INPUT);

  for (int i = 0; i < numLEDs; i++) {

    pinMode(ledPins[i], OUTPUT);

    digitalWrite(ledPins[i], LOW); // Set all LEDs initially off

  }

}


void loop() {

  static int currentLED = 0;


  if (digitalRead(touchSensorPin) == HIGH) {

    digitalWrite(ledPins[currentLED], HIGH);

    delay(delayTime);

    digitalWrite(ledPins[currentLED], LOW);


     currentLED++;

    if (currentLED == numLEDs) {

      currentLED = 0; // Start over from the first LED

    }

    while (digitalRead(touchSensorPin) == HIGH) {

      // Wait for touch sensor to be released

    }

  }

}

```


Feel free to explore, modify, and experiment with the code. Copy and paste this into your Arduino IDE, and watch the magic unfold on your own Arduino Uno!


Getting Started

If you're new to Arduino or want a step-by-step guide, make sure to watch the full tutorial on my YouTube channel. I guide you through the entire process, from setting up the circuit to uploading the code and witnessing the magic unfold.


Share Your Creations

I'm eager to see your take on this project! Share your creations on social media using the hashtag  #ArduinotouchsensorLEDControl. Let's build a community of Arduino enthusiasts and inspire others to embark on their own electronic adventures.


Happy coding!


Shiva the CREATOR



Post a Comment

Previous Post Next Post