ESP32 and vibration sensor module

In this example we connect a vibration motor module to an ESP32 – as usual we use a Lolin32. This is the type of motor that you could find in a mobile phone which vibrates when you receive a text message for example of the usage of the motor

This is the module I bought


When the Logic level is HIGH, the motor is ON. When its LOW, the motor is OFF.

Connection

I used a Lolin32 and connected the In of the motor module to D15 – you can use another pin if you desire

Lolin32 ESP32 Vibration motor
3v3 Vcc
Gnd Gnd
D15 In

Parts List

Here are the parts I used

Part name Link
Lolin32 New ESP-32 esp32 Lite V1.0.0 For Rev1 wifi Module + bluetooth board 4MB FLASH
Vibration Motor Module PWM Vibration Motor Module DC Motor Phone Vibrator for Arduino UNO R3 MEGA2560 Electronic DIY Kit
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino

 

Code

This is a simple example which simply switches the motor on for 1 second and off for 1 second

int motorPin = D15;    // vibration motor digital pin D15
 
void setup()  
{
    pinMode(motorPin, OUTPUT );
}
 
void loop()  
{
    digitalWrite(motorPin, HIGH);
    delay(1000);
    digitalWrite(motorPin, LOW);
    delay(1000);
}

Links

 

SHARE
Previous articleESP32 and MMA8452 accelerometer example
Next articleESP32 and PCF8563 RTC module example