11/*
2- Arduino LSM6DS3 - Accelerometer Tap
2+ Arduino LSM6DS3 - Accelerometer Tap
33
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.
4+ this code is to detect tap
85
9- Made by
10- tanmay khabia
6+ usign IMU.accelerationAvailable()
7+
8+ Made by
9+ tanmay khabia
1110
1211*/
1312
1413#include < Arduino_LSM6DS3.h>
1514
1615void setup () {
1716 Serial.begin (9600 );
17+
1818 while (!Serial);
1919
2020 while (!IMU.begin ()) {
21+
2122 Serial.println (" Failed to initialize IMU!" );
2223
2324 delay (3000 ); // wait for 3 sec and check if it can be initialize again
25+
2426 }
27+
2528}
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.
29+
30+ float tapThreshold = 0.05 ; // 0.05g acceleration in some direction is considered as tap. it can be change for the required sensitivity.
31+
2732void loop () {
33+
2834 float x, y, z;
35+
2936 if (IMU.accelerationAvailable ()) {
37+
3038 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" );
39+
40+ if (x > tapThreshold || x < -tapThreshold) {
41+
42+ Serial.println (" Tap detected across X-axis" );
43+ }
44+ if (y > tapThreshold || y < -tapThreshold) {
45+
46+ Serial.println (" Tap detected across Y-axis" );
47+ }
48+ if (z > tapThreshold || z < -tapThreshold) {
49+
50+ Serial.println (" Tap detected across Z-axis" );
51+ }
3752 }
38- }
53+
54+ }
0 commit comments