Maker Portal
Main Portal Raspberry Pi Arduino Engineering Python BLExAR
Blog Contact About Consulting Search
- All Products - New and Popular Microcontrollers Raspberry Pi Engineering Kits Internet of Things Sensors Motors + Actuators Data Acquisition Maker Tools BLExAR Resources WaWiCo
Main PortalRaspberry PiArduinoEngineeringPythonBLExAR
Maker Portal
Engineering Applications with Raspberry Pi and Arduino
Blog Shop - All Products - New and Popular Microcontrollers Raspberry Pi Engineering Kits Internet of Things Sensors Motors + Actuators Data Acquisition Maker Tools BLExAR Resources WaWiCo ContactAboutConsultingSearch

Haptic Feedback Joystick with Arduino

haptic_joystick_hand.JPG

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

Introduction
Parts List and Wiring
Haptic Joystick Code with Arduino
Conclusion

Haptics in the context of modern technology refers to the interaction between human touch and responses provided by computer interfaces in an attempt to emulate real-world stimuli. The real-world stimuli can be auditory, physical, or visual. For example, in the case of haptic vibration, a motor can provide feedback to users as they experience shaking due to driving, explosions, or physical contact while playing a video game [learn more about haptics here and here and here]. In this tutorial, we design and explore haptic vibrational feedback due to movements of an analog joystick. The Arduino platform will be used to read the analog joystick and control the response of a vibration motor shaking in the user's hand. An ESP32 D1 Mini microcontroller is selected as the microcontroller that will be programmed to control the haptic response. The ESP32 is chosen due to its fast processor, which will decrease the time delay between joystick reading and the haptic feedback response. The goal of this tutorial is to introduce users to haptic feedback and the interplay between humans and computer interfaces capable of responding to touch inputs.


Parts List and Wiring

The components used in this tutorial have been compiled into a kit for convenience, which consists of the ESP32 D1 Mini microcontroller, the analog joystick, the vibration motor, and the 3D printed handheld enclosure. We’ve also listed the components one-by-one below in the event that the user has all or most of the components already at their disposal. The component list is also followed by the wiring diagram for the tutorial.

  • Haptic Joystick Kit - $25 [Our Store]

Individual Component List:

  • ESP32 D1 Mini - $14.00 [Our Store]

  • Vibration Motor - $3.00 [Our Store]

  • Analog Joystick - $5.00 [Our Store]

  • Male-to-Female Jumper Wires - $1.20 (8pcs) [Our Store]

  • Raspberry Pi 4 Computer - $69.99 (4GB) [Amazon], $119.99 (8GB Kit) [Amazon]

Haptic Vibration Joystick Kit Haptic Vibration Joystick Kit
Sold out
Haptic Vibration Joystick Kit
$25.00

The pinout for the ESP32 D1 Mini is given below for reference, in the case that users want to change pins for the joystick or motor, or even add more sensors or motors to the project:

esp32_d1_mini_pinout.png

ESP32 D1 Mini Pinout

Image courtesy of: https://github.com/r0oland/ESP32_mini_KiCad_Library

Lastly, the wiring diagram between the ESP32 D1 Mini and the vibration motor and joystick is given below:

Screen Shot 2021-08-09 at 12.26.26 PM.png

Component Wiring Table

ESP32 + Joystick + Vibration Motor

The wiring configuration given above is used in the Arduino codes provided in the next section. Thus, any changes made to the wiring diagram will need to be implemented in the subsequent Arduino codes.


Haptic Joystick Code with Arduino

The Arduino code used in conjunction with the wiring configuration provided above can be found at the project’s GitHub page:

 
github_card.png
 

The code is also given below for reference:

/***************************************************************************
* ESP32 Haptic Joystick 
* -- using vibration motor + joystick + ESP32 D1 Mini
*
* 
*  by Josh Hrisko | Maker Portal LLC (c) 2021
* 
* 
***************************************************************************/

int joy_pins[4] = {35,34,14}; // pins being used for joystick
float bit_depth = pow(2.0,12); // ADC conversion ratio
float Rx_offset = 0.0; // offset in x-dir
float Ry_offset = 0.0; // offset in y-dir

const int buzz_pin = 2;  // corresponds to GPIO2 on ESP32

void setup(){ 
  Serial.begin(115200);
  pinMode(joy_pins[0],INPUT); // VR_x pin
  pinMode(joy_pins[1],INPUT); // VR_y pin
  pinMode(joy_pins[2],INPUT_PULLUP); // SW pin
  pinMode(buzz_pin,OUTPUT); // output for buzzer
  Serial.println("VRx,VRy,SW");
  delay(100);
  Rx_offset = float(analogRead(joy_pins[0]))/bit_depth; // calc offset
  Ry_offset = float(analogRead(joy_pins[1]))/bit_depth; // calc offset
}

void loop(){
  float Rx = float(analogRead(joy_pins[0]))/bit_depth-Rx_offset; // instantaneous x-joystick
  float Ry = float(analogRead(joy_pins[1]))/bit_depth-Ry_offset; // instantaneous y-joystick
  int   SW = digitalRead(joy_pins[2]); // instantaneous z-joystick (press down)
  Serial.print(Rx); Serial.print(","); // print for debugging (-0.45 to +0.55)
  Serial.print(Ry); Serial.print(","); // print for debugging (-0.45 to +0.55)
  Serial.println(SW); // print press (0-1)
  delay(1);

  if (Rx<-0.1){
    buzz_now(1,100,0,0); // (joystick left) buzz without delays
  } else if (Ry<-0.1){ 
    buzz_now(2,100,100,0); // (joystick down) buzz on/off equally for 100ms 
  } else if (Rx>0.1){
    buzz_now(1,600,200,0); // (joystick right) long buzz 600ms on, 200 off 
  } else if (Ry>0.1){
    buzz_now(3,80,80,150); // (joystick up) buzz with 'train' style rhythm
  } else if (SW==0){
    buzz_now(2,150,150,300); // (joystick press) heartbeat rhythm (dual buzz, with delay)
  }
}

void buzz_now(int buzz_count,int delay_1,int delay_2,int final_delay){ // buzz function
  for (int ii=0;ii<buzz_count;ii++){ // loop 
    digitalWrite(buzz_pin,HIGH); // set buzzer on
    delay(delay_1); // keep on for delay_1 [ms]
    digitalWrite(buzz_pin,LOW); // set buzz off
    delay(delay_2); // keep off for delay_2 [ms]
  }
  delay(final_delay); // final delay before restarting or moving on
}

The code does out the following:

  1. Sets the analog joystick pins as inputs (analog inputs on pins 34/35, and digital input on pin 14)

  2. Sets digital pin 2 as a digital output for the vibration motor

  3. Reads offset values from the joystick (for centering response from -0.5 to +0.5, rather than 0-1)

  4. Reads joystick inputs (Rx, Ry, SW)

  5. Excites the vibration motor based on the Rx, Ry, SW values

haptic_joystick_open.JPG

 

Haptic Responses from Joystick

Now we can test the haptic responses of the vibration motor based on the joystick movements. First, moving the joystick to the left results in a constant vibration, which we have prescribed in the function ‘buzz_now()’ - which contains the specific response of the vibration motor controlled by the ESP32 microcontroller. The following breaks down the if() statement in the loop() above, telling us what happens when the joystick is moved to given positions:

(Rx<-0.1)     buzz_now(1,100,0,0); // (joystick left) buzz without delays
 
joystick_left.png

Joystick Left ←: Constant Motor Vibration

 
(Ry<-0.1)
    buzz_now(2,100,100,0); // (joystick down) buzz on/off equally for 100ms 
 
joystick_down.png

Joystick Down ↓: 200ms delay between vibrations (~300BPM)

 
(Rx>0.1){
    buzz_now(1,600,200,0); // (joystick right) long buzz 600ms on, 200 off 
 
joystick_right.png

Joystick Right →: Heavy vibration with a short off delay

 
(Ry>0.1){
    buzz_now(3,80,80,150); // (joystick up) buzz with 'train' style rhythm
 
joystick_up.png

Joystick Up ↑: Three pulses with a train-like momentum

 
(SW==0){
    buzz_now(2,150,150,300); // (joystick press) heartbeat rhythm (dual buzz, with delay)
 
joystick_press.png

Joystick Press: Dual pulse similar to heart beat

 

These different haptic vibration feedback profiles can be customized to fit the user’s desired application, whether it relates to buzz length or buzz number or delay between buzzes - it’s completely customizable down to the resolution of the vibration motor. For the motor used here, we’re able to buzz on/off within about 50-80ms, which is likely the limit of the hardware. Delays smaller than 50ms tend to blend together as one buzz. The user may want to change the number of buzzes to relate to cardinal directions, or even change the delay between buzzes based on navigational accuracy (longer delay for further away, shorter delay for closer). There are many opportunities available to the user based on customization and desired outcome!

Below is a video demonstration of our haptic joystick for the different joystick movements. Make sure to turn on audio to hear the buzzes created by the vibration motor:


Conclusion

A vibration motor and joystick were used to create a haptic feedback device using the Arduino platform. As a response to specific changes in joystick position, we prescribed vibration motor actions corresponding to the movement of the joystick. This allowed us to create haptic vibration feedback similar to those used in video games and virtual reality systems. The goal of this tutorial was to introduce users to haptic technology that can immerse users into the digital world using physical feedback mechanisms, such as vibration. Different tunings of the vibration motor can provide users with instructions based on their input, which makes this type of application useful for enhancing digital media, as referenced above, or situations such as visually impaired navigation, feedback in auditory-restricted environments, and delivering quiet notifications to users. Haptics can be incredibly useful in emulating the real world and immersing users into scenarios that may otherwise be dangerous or difficult to experience. Vibrational haptic feedback is just one of a series of haptic mechanisms, and this tutorial was just a simple entry into a wide ranging and evolving field of human computer interaction.

Citation for This Page:
 

See More in Arduino and Engineering:

Featured
Arduino Sensor Data Logging and Visualization on iPhone
Nov 28, 2022
Arduino Sensor Data Logging and Visualization on iPhone
Nov 28, 2022
Nov 28, 2022
MakerBLE — A Tiny nRF52840 Bluetooth Arduino Board
Nov 15, 2022
MakerBLE — A Tiny nRF52840 Bluetooth Arduino Board
Nov 15, 2022
Nov 15, 2022
Haptic Feedback Joystick with Arduino
Aug 9, 2021
Haptic Feedback Joystick with Arduino
Aug 9, 2021
Aug 9, 2021
Portable GPS Tracker with Arduino
Jul 15, 2021
Portable GPS Tracker with Arduino
Jul 15, 2021
Jul 15, 2021
Bluetooth-Enabled e-Paper Display with Arduino
Jul 8, 2021
Bluetooth-Enabled e-Paper Display with Arduino
Jul 8, 2021
Jul 8, 2021
An Introduction to RFID with Arduino
Jun 27, 2021
An Introduction to RFID with Arduino
Jun 27, 2021
Jun 27, 2021
Solar Panel Characterization and Experiments with Arduino
Jun 18, 2021
Solar Panel Characterization and Experiments with Arduino
Jun 18, 2021
Jun 18, 2021
TinyBlueX - A Low Power Bluetooth Arduino Board
Apr 24, 2021
TinyBlueX - A Low Power Bluetooth Arduino Board
Apr 24, 2021
Apr 24, 2021
3 Intermediate-Level Arduino Projects to Try at Home
Feb 4, 2021
3 Intermediate-Level Arduino Projects to Try at Home
Feb 4, 2021
Feb 4, 2021
Arduino Venturi Flow Meter
Jul 25, 2020
Arduino Venturi Flow Meter
Jul 25, 2020
Jul 25, 2020
Featured
raspberry_pi_pico_handheld.JPG
sale
Raspberry Pi Pico Microcontroller
Sale Price:$6.00 Original Price:$8.00
MLX90640 Thermal Camera for Raspberry Pi (32 x 24 Pixels)
MLX90640 Thermal Camera for Raspberry Pi (32 x 24 Pixels)
from $95.00
Maker Portal Arduino-Compatible Uno Rev3 Board
sold out
Maker Portal Arduino-Compatible Uno Rev3 Board
$13.00
3.7V 600mAh LiPo Battery Kit for Arduino
3.7V 600mAh LiPo Battery Kit for Arduino
$15.00
Only 2 left in stock
I2S MEMS Microphone for Raspberry Pi (INMP441)
sold out
I2S MEMS Microphone for Raspberry Pi (INMP441)
$8.00
MFRC522 RFID Kit for Arduino
sold out
MFRC522 RFID Kit for Arduino
$18.00
Mini GPS Module for Arduino (ATGM336H + Antenna)
sold out
Mini GPS Module for Arduino (ATGM336H + Antenna)
$15.00
e-Paper Display for Arduino (1.54in, 200x200 Pixels)
sold out
e-Paper Display for Arduino (1.54in, 200x200 Pixels)
$20.00
Solar Panel Datalogger Kit for Arduino
sold out
Solar Panel Datalogger Kit for Arduino
$30.00
SSD1306 OLED Display Kit
sold out
SSD1306 OLED Display Kit
$12.00
Featured
MFRC522 RFID Kit for Arduino
sold out
MFRC522 RFID Kit for Arduino
$18.00
Solar Panel Datalogger Kit for Arduino
sold out
Solar Panel Datalogger Kit for Arduino
$30.00
venturi_tube_flow_meter_kit_all.JPG
sold out
Venturi Tube Flow Meter Kit
$75.00
NEMA 17 Stepper Motor Kit (17HS4023 + DRV8825 + Bridge)
sold out
NEMA 17 Stepper Motor Kit (17HS4023 + DRV8825 + Bridge)
$45.00
Load Cell Calibration Kit (1 kg, HX711, Calibrated Masses)
sold out
Load Cell Calibration Kit (1 kg, HX711, Calibrated Masses)
$25.00
SSD1306 OLED Display Kit
sold out
SSD1306 OLED Display Kit
$12.00
Arduino Starter Kit for Engineers (Sensor Suite)
sold out
Arduino Starter Kit for Engineers (Sensor Suite)
$32.00
Pitot Tube Airspeed Sensor for Arduino and Raspberry Pi
sold out
Pitot Tube Airspeed Sensor for Arduino and Raspberry Pi
$45.00
Solar Panel Power Metering Kit (2V/120mA)
sold out
Solar Panel Power Metering Kit (2V/120mA)
$10.00
PiCamera + Servo Camera Pan Bundle
sold out
PiCamera + Servo Camera Pan Bundle
$25.00
Arduino, EngineeringJoshua HriskoAugust 9, 2021ESP32, Arduino, Arduino Joystick, Joystick, Haptic, Haptic Feedback, Feedback, Arduino Project, Vibration, Motor, ESP32 D1 Mini, Analog Joystick, Wiring, Arduino Wiring, Arduino Code1 Comment
Facebook0 Twitter LinkedIn0 Reddit Tumblr Pinterest0 0 Likes
Previous

MakerBLE — A Tiny nRF52840 Bluetooth Arduino Board

Arduino, Electronics, BluetoothJoshua HriskoNovember 15, 2022BLE, BLExAR, Arduino BLExAR, Bluetooth, Bluetooth Low Energy, iOS Bluetooth, Arduino iOS Bluetooth, Arduino, MakerBLE
Next

Portable GPS Tracker with Arduino

Arduino, Electronics, GIS, Programming, PythonJoshua HriskoJuly 15, 2021GPS, Arduino GPS, Arduino GPS Tracker, GPS Data, GPS Tracker, GPS Tracking, TinyGPS, Arduino Python GPS, ATGM336H, Latitude, Longitude, ATSAMD21, Arduino Xiao, Xiao, SD, SD Module, SD Card, Arduino SD, Arduino SD Card, Datalogger, datalogger, Arduino Data, Arduino Data Acquisition
Maker Portal LLC
San Francisco, CA 94102,
United States
646-285-6808 engineer@makersportal.com
Hours

Explore


About Blog Shop Contact

Collaborate


Consulting Guest Post Advertise

Connect


Maker Portal LLC Copyright © 2021 | Affiliate Disclosure | Privacy Policy | Fulfillment Policy