> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import vibrate from '@ohos.vibrator';
```
## Required Permissions
ohos.permission.VIBRATE
## vibrator.vibrate
vibrate(duration: number): Promise<void>
Triggers vibration with a specific duration. This method uses a promise to return the execution result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| duration | number | Yes| Vibration duration.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to indicate whether the vibration is triggered successfully.|
- Example
```
vibrator.vibrate(1000).then(()=>{
console.log("Promise returned to indicate a successful vibration.");
Stops the vibration based on the specified **stopMode**. This method uses a promise to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes| Vibration mode to stop.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to indicate whether the vibration is stopped successfully.|
Stops the vibration based on the specified **stopMode**. This method uses a callback to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes| Vibration mode to stop.|
| callback | AsyncCallback<void> | No| Callback used to indicate whether the vibration is stopped successfully.|
Console.log("Callback returned to indicate a successful stop.");
}
})
```
## EffectId
Describes the vibration effect.
| Name| Default Value| Description|
| -------- | -------- | -------- |
| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.|
## VibratorStopMode
Describes the vibration mode to stop.
| Name| Default Value| Description|
| -------- | -------- | -------- |
| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.|
| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.|