Arduino Vibration Motor Code, Circuit, Control (Tutorial)

In this tutorial, you’ll learn how to do Arduino Vibration Motor Control and use the Vibration Motor with Arduino to turn it ON/OFF and control the vibration strength. We’ll also create an Arduino Vibration Motor Example Project which can be a very good starting point for your Arduino Haptic Feedback project idea. Without further ado, let’s get right into it!

Table of Contents

  1. Introducing Vibration Motor
  2. Arduino Vibration Motor Circuit Diagram
  3. Arduino Vibration Motor Control Code Example
  4. Arduino Vibration Motor Strength Control
  5. Concluding Remarks

Introducing Vibration Motor

A Vibration Motor is a compact device that generates mechanical vibrations through the use of an electric motor with an unbalanced mass on its drive shaft. Primarily used in a wide range of applications to provide haptic feedback to make the user interface a lot more engaging to the end user.

Arduino-Vibration-Motor-Working-Principle

The figure above shows you the internal structure of a small Vibration Motor that’s found in cell phone devices which happens to be the same as the mini Vibration motor that we also use in various projects (with Arduino, ESP32, etc). Below is an image of the small Vibration motor that we’ll be using in this tutorial (on the left side). The image on the right side is also for the same mini vibration motor but it’s soldered on a PCB with a driver transistor control circuit to make it easier for interfacing with various microcontrollers.

Arduino-Vibration-Motor
Arduino-Vibration-Motor-Module

Vibration Motor Technical Specs

  • Rated Voltage: 1.5 – 4VDC  (3V typical)
  • Rated Current: 80mA @ 3V

Vibration Motor Applications

  • Haptic Feedback
  • Alarm Systems
  • Remote Controllers
  • Interactive HMI

Buy a Vibration Motor: you can find it here on Amazon.com


Arduino Vibration Motor Circuit Diagram

Here is the wiring diagram for the Arduino Vibration Motor control circuit using a BJT transistor as a driver switch. Note that the Vibration Motor is being driven by the BJT transistor which is taking a 5v DC from the Arduino UNO board. You can also use the 3.3v supply output pin for a weaker, but safer, drive of the vibration motor.

Arduino-Vibration-Motor-Circuit-Example

It’s highly recommended to check out this Arduino + Transistor Tutorial to learn more about how to use BJT transistors with Arduino in your projects, how to calculate the base resistor’s value, and much more.

Arduino Transistor Tutorial NPN-PNP As a Switch

This article will give more in-depth information about BJT transistors and how to use NPN/PNP transistors with Arduino to control various devices.


Arduino Vibration Motor Control Code Example

In this example project, we’ll use an Arduino + Vibration Motor with a BJT 2N3904 output driver transistor. A push button will be used to turn the Vibration Motor ON and OFF making it active as long as the button is held down.

The core logic of this application is taking the input button pin reading, and applying control signals to the BJT output driver transistor that turns ON and OFF the Vibration Motor.

Vibration Motor Wiring

The wiring diagram for this example project is shown in the previous section, scroll up and check it out. Below is an image of how the whole setup looks like at the end, ready for the test.

Arduino-Vibration-Motor-Wiring-Circuit-Example

Code Example

Here is the full code listing for this example.

Code Explanation

First of all, we define the 2 IO pins used for the Arduino-Vibration Motor BJT Transistor driver & the push button input reading.

setup()

in the setup() function, we’ll set the pinMode for the IO pins.

loop()

in the loop() function, we’ll check the button’s input pin state and enable the Vibration Motor’s driver (TIP120 BJT Transistor) as long as the button is held down (state= HIGH). When the button is released (state = LOW), we’ll get out of the while loop already and we’ll drive the motor’s output to LOW in order to turn it OFF.

TinkerCAD Simulation

Here is the simulation result for this project on the TinkerCAD simulator. You can run it as is, or make a copy, add your own code, and start running the simulation to see how it’s going to behave.

You can check this simulation project on TinkerCAD using this link.

Testing Results

Here is a demo video for testing this project on my Arduino UNO board.

❕ Note

You need to make sure that your vibration motor is fixed in place because it can easily jump out of the circuit or induce mechanical stress on its really weak leads causing them to be torn. Usually, a vibration motor is trapped in a plastic fixture or glued to a surface using super glue.


Arduino Vibration Motor Strength Control

Can I use Arduino PWM output to control the vibration strength of a vibration motor? The answer is YES, you can. Using a variable duty cycle PWM output from your Arduino board with the BJT transistor output driver will result in a variable vibration strength on the vibration motor.

Consider adding a Fly-Back Diode in parallel with your vibration motor in case you’re going to use a PWM signal to control the vibration strength. This diode will protect your output driver transistor from inductive spikes that the motor is going to generate.


Required Parts List

Here is the full components list for all the parts that you’d need to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

QTY.Component NameBuy Link
1Vibration MotorAmazon
1TIP Transistors KitAmazon
1Arduino UNO KitAmazon
1BreadBoardAmazon
1LEDs KitAmazon
1Capacitors KitAmazon Amazon
1Jumper Wires PackAmazon Amazon
19v Battery or DC Power SupplyAmazon
1Push ButtonsAmazon
1PotentiometerAmazon

Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.


Concluding Remarks

To conclude this tutorial, we can say that you can easily control a Vibration Motor with Arduino and an output driver transistor. The Vibration Motor’s vibration strength can be controlled in a variable way using a PWM signal. To learn more about Arduino PWM, it’s highly recommended that you check out this Arduino PWM Tutorial.

If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment