have a hc sr04 sensor coupled with arduino..the sensor detects distance(analog value)..now how to convert into a digital value or a count so that it can drive a vibration motor!!?
not quite sure how far you are, but you just need a loop of reading the value and then map it to 0 to 255. write the value(0 -255) to the PWM pin:
//send a trigger signal
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
//receive the trigger signal echo, and calculate cm to the object
dist= pulseIn(echo, HIGH);
dist= dist/58; //converts raw to cm, valueSensor/74/2 = inches
VibVal = map(dist, 0 80,0,255);
analogWrite(PWMpin, VibVal);
it also depends on how you are driving the vibrator.