Haptic Motor Driver Hook-Up Guide

Pages
Contributors: LightningHawk
Favorited Favorite 5

PWM & Analog Input Mode Example: Light Vibes

In this example project, we are going to control an ERM motor based on analog input from a photocell that gets mapped to a range from 0-255 and uses that result to set the pulse width modulation of an output pin connected to the IN/TRIG pin on the Haptic Motor Driver. This project will give haptic effects based on the amount of ambient light in an area.

alt text

Waving your hand over the photoresistor turns off the motor, and, when you move your hand away, you can feel the ramping effects as the PWM signal increases with the amount of light detected.

Parts Needed

In addition to the basics like hook-up wire, you'll also need the following parts:

SparkFun RedBoard - Programmed with Arduino

SparkFun RedBoard - Programmed with Arduino

DEV-13975
$19.95
47
Vibration Motor

Vibration Motor

ROB-08449
$2.15
12
Mini Photocell

Mini Photocell

SEN-09088
$1.50
7
SparkFun Haptic Motor Driver - DRV2605L

SparkFun Haptic Motor Driver - DRV2605L

ROB-14538
$8.50
Resistor 10K Ohm 1/4 Watt PTH - 20 pack (Thick Leads)

Resistor 10K Ohm 1/4 Watt PTH - 20 pack (Thick Leads)

PRT-14491
$1.20

The Circuit

alt text

Arduino Sketch

language:c
// Control the vibration of an ERM motor
// using PWM and a photoresistor. 

#include <Sparkfun_DRV2605L.h>
#include <Wire.h>

SFE_HMD_DRV2605L HMD;
const int analogInPin = A0;  // Analog input pin that the sensor is attached to
const int analogOutPin = 9; // Analog output pin that the Haptic Motor Driver is attached to

int sensorValue = 0;        // value read from the sensor
int outputValue = 0;        // value output to the PWM (analog out)


void setup() 
{
  HMD.begin();
  Serial.begin(9600);
  HMD.Mode(0x03); //PWM INPUT 
  HMD.MotorSelect(0x0A);
  HMD.Library(7); //change to 6 for LRA motors 

}
void loop() 
{

 // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the serial monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
 }