Example Code for Arduino-Contorl the Module by the Switch
This article guides readers through controlling a micro vibration module with Arduino, featuring operating principles, wiring diagrams, and sample code for PWM signal management.
Tutorial
- Introduce the operating priciples of the vibration module.
- Introduce control mode of the micro vibration module by simple examples and pictures.(high level work, low level stop).
- Control the module vibration intensity by the PWM signal.
Hardware Preparation
- DFRduino UNO x1
- The Micro Vibration Module x1
- Digital Push Button DFR0029-Y X1
- Dupont
Software Preparation
- Arduino IDE Click to download Arduino IDE
Operating Priciples
The vibration module uses the vibration motor as exciting vibration source, a set of adjustable eccentric block is installed in the end of rotor shaft, then we can ger the centrifugal force generated by high speed rotation of the shaft and eccentric block.
Wiring Diagram

Sample Code
/***************************************************
* Vibration
* ****************************************************
* This example shows that the module will shake /vibrate 5S when we press the button
* @author Dongzi([email protected])
* @version V1.0
* @date 2016-5-26
* All above must be included in any redistribution
* ****************************************************/
const int buttonPin = 8; // the number of the pushbutton pin
const int VibPin = 13; // the number of the Vibration Module pin
int key=0;
void setup()
{
pinMode(VibPin,OUTPUT); // Set the digital pin(11) as output
pinMode(buttonPin, INPUT); // Set the digital pin(8) as input
}
void loop()
{
key=digitalRead(buttonPin);
if(key==LOW)
{
digitalWrite(VibPin,HIGH); //Turn on the Vibration Module
delay(5000); //Waits for 5 seconds
digitalWrite(VibPin,LOW); //Turn off the Vibration Module
}
else
digitalWrite(VibPin,LOW); //Turn off the Vibration Module
// put your main code here, to run repeatedly:
}
Results
when the button of 8 pin is pressed, the vibration module can work for 5 seconds, then stop and wait for pushing the button again
Was this article helpful?
