Skip to content

Sprint 3

What is a vibration motor?

What does a vibration motor do?

Vibration motors are electronic devices that provide vibration capabilities to devices. This can be used to provide haptic feedback to a device.

How do I control a vibration motor?

Vibration motors vibrate depending on the voltage being provided. Simple Arduino vibration modules have 3 pins. One ground pin, one power pin and one IN pin. The IN pin is used to control whether the motor is supposed to be vibrating. By connecting the IN pin to a PWM pin, you can control the intensity of the vibrations.

What is a vibration motor
Vibration motor control
Interfacing with a vibration motor

Where can we get a vibration motor?

Miguel’s support desk

Unfortunately, when I asked whether Miguel had any vibration motors, he told me he did not. So we went looking for one on our own, which led me to the next section.

The webshops specified on the dlo

This section is referring to this announcement on the dlo and the webshops specified therein.

Because we’re working with development boards, I thought it may be good to get a development motor like the one I found on Conrad which already contains most of the electronic circuitry required to operate a vibration motor. It costs € 3,29.

An alternative would be this 5 pack that I found on Conrad. Getting this pack would require us to get additional components such as a transistor and a diode. The pack costs € 8,99.

Another alternative would be to get this vibration motor module from TinyTronics. This module is very similar to to the first module, the downside is that it may take longer to arrive than if I were to order at Conrad. The module costs €3,00.

Conclusion

According to the documentation for our development board, there is 25.25mm of space between the pins, whereas the vibration motor module is 22mm in width. It should therefore be possible to place the motor under the PCB. This allows for the addition of the module without the need for the case and/or PCB to be changed.


What are PWM pins?

What does PWM stand for?

PWM stands for Pulse Width Modulation, what this means is that the electronic signal/current that these pins output can be changed. The output can be changed to be of a lower frequency or a higher frequency and can in this way provide more or less power to a device programmatically.

What are PWM pins used for?

PWM pins are mostly used for changing the intensity of an electronic component. Think of an led light that can be set to a higher or lower brightness by changing the output of the PWM pin. With the Vibration motor, we can implement the same concept. It will vibrate more if a higher value is being released from the PWM pin and it will vibrate less if a lower value is being sent from the PWM pin.

Example code of how to control PWM pins

This code demonstrates the use of analogWrite(). According to the value of the potentiometer 1 of evive, the brightness of the LED is controlled.

int LEDPin = 13;   // LED connected to digital pin 13
int PotPin = A9;   // Potentiometer connected to analog pin A9
int val;           // variable to store the read value

void setup() {
  pinMode(LEDPin, OUTPUT);
}

void loop() {
  val = analogRead(PotPin);     // Read the value of voltage from potentiometer
  val = val/4;   //this maps the analog values of potentiometer that range from 0-1023 to values 0-255 for giving analog output at pwm pins. 
  analogWrite(LEDPin, val);   // Sets the brightness according to potentiometer state
  delay(50);
}

Explanation about PWM pins


What is an NPN transistor?

Introduction

While I was researching how to connect a vibration motor to out ESP32 development board, a lot of tutorials used an electronic component called a NPN transistor. While I had heard the name before, I realized I didn’t actually know what it is or does. It would therefore, before trying to use an NPN transistor, be prudent to know what it is.

What is it?

An NPN transistor is an electronic component that controls current flow and is capable of amplifying current or acting as a switch.
An NPN transistor has 3 pins: a collector pin which is where you let the main current enter the transistor, a emitter pin which is the transistor’s output and a base pin which controls the current flowing out of the emitter pin.

When using an NPN transistor as a switch, it can be in 2 states: on or off. Either letting current through, or not letting it through.

Using an NPN transistor as an amplifier is basically using it as a switch. There’s one key difference: the current going through the transistor is of a higher voltage than the current flowing into the base pin that is controlling the resistance value of the transistor. This makes them particularly useful for use with our vibration motor, as that needs 5V to work and the ESP32 outputs at 3.3V. It does this by acting like a sort of valve for a larger power supply, with the current going into the base pin, you change how much current is let through, effectively amplifying the current when opened to a certain degree.

Transistor explanation


How do I control PWM pins on the ESP32?

In my initial research about PWM pins, I did research on the Arduino analogue pin methods. After some experimentation, I found out that these methods don’t work on ESP32 boards. This meant that I had to look for an alternative.

What can I use to control PWM pins on ESP32 boards?

After doing a bit of research, I came across a built-in ESP32 library called ledc. The library allows you to set specific PWM channels driving one or multiple pins. It then allows you to set the output values of those channels using the ledcWrite(). This is largely the same as the Arduino analogWrite() method. With help from the ledc documentation and a tutorial I found here, I wrote some code that is able to control PWM pins using the ledc library.

First I had to call the ledcSetup() and ledcAttachPin() methods to initialize the PWM channel and attach the PWM pin to the channel. Code initializing the PWM channel

VibrationMotor(uint8_t pwmPin, uint8_t channel) {
    ledcSetup(channel, DEFAULT_PWM_FREQUENCY, DEFAULT_PWM_RESOLUTION);
    ledcAttachPin(pwmPin, channel);
    this->pwmChannel = channel;
    this->vibrating = false;
}

Then I had to call ledcWrite() to make the PWM channel output the required value.

Makes the motor vibrate

void vibrate(int intensity) {
    ledcWrite(this->pwmChannel, intensity);
    this->vibrating = true;
}

Stops the motor from vibrating

void stopVibrating() {
    ledcWrite(this->pwmChannel, LOW);
    this->vibrating = false;
}

What is a diode?

A diode is an electronic component that allows current to easily flow in one direction but restricts flow in the other. This means that it can be used to create looping circuits. The two sides of a diode are called the anode (positive) and cathode (negative), these different sides create polarity in circuits. Most diodes only allow current flow when a positive voltage is applied to the anode. The diode can be considered a one way gateway for current. A diode is also known as a rectifier because they change alternating current (AC) into direct current (DC).

There’s 2 types of diodes: forward biased and reverse biased. A forward biased diode allows for current to flow. A reverse based diode acts as an insulator, blocking current flow.

What are diodes commonly used for?

A common use for diodes is the Light emitting diode, also known as an LED. This is what is making the led’s in our kit work.
Another well known use for diodes is in power conversion. Diodes are commonly used in rectifier circuits, converting AC (alternating current) to DC (direct current).
Diodes are also used for power surge protection. When used as surge protection, a diode is non conductive but will immediately short any voltage spikes to ground.

Diode explanation
Diode usages explanation

How do I represent the numbers 1, 2, 3, 4 and 5 in morse code?

Because, we’re making a product for visually impaired people. We thought it was a good idea to make the remote vibrate in morse code. This would allow the user to immediately know what button they have pressed. I have researched what each number translates to in international morse-code. In the final product, I will represent the dots with short vibrations and the dashes using longer vibrations. The dashes will last at least 2x longer than a dot.

One in morse code

. _ _ _ _

Two in morse code

. . _ _ _

Three in morse code

. . . _ _

Four in morse code

. . . . _

Five in morse code

. . . . .

Morse code chart

Morse code explanation and cheat sheet


Last update: June 20, 2023