Touch sensor with disc vibration motor

i am working on project for touch sensor and vibration motor coin type.
where i have connected touch sensor to esp32 and vibration motor to esp32 .
when i touch sensor motor should vibrate, if not touched it should not vibrate but in my case without touch it is vibrating with less intensity but with touch it is vibrating with high intensity.
i have upload wiring and code, check if i have make any changes in it

#define TOUCH_SENSOR_PIN 5   // Touch sensor connected to GPIO5
#define MOTOR_PIN 13         // Vibration motor connected to GPIO13

void setup() {
  Serial.begin(115200);
  delay(2000); // Allow time for Serial Monitor to connect
  Serial.println("ESP32 Touch Sensor with Vibration Motor");

  // Set the touch sensor pin to input with an internal pull-up resistor
  pinMode(TOUCH_SENSOR_PIN, INPUT_PULLUP);
  
  // Set the motor pin to output
  pinMode(MOTOR_PIN, OUTPUT);
  digitalWrite(MOTOR_PIN, LOW);  // Initially, motor is off
}

void loop() {
  // Check if the touch sensor is activated (touched)
  if (digitalRead(TOUCH_SENSOR_PIN) == LOW) { // Sensor triggered (LOW when touched)
    Serial.println("Touch detected! Motor ON");
    digitalWrite(MOTOR_PIN, HIGH);  // Turn on the vibration motor
  } else {
    Serial.println("No touch detected. Motor OFF");
    digitalWrite(MOTOR_PIN, LOW);   // Turn off the vibration motor
  }

  delay(100); // Small delay for stability
}


You should never connect any kind of motor directly to an ESP32 I/O pin. The motor will draw too much current, possibly damaging the ESP. Also the motor will generate a high voltage when it stops and that can also damage the ESP

I moved your topic to an appropriate forum category @99poojaskulal .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Thanku sir,
I will implement this and check and I will come back.

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