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
Name | Link | |
ESP32 | ||
Vibration Motor Module | ||
Connecting cables |
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