In this lesson, we will use vibration sensors to feel vibrations.
After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.
Connect the buzzer module to P0 and vibration switch module to D1. Then connect the VCC and GND to 3.3V and GND respectively. The vibration sensor is used to sense the magnitude of the vibration force.
Create a variable named vibVal by clicking Create variable under the Variables category.
The reading of vibration sensor is assigned to the variable vibVal and then is printed on the Debug Monitor via print block.
Set a judgment condition by if do block. If vibVal is equal to 0, let the buzzer sound. You can modify the buzzer’s note and beat yourself.
Go to the Simulation page and click on the Run button. Long press the vibration switch module, and you will see that the vibration switch has litter effect. Now save your project, connect the Bluetooth and click Flash to compile and download the code.