• 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_COIL10
// 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.

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

  • Arduino and LED Bar Display : Circuit Diagram, Code

    Here is a Guide Explaining the Basics, Circuit Diagram, Code on Arduino and LED Bar Display. LED Bar Display is Actually Like Multiple LED.

  • 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.

  • WROOM ESP32 Example Codes For IBM Watson IoT Platform

    Here Are Few WROOM ESP32 Example Codes For IBM Watson IoT Platform So That Anyone Can Get Started With Both of Them Without Huge Experience.

  • Detect Smartwatch With ESP32 on IBM Watson IoT Widget

    In our previous guide, we have shown that we can trigger ESP32 (with Arduino IDE) to send message to IBM Watson IoT in Presence of a Particular Samsung Galaxy Smartwatch. That process involves BLE and WiFi. In our one series of articles on Samsung Smartwatch as Proximity Switch, we triggered a local event, such as […]

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 (24.3K 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
Page Visits Alerts

Recent Posts

  • Advantages and Disadvantages of Ubuntu Server DistributionJune 2, 2023
  • Typography on the WebJune 2, 2023
  • How to Use JuliaMono Font in Urvanov/Crayon Syntax HighlighterJune 1, 2023
  • What Is a Sales Funnel?June 1, 2023
  • The 6G Network: 100 Times Faster than 5GMay 31, 2023

About This Article

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

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

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

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

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT