• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » ESP32 and Coin Vibrator Motor

By Abhishek Ghosh August 7, 2021 7:24 pm Updated on August 7, 2021

ESP32 and Coin Vibrator Motor

Advertisement

Coin vibration motors or small vibration motors can be used for different purposes, such as an alert instead of a beep. A Vibration Motor Module is sold which includes the required resistors and transistors. They cost around $3-$4 per piece. 10mm and 12mm coin vibration motors are also sold as a component. If you are using the module, you can connect :

———————–
ESP32 | Vibration motor
———————–
3v3 | Vcc
———————–
Gnd | Gnd
———————–
D15 | In
———————–

Use this code :

Advertisement

---

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int motorPin = D15;  
void setup()  
{
    pinMode(motorPin, OUTPUT );
}
void loop()  
{
    digitalWrite(motorPin, HIGH);
    delay(1000);
    digitalWrite(motorPin, LOW);
    delay(1000);
}

If you use the “solo” vibration motor, then you need to connect in this way :

ESP32 and Coin Vibrator Motor

You’ll need :

BreadBoard
ESP32
Vibration Motor
Diode Rectifier – 1A 50V
Transistor – NPN BC337
1K Ohm Resistor
Jumper Wires

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Include Libraries
#include "Arduino.h"
#include "Switchable.h"
#include "VibrationMotor.h"
// Pin Definitions
#define VIBRATIONMOTOR_PIN_COIL1 0
// Global variables and defines
// object initialization
VibrationMotor vibrationMotor(VIBRATIONMOTOR_PIN_COIL1);
// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time 0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");  
    menuOption = menu();    
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
    if(menuOption == '1') {
    // Vibration Motor - Test Code
    // The vibration motor will turn on and off for 500ms (0.5 sec)
    vibrationMotor.on();     // 1. turns on
    delay(500);           // 2. waits 500ms (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    vibrationMotor.off();    // 3. turns off
    delay(500);           // 4. waits 500ms (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
    }
    
    if (millis() - time0 > timeout)
    {
        menuOption = menu();
    }
    
}
// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{
 
    Serial.println(F("\nWhich component would you like to test?"));
    Serial.println(F("(1) Vibration Motor"));
    Serial.println(F("(menu) send anything else or press on board reset button\n"));
    while (!Serial.available());
 
    // Read data from serial monitor if received
    while (Serial.available())
    {
        char c = Serial.read();
        if (isAlphaNumeric(c))
        {  
            
            if(c == '1')
     Serial.println(F("Now Testing Vibration Motor"));
            else
            {
                Serial.println(F("illegal input!"));
                return 0;
            }
            time0 = millis();
            return c;
        }
    }
}

In the above example, you need :
VibrationMotor.cpp
VibrationMotor.h
Switchable.h
Switchable.cpp

VibrationMotor.cpp :

VibrationMotor.cpp
Vim
1
2
3
4
5
6
7
#include <Arduino.h>
#include "VibrationMotor.h"
 
VibrationMotor::VibrationMotor(const int pin) : Switchable(pin)
{
}

VibrationMotor.h :

VibrationMotor.h
Vim
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _VIBRATION_MOTOR_H_
#define _VIBRATION_MOTOR_H_
 
#include "Switchable.h"
 
class VibrationMotor : public Switchable  {
 
public:
VibrationMotor(const int pin);
};
 
#endif // _VIBRATION_MOTOR_H_

Switchable.h :

Switchable.h
Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef _SWITCHABLE_H_
#define _SWITCHABLE_H_
 
//Base class for output that can be switched on/off via a single digital pin:
class Switchable  
{
public:
 
// Consturcutor accepts pin number for output
    Switchable(const int pin);
// Turn pin on
void on();
    
    // Turn pin off
void off();
// Toggle pin
void toggle();
// dim pin
void dim(int dimVal);
// Get current state
bool getState();
// Set state with bool variable
void setState(bool state);
private:
const int m_pin; //output pin
bool m_state; //current state
};
 
#endif // _SWITCHABLE_H_

Switchable.cpp

Switchable.cpp
Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Switchable.h"
#include <Arduino.h>
 
Switchable::Switchable(const int pin) : m_pin(pin)
{
    // Set pin as output
    pinMode(m_pin, OUTPUT);
    // Start state if off
off();
}
 
//turn on:
void Switchable::on()
{
digitalWrite(m_pin, 1); //high
m_state = true;
}
 
//turn off:
void Switchable::off()
{
digitalWrite(m_pin, 0); //low
m_state = false;
}
 
void Switchable::toggle()
{
digitalWrite(m_pin, !m_state); //low
m_state = !m_state;
}
 
// dim pin
void Switchable::dim(int dimVal)
{
    analogWrite(m_pin, dimVal);
}
bool Switchable::getState()
{
    return m_state;
}
 
void Switchable::setState(bool state)
{
    digitalWrite(m_pin, state);
    m_state = state;
}

I got the thing from here :

Vim
1
https://www.circuito.io/app?components=513,8449,360217

and kept it here on GitHub.

This Article Has Been Shared 700 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to ESP32 and Coin Vibrator Motor

  • ESP32 Arduino and TM1637 Seven Segment LED Display

    TM1637 Seven Segment LED Display is Popular Thing in Arduino Prototyping World. Here is Some Words About Using TM1637 With ESP32 Arduino.

  • ESP32 Arduino Built-in Hall Sensor Code & Theory

    ESP32 has a Hall Effect Sensor near pin 22. Here is ESP32 Arduino Built-in Hall Sensor Code & Theory. Here is something about Hall Effect Sensor as well.

  • ESP32 MicroPython Setup with Adafruit Ampy

    Here is ESP32 MicroPython Setup with Adafruit Ampy for Windows, MacOS X and Linux. You need Python needs to be running and install few tools.

  • How to Control Multiple Relays With Single Arduino ESP32?

    Before How to Control Multiple Relays With Single Arduino ESP32 Testing, You Need to Learn How to Create Multiple MQTT Channels & Fetch Data.

  • How to Work With Tasmota on ESP32

    Tasmota is an Open-Source firmware for ESP devices developed by Theo Arends (from the Netherlands). He is also the webmaster of a technology blog with nice tutorials. Tasmota is not written in “Arduino language”, however, you will not need to code with Tasmota. It is mostly about uploading the code, hardly changing 1-2 lines for […]

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (22.1K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Ways To Make Sure Your Online Course Outshine Others July 3, 2022
  • Will Smart Factories Become the New Assembly Line? July 2, 2022
  • The Cost of Doing Business as a Handyman July 1, 2022
  • Samsung Galaxy S22 Ultra: Long Term Review June 30, 2022
  • How to Make the Most of Your S Pen (S22 Ultra) June 29, 2022

About This Article

Cite this article as: Abhishek Ghosh, "ESP32 and Coin Vibrator Motor," in The Customize Windows, August 7, 2021, July 4, 2022, https://thecustomizewindows.com/2021/08/esp32-and-coin-vibrator-motor/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2022 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy