Skip to content

Commit 44d169b

Browse files
committed
fix #3
added AccelerometerTap code.
1 parent 17fe6fb commit 44d169b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Arduino LSM6DS3 - Accelerometer Tap
3+
4+
this is a code to detect tap
5+
via the help of acceleration Available
6+
and the direction it is in and print it on
7+
the serial monitor.
8+
9+
Made by
10+
tanmay khabia
11+
12+
*/
13+
14+
#include <Arduino_LSM6DS3.h>
15+
16+
void setup() {
17+
Serial.begin(9600);
18+
while (!Serial);
19+
20+
while (!IMU.begin()) {
21+
Serial.println("Failed to initialize IMU!");
22+
23+
delay (3000); // wait for 3 sec and check if it can be initialize again
24+
}
25+
}
26+
float tapThreshold = 0.05 ; //0.49 m/sec^2 acceleration in some direction is considered as tap. it can be change for the required sensitivity.
27+
void loop() {
28+
float x, y, z;
29+
if (IMU.accelerationAvailable()) {
30+
IMU.readAcceleration(x, y, z);
31+
if(x > tapThreshold | x < -tapThreshold)
32+
Serial.println("Tap detected across X-axis");
33+
if(y > tapThreshold | y < -tapThreshold)
34+
Serial.println("Tap detected across Y-axis");
35+
if(z > tapThreshold | z < -tapThreshold)
36+
Serial.println("Tap detected across Z-axis");
37+
}
38+
}

0 commit comments

Comments
 (0)