Skip to content

Vibration functionality

The client wanted the device to give haptic feedback when an action is taken on the remote. This can be anything from pressing a button to putting the device in pairing mode.

How did we implement the feature on the hardware side?

The feature is implemented with the help of a vibration motor. The specific vibration motor we’re using can be found below: Vibration motor
Link to buy page

The other components used are: - NPN transistor - Diode - Resistor 220Ω

The transistor is used to control how much current is flowing to control the motor’s vibration intensity. The resistor helps in controlling how high the maximum current is by restricting flow to the transistor. The resistor and the middle pin of the transistor are connected to a PWM pin on the ESP32. The diode is used to protect the circuit against any power surges coming from the motor when it turns off.

How the feature is implemented in the code

The feature is implemented using the VibrationMotor class. The class keeps track of the pin the vibration motor is connected to. It also contains the vibrate() method to make the motor vibrate at a given intensity and the stopVibrating() method to make the motor stop vibrating entirely.

Vibrating in specified patterns

We thought it was a good idea to make the motor vibrate in specific patterns when a button is pressed. This would make it easier for a visually impaired person to sense what they pressed. This is done through the VibrationPattern class. This class holds the specified frames. You can pass the initialized class to the earlier mentioned vibrate() method to make the motor vibrate in that specific pattern. The way the function is implemented, the motor will vibrate in morse code.


Last update: June 21, 2023