Arduino micro vibration motor | Arduino vibration motor code, interfacing
Table of Contents
Micro Vibration Motor Description:
In this tutorial, you will learn how to use a micro vibration motor with Arduino. For the best understanding, a variable resistor will be used to control the vibration motor. by rotating the knob of the variable resistor the vibration can be increased and decreased. Without any further delay, let’s get started!!!!!
Amazon Links:
Arduino Nano USB-C Type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
Micro Vibration Motor:
This is the micro vibration motor, as you can see it has two wires red and black. Red is the positive wire while black is the ground wire. The working voltage of the vibration motor is 2 to 5 volts.. The rated voltage is 3.7 volts and the current is .07 amps which is equal to 70milli amps. As you can see the vibration motor has small thin wires due to which it’s really hard to interface this with the Arduino, so I decided to fix the vibration motor on a small PCB board.
as you can see the two wires are soldered and now it can be easily interfaced with the Arduino. the red wire is the positive and the blue wire is the ground.
Interfacing of the Vibration Motor and Variable Resistor with Arduino:
Connect the middle leg of the variable resistor with analog pin A1 of the Arduino…
now connect the grey wire with the ground…
connect the red wire with the 5v…
connect the red wire of the vibration motor with pin number 5 which is the PWM pin of the Arduino…
connect the blue wire with the Arduino’s ground….
Now we will use this variable resistor to control the vibration of the micro vibration motor.
Micro Vibration Motor Arduino Programming:
The micro-vibration motor programming is really simple
1 2 |
int mvm = 5; // micro vibration motor is connected with pin number 5 which is the pwm pin. int vresistor = A1; |
the variable resistor is connected with the analog pin A1 of the Arduino.
1 |
int data = 0; |
As you know my friends every Arduino and Mega program has at least two functions, which are the void setup and void loop functions. Void means that these functions are not returning any values while the empty parenthesis means that these functions are not taking any arguments as the input.
1 |
void setup() { |
// put your setup code here, to run once:
pinMode is a builtin function and it takes two arguments as the input, the pin number or pin name and the status which can be input or output. as micro vibration motor is the output device so that’s why we set it to output. while the variable resistor is set to input
1 2 3 4 5 6 7 8 9 |
pinMode(mvm, OUTPUT); pinMode(vresistor, INPUT); } void loop() { // put your main code here, to run repeatedly: data = analogRead(vresistor); |
reads the variable resistor and store the value in variable data. Then using the map function we limit the maximum value to 255, and store the mapped value in data. Then using the analogwrite function we send the value stored in variable data to the pwm which is pin number 5 and its name is mvm.
1 2 3 4 |
data = map(data, 0, 1023, 0,255); analogWrite(mvm, data); } |