Overview
The LSM6DS3TR is a state-of-the-art Inertial Measurement Unit (IMU) that combines a 3-axis accelerometer and a 3-axis gyroscope in a single chip. This advanced sensor can measure:
Accelerometer
- Linear acceleration (g-force)
- Tilt and orientation
- Vibration detection
- Free-fall detection
Gyroscope
- Angular velocity
- Rotation rate
- Spin detection
- Turn rate measurement
The LSM6DS3TR is used in:
- Smartphones (screen rotation, step counting)
- Drones (flight stabilization)
- Robotics (balance, navigation)
- Wearable devices (activity tracking)
- Game controllers (motion control)
- Industrial equipment (vibration monitoring)
- Satellites and CubeSats (attitude determination)
The LSM6DS3TR is pre-integrated on your Vumbua board and connected via I2C at address 0x6B. This advanced sensor gives your projects professional-grade motion sensing capabilities!
Prerequisites
Before starting this advanced lesson, make sure you have:
Completed Lessons
- Lesson 10: Ultrasonic Distance Sensor
- Lesson 11: Infrared Sensor
- Understanding of Serial Monitor and data plotting
- Basic trigonometry concepts (helpful but not required)
Hardware Requirements
- Vumbua Synapse Kit with LSM6DS3TR sensor
- USB Type-C cable for programming
- Computer with Arduino IDE installed
- LSM6DS3TR library (installation covered below)
This lesson requires the LSM6DS3TR library which is not included in the standard Arduino IDE. Follow the installation steps in the "Library Setup" section below.
Learning Objectives
By the end of this lesson, you will be able to:
- Understand IMU (Inertial Measurement Unit) technology
- Install and use the LSM6DS3TR library
- Read raw acceleration data from all three axes
- Convert raw data to g-force units
- Detect device tilt and orientation
- Calculate pitch, roll, and yaw angles
- Implement motion-activated projects
- Troubleshoot I2C communication issues
- Create advanced motion-sensing applications
What is an Inertial Measurement Unit (IMU)?
IMU Components
An IMU typically combines multiple sensors:
- Accelerometer: Measures linear acceleration (change in velocity)
- Gyroscope: Measures angular velocity (rotation rate)
- Magnetometer: Measures magnetic field (compass)
- Barometer: Measures atmospheric pressure (altitude)
The LSM6DS3TR includes accelerometer and gyroscope in one package.
Working Principle
MEMS (Micro-Electro-Mechanical Systems) technology uses microscopic structures that move in response to acceleration or rotation. These movements create electrical signals that are converted to digital readings.
Think of it as microscopic springs and masses that detect motion!
3-Axis Coordinate System
The sensor uses a right-handed coordinate system:
LSM6DS3TR Technical Specifications
Key Features
- Accelerometer Range: ±2/±4/±8/±16 g
- Accelerometer Resolution: Up to 16-bit
- Gyroscope Range: ±125/±250/±500/±1000/±2000 dps
- Gyroscope Resolution: Up to 16-bit
- Interface: I2C & SPI
- Operating Voltage: 1.71V to 3.6V
- Low Power Mode: Available
- FIFO Buffer: 3KB
- Temperature Sensor: Included
- Package: 2.5 × 3 × 0.83 mm LGA
Understanding "g" and "dps"
g (gravity): 1g = 9.81 m/s² (Earth's gravitational acceleration)
dps (degrees per second): Angular velocity measurement
The LSM6DS3TR allows you to configure:
- Output data rate (ODR) from 1.6 Hz to 6.66 kHz
- Measurement range (sensitivity)
- High-pass and low-pass filters
- Interrupt generation for specific events
- Power mode (normal/low-power)
I2C Communication Protocol
The LSM6DS3TR on your Vumbua Kit communicates via I2C (Inter-Integrated Circuit):
I2C Basics
I2C is a two-wire serial communication protocol:
- SDA (Serial Data): Data line (pin A4 on ATmega328P)
- SCL (Serial Clock): Clock line (pin A5 on ATmega328P)
- Address: Each device has a unique address
- Speed: Standard (100 kHz), Fast (400 kHz), High-speed (3.4 MHz)
LSM6DS3TR I2C Address
This 7-bit address (1101011 in binary) is hardwired into the sensor. Some LSM6DS3TR variants might use address 0x6A if the SA0 pin is pulled low.
I2C on Vumbua Kit
The Vumbua Synapse Kit has the I2C lines connected:
- SDA: Connected to ATmega328P pin A4
- SCL: Connected to ATmega328P pin A5
- Pull-up resistors: Already included on the board
- Multiple devices: Can connect additional I2C sensors
On the ATmega328P microcontroller (used in Vumbua Kit and Arduino Uno):
- Pin A4 (PC4): SDA (Serial Data Line)
- Pin A5 (PC5): SCL (Serial Clock Line)
- Internal Pull-ups: Can be enabled in software if needed
The Wire library in Arduino handles I2C communication automatically.
LSM6DS3TR Library Installation
We need to install a library to communicate with the LSM6DS3TR sensor:
Option 1: Library Manager (Recommended)
- Open Arduino IDE
- Go to Tools → Manage Libraries...
- Search for "LSM6DS3" or "STMicroelectronics"
- Install "LSM6DS3" library by STMicroelectronics
- Also install "Adafruit Unified Sensor" library if prompted
Option 2: Manual Installation
- Download the library from:
- In Arduino IDE: Sketch → Include Library → Add .ZIP Library
- Select the downloaded ZIP file
- Restart Arduino IDE
Option 3: Vumbua Custom Library
For Vumbua Synapse Kit users, we provide a simplified library:
// Download from Vumbua resources: // https://github.com/olspace/vumbua-lsm6ds3 // // Installation: // 1. Download the ZIP file // 2. In Arduino IDE: Sketch → Include Library → Add .ZIP Library // 3. Select the downloaded file // 4. Restart Arduino IDE
To verify the library is installed correctly:
- Open Arduino IDE
- Go to File → Examples
- Look for "LSM6DS3" or "Adafruit LSM6DS" in the examples list
- If you see examples, the library is installed correctly!
Hardware Setup
On the Vumbua Synapse Kit, the LSM6DS3TR is already connected. Here's how it's wired:
LSM6DS3TR Pin Connections
| LSM6DS3TR Pin | Vumbua Connection | Function |
|---|---|---|
| VDD | 3.3V | Power Supply (3.3V) |
| GND | GND | Ground |
| SCL | ATmega328P A5 | I2C Clock Line |
| SDA | ATmega328P A4 | I2C Data Line |
| SA0 | 3.3V (pulled high) | I2C Address Select (0x6B when high) |
| INT1 | Digital Pin 2 (optional) | Interrupt Output 1 |
| INT2 | Digital Pin 3 (optional) | Interrupt Output 2 |
The beauty of the Vumbua Synapse Kit is that all sensors are pre-connected. You don't need to do any wiring for this lesson - just upload your code and start reading data!
The LSM6DS3TR is connected to the I2C bus and powered by the 3.3V regulator on the Vumbua board.
Testing I2C Connection
Before proceeding, let's verify the sensor is connected and responding:
i2c_scanner.ino
/* Vumbua Synapse Kit - I2C Scanner Scan I2C bus for connected devices Should detect LSM6DS3TR at address 0x6B */ #includevoid setup() { Wire.begin(); Serial.begin(9600); Serial.println("\nI2C Scanner for Vumbua Synapse Kit"); Serial.println("================================="); Serial.println("Scanning I2C bus for devices..."); Serial.println(); } void loop() { byte error, address; int nDevices = 0; Serial.println("Scanning..."); for (address = 1; address < 127; address++) { // The i2c_scanner uses the return value of // the Write.endTransmission to see if // a device acknowledged the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) { Serial.print("0"); } Serial.print(address, HEX); Serial.print(" ("); Serial.print(address); Serial.println(" decimal)"); // Check for LSM6DS3TR if (address == 0x6B || address == 0x6A) { Serial.println(" → This is likely the LSM6DS3TR accelerometer/gyroscope!"); } nDevices++; } } if (nDevices == 0) { Serial.println("No I2C devices found\n"); } else { Serial.println("Scan complete\n"); } delay(5000); // Wait 5 seconds before next scan }
Running the I2C Scanner
- Upload the code to your Vumbua Kit
- Open Serial Monitor (Tools → Serial Monitor)
- Set baud rate to 9600
- You should see the LSM6DS3TR detected at address 0x6B
- Other I2C devices on the board might also appear
If you don't see 0x6B, try 0x6A as the sensor might use the alternate address.
Basic Accelerometer Reading
Now let's read raw acceleration data from the LSM6DS3TR:
accelerometer_basic.ino
/* Vumbua Synapse Kit - Lesson 12: Basic Accelerometer Reading Read raw acceleration data from LSM6DS3TR sensor I2C Address: 0x6B */ #include#include "LSM6DS3TR.h" // Create sensor object with I2C address 0x6B LSM6DS3TR myIMU(I2C_MODE, 0x6B); void setup() { Serial.begin(9600); Serial.println("Vumbua Synapse Kit - LSM6DS3TR Accelerometer"); Serial.println("============================================="); // Initialize the sensor if (myIMU.begin() != 0) { Serial.println("ERROR: LSM6DS3TR not detected!"); Serial.println("Please check:"); Serial.println("1. I2C connections (SDA=A4, SCL=A5)"); Serial.println("2. I2C address (try 0x6A if 0x6B fails)"); Serial.println("3. Power supply (3.3V)"); while (1); // Stop program } else { Serial.println("LSM6DS3TR initialized successfully!"); Serial.println("Move the Vumbua Kit to see acceleration values change"); Serial.println(); } // Configure sensor settings myIMU.settings.gyroEnabled = 1; // Enable gyroscope myIMU.settings.accelEnabled = 1; // Enable accelerometer myIMU.settings.accelRange = 4; // ±4g range myIMU.settings.gyroRange = 500; // ±500 dps myIMU.settings.accelSampleRate = 416; // 416 Hz myIMU.settings.gyroSampleRate = 416; // 416 Hz } void loop() { // Read acceleration data (in g units) float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); // Read gyroscope data (in dps units) float gx = myIMU.readFloatGyroX(); float gy = myIMU.readFloatGyroY(); float gz = myIMU.readFloatGyroZ(); // Read temperature float temperature = myIMU.readTempC(); // Display acceleration values Serial.print("Accel X: "); Serial.print(ax, 2); Serial.print("g | Y: "); Serial.print(ay, 2); Serial.print("g | Z: "); Serial.print(az, 2); Serial.println("g"); // Display gyroscope values Serial.print("Gyro X: "); Serial.print(gx, 1); Serial.print(" dps | Y: "); Serial.print(gy, 1); Serial.print(" dps | Z: "); Serial.print(gz, 1); Serial.println(" dps"); // Display temperature Serial.print("Temperature: "); Serial.print(temperature, 1); Serial.println("°C"); Serial.println("----------------------------------------"); delay(200); // Update 5 times per second }
Understanding the Output
Testing the Program
- Upload the code to your Vumbua Kit
- Open Serial Monitor (Tools → Serial Monitor)
- Set baud rate to 9600
- You should see acceleration and gyroscope readings
- Move the board in different directions
- Notice how the values change with movement
Expected Values
When the board is flat on a table:
- X: Approximately 0g (left-right)
- Y: Approximately 0g (forward-backward)
- Z: Approximately +1g (up-down, Earth's gravity)
If you tilt the board, the values will change accordingly.
Understanding Acceleration Values
What Do the Numbers Mean?
g-Force Units
The accelerometer measures in "g" units where:
- 1g = 9.81 m/s² (Earth's gravitational acceleration)
- 0g = No acceleration (in free fall or in space)
- +1g = Acceleration equal to Earth's gravity
- -1g = Deceleration or acceleration in opposite direction
When stationary, one axis will show approximately ±1g (pointing toward Earth).
Range Settings
The LSM6DS3TR can be configured for different ranges:
| Range Setting | Minimum Value | Maximum Value | Use Case |
|---|---|---|---|
| ±2g | -2.00g | +2.00g | High precision (0.061 mg/LSB) |
| ±4g | -4.00g | +4.00g | General purpose (default) |
| ±8g | -8.00g | +8.00g | High acceleration |
| ±16g | -16.00g | +16.00g | Extreme acceleration |
Calculating Total Acceleration
The magnitude of acceleration (ignoring direction) can be calculated:
When stationary, this should be approximately 1g (Earth's gravity).
Acceleration Visualization Program
acceleration_visualizer.ino
/* Vumbua Synapse Kit - Acceleration Visualizer Calculate and display total acceleration and vector components */ #include#include "LSM6DS3TR.h" #include LSM6DS3TR myIMU(I2C_MODE, 0x6B); void setup() { Serial.begin(115200); // Higher baud rate for more data if (myIMU.begin() != 0) { Serial.println("Sensor initialization failed!"); while (1); } Serial.println("Acceleration Visualizer Ready"); Serial.println("AX,AY,AZ,TOTAL"); // Header for Serial Plotter } void loop() { // Read acceleration float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); // Calculate total acceleration float total = sqrt(ax * ax + ay * ay + az * az); // For Serial Monitor display Serial.print("X:"); Serial.print(ax, 3); Serial.print("g Y:"); Serial.print(ay, 3); Serial.print("g Z:"); Serial.print(az, 3); Serial.print("g Total:"); Serial.print(total, 3); Serial.println("g"); // For Serial Plotter (Tools → Serial Plotter) // Uncomment for graphing: // Serial.print(ax); Serial.print(","); // Serial.print(ay); Serial.print(","); // Serial.print(az); Serial.print(","); // Serial.println(total); delay(50); // 20 Hz update rate }
Arduino IDE includes a Serial Plotter (Tools → Serial Plotter) that can graph multiple values in real-time. Uncomment the last few lines in the loop() function to see a beautiful graph of your acceleration data!
Tilt Detection and Orientation
One of the most useful applications of an accelerometer is detecting tilt/orientation:
tilt_detector.ino
/* Vumbua Synapse Kit - Tilt Detector Calculate pitch and roll angles from accelerometer data */ #include#include "LSM6DS3TR.h" #include LSM6DS3TR myIMU(I2C_MODE, 0x6B); // Function to convert radians to degrees float radToDeg(float radians) { return radians * 180.0 / PI; } void setup() { Serial.begin(9600); if (myIMU.begin() != 0) { Serial.println("Sensor initialization failed!"); while (1); } Serial.println("Vumbua Tilt Detector"); Serial.println("===================="); Serial.println("Tilt the board to see pitch and roll angles change"); Serial.println(); } void loop() { // Read acceleration float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); // Calculate pitch (rotation around X-axis) // Pitch: forward/backward tilt float pitch = atan2(-ax, sqrt(ay * ay + az * az)); // Calculate roll (rotation around Y-axis) // Roll: left/right tilt float roll = atan2(ay, az); // Convert to degrees pitch = radToDeg(pitch); roll = radToDeg(roll); // Determine orientation String orientation = "Unknown"; if (abs(pitch) < 15 && abs(roll) < 15) { if (az > 0.8) { orientation = "Flat (face up)"; } else if (az < -0.8) { orientation = "Flat (face down)"; } } else if (pitch > 45) { orientation = "Tilted Forward"; } else if (pitch < -45) { orientation = "Tilted Backward"; } else if (roll > 45) { orientation = "Tilted Right"; } else if (roll < -45) { orientation = "Tilted Left"; } // Display results Serial.print("Pitch: "); Serial.print(pitch, 1); Serial.print("° | Roll: "); Serial.print(roll, 1); Serial.print("° | Orientation: "); Serial.println(orientation); // Simple visual indicator int pitchBars = map(int(pitch), -90, 90, 0, 20); int rollBars = map(int(roll), -90, 90, 0, 20); Serial.print("Pitch: ["); for (int i = 0; i < 20; i++) { Serial.print(i == pitchBars ? "|" : "-"); } Serial.print("] Roll: ["); for (int i = 0; i < 20; i++) { Serial.print(i == rollBars ? "|" : "-"); } Serial.println("]"); delay(200); }
Understanding Pitch and Roll
Pitch: Rotation around the X-axis (forward/backward tilt)
Roll: Rotation around the Y-axis (left/right tilt)
Yaw: Rotation around the Z-axis (compass direction) - requires magnetometer
The accelerometer can only measure pitch and roll accurately when stationary. For yaw and dynamic motion, you need the gyroscope or a magnetometer.
Testing Tilt Detection
- Upload the tilt detector code
- Place the Vumbua Kit flat on a table
- Slowly tilt it forward (pitch should increase)
- Tilt it backward (pitch should decrease)
- Tilt it left (roll should decrease)
- Tilt it right (roll should increase)
The orientation text should update as you move the board.
Complete Orientation Detection
Combine accelerometer and gyroscope for better orientation tracking:
orientation_tracker.ino
/* Vumbua Synapse Kit - Orientation Tracker Complementary filter combining accelerometer and gyroscope */ #include#include "LSM6DS3TR.h" #include LSM6DS3TR myIMU(I2C_MODE, 0x6B); // Variables for complementary filter float pitch = 0, roll = 0; float gyroAngleX = 0, gyroAngleY = 0; unsigned long lastTime = 0; // Complementary filter constant (0-1) // Closer to 1 = trust accelerometer more // Closer to 0 = trust gyroscope more const float alpha = 0.98; float radToDeg(float radians) { return radians * 180.0 / PI; } void setup() { Serial.begin(115200); if (myIMU.begin() != 0) { Serial.println("Sensor initialization failed!"); while (1); } // Configure for high performance myIMU.settings.gyroEnabled = 1; myIMU.settings.accelEnabled = 1; myIMU.settings.accelRange = 4; myIMU.settings.gyroRange = 500; myIMU.settings.accelSampleRate = 104; myIMU.settings.gyroSampleRate = 104; lastTime = millis(); Serial.println("Vumbua Orientation Tracker Ready"); } void loop() { // Calculate time difference unsigned long currentTime = millis(); float dt = (currentTime - lastTime) / 1000.0; // in seconds lastTime = currentTime; // Read sensor data float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); float gx = myIMU.readFloatGyroX(); float gy = myIMU.readFloatGyroY(); float gz = myIMU.readFloatGyroZ(); // Calculate angles from accelerometer (in radians) float accelPitch = atan2(-ax, sqrt(ay * ay + az * az)); float accelRoll = atan2(ay, az); // Convert to degrees accelPitch = radToDeg(accelPitch); accelRoll = radToDeg(accelRoll); // Calculate angles from gyroscope (integration) gyroAngleX += gx * dt; // Pitch from gyro gyroAngleY += gy * dt; // Roll from gyro // Complementary filter: combine accelerometer and gyroscope pitch = alpha * (pitch + gx * dt) + (1 - alpha) * accelPitch; roll = alpha * (roll + gy * dt) + (1 - alpha) * accelRoll; // Display results Serial.print("Accel Pitch: "); Serial.print(accelPitch, 1); Serial.print("° | Gyro Pitch: "); Serial.print(gyroAngleX, 1); Serial.print("° | Filtered: "); Serial.print(pitch, 1); Serial.println("°"); // Optional: Send to Serial Plotter // Serial.print(accelPitch); Serial.print(","); // Serial.print(gyroAngleX); Serial.print(","); // Serial.println(pitch); // Small delay for stability delay(10); // ~100 Hz update rate }
A complementary filter combines the strengths of both sensors:
- Accelerometer: Accurate for static tilt, but noisy during movement
- Gyroscope: Accurate for dynamic motion, but drifts over time
By combining them with the formula:
angle = α × (gyro_angle) + (1-α) × (accel_angle)
We get stable, accurate orientation tracking.
Advanced LSM6DS3TR Features
The LSM6DS3TR has several advanced features you can explore:
FIFO Buffer
The 3KB FIFO (First In, First Out) buffer allows:
- Storing up to 1,024 accelerometer samples
- Storing up to 512 gyroscope samples
- Batching data for power-efficient reading
- Watermark interrupts when buffer is half-full
Perfect for data logging applications!
Interrupt Generation
The sensor can generate interrupts for:
- Free-fall detection
- Wake-up on motion
- Single/double tap detection
- 6D/4D orientation detection
- FIFO watermark/threshold
Connect INT1 or INT2 to Arduino interrupt pins for event-driven programming.
Pedometer and Step Counter
Built-in pedometer functionality:
- Automatic step detection and counting
- Step frequency estimation
- Embedded step algorithm
- Low-power mode for wearables
Perfect for fitness tracker projects!
Example: Tap Detection
tap_detector.ino
/* Vumbua Synapse Kit - Tap Detection Example Detect single and double taps using LSM6DS3TR */ #include#include "LSM6DS3TR.h" LSM6DS3TR myIMU(I2C_MODE, 0x6B); unsigned long lastTapTime = 0; int tapCount = 0; void setup() { Serial.begin(9600); if (myIMU.begin() != 0) { Serial.println("Sensor initialization failed!"); while (1); } // Configure for tap detection // Note: Actual tap configuration requires low-level register access // This example uses threshold-based software detection Serial.println("Tap Detector Ready"); Serial.println("Tap the Vumbua Kit gently"); } void loop() { static float lastAccel = 0; static bool tapDetected = false; float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); // Calculate total acceleration change float totalAccel = sqrt(ax * ax + ay * ay + az * az); float accelChange = abs(totalAccel - lastAccel); lastAccel = totalAccel; // Simple tap detection based on acceleration change if (accelChange > 0.5 && !tapDetected) { // Threshold for tap tapDetected = true; unsigned long currentTime = millis(); if (currentTime - lastTapTime < 500) { // 500ms window for double tap tapCount++; if (tapCount == 2) { Serial.println("DOUBLE TAP DETECTED!"); tapCount = 0; } } else { tapCount = 1; Serial.println("Single tap detected"); } lastTapTime = currentTime; // Debounce: ignore new taps for 100ms delay(100); tapDetected = false; } delay(10); }
Practical Project Ideas
Motion-Controlled Game
Create a simple game where you control an on-screen object by tilting the Vumbua Kit.
- Use pitch and roll to control movement
- Detect shakes for special actions
- Send data to Processing or p5.js
Step Counter
Build a DIY pedometer that counts your steps.
- Detect walking/running patterns
- Count steps accurately
- Calculate approximate distance
- Display on LCD or Serial Monitor
Self-Balancing Robot
Use the LSM6DS3TR as the "inner ear" for a balancing robot.
- Measure tilt angle
- Implement PID control
- Control motors to maintain balance
- Advanced robotics project
CubeSat Attitude Simulator
Simulate satellite attitude determination and control.
- Detect orientation in 3D space
- Simulate reaction wheel control
- Display attitude on computer
- Educational space technology demo
Project: Motion-Activated Security System
motion_security.ino
/* Vumbua Synapse Kit - Motion-Activated Security System Detects unauthorized movement and triggers alarm */ #include#include "LSM6DS3TR.h" LSM6DS3TR myIMU(I2C_MODE, 0x6B); const int buzzerPin = 3; const int ledPin = 9; const int buttonPin = 2; bool systemArmed = false; bool alarmTriggered = false; float baseAccel = 0; void setup() { Serial.begin(9600); pinMode(buzzerPin, OUTPUT); pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); if (myIMU.begin() != 0) { Serial.println("Sensor initialization failed!"); while (1); } Serial.println("Motion Security System"); Serial.println("Press button to arm/disarm"); // Calibrate baseline acceleration calibrateSensor(); } void calibrateSensor() { Serial.println("Calibrating... Do not move the device."); float sum = 0; for (int i = 0; i < 100; i++) { float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); sum += sqrt(ax * ax + ay * ay + az * az); delay(10); } baseAccel = sum / 100; Serial.print("Baseline acceleration: "); Serial.print(baseAccel, 3); Serial.println("g"); } void loop() { // Check arm/disarm button if (digitalRead(buttonPin) == LOW) { delay(50); // Debounce if (digitalRead(buttonPin) == LOW) { systemArmed = !systemArmed; if (systemArmed) { Serial.println("System ARMED"); digitalWrite(ledPin, HIGH); calibrateSensor(); // Recalibrate when arming } else { Serial.println("System DISARMED"); digitalWrite(ledPin, LOW); alarmTriggered = false; noTone(buzzerPin); } while (digitalRead(buttonPin) == LOW); // Wait for release } } // If system is armed, monitor for motion if (systemArmed && !alarmTriggered) { float ax = myIMU.readFloatAccelX(); float ay = myIMU.readFloatAccelY(); float az = myIMU.readFloatAccelZ(); float currentAccel = sqrt(ax * ax + ay * ay + az * az); float deviation = abs(currentAccel - baseAccel); if (deviation > 0.1) { // Motion threshold Serial.println("MOTION DETECTED! ALARM!"); alarmTriggered = true; } } // Trigger alarm if motion detected if (alarmTriggered) { tone(buzzerPin, 1000); delay(100); tone(buzzerPin, 1500); delay(100); } delay(50); }
Troubleshooting Common Issues
- Solution 1: Run the I2C scanner to check address (0x6B or 0x6A)
- Solution 2: Check I2C connections (SDA=A4, SCL=A5 on Vumbua)
- Solution 3: Ensure proper power (3.3V, not 5V)
- Solution 4: Add pull-up resistors (4.7kΩ) if not already present
- Solution 5: Try lower I2C speed:
Wire.setClock(100000);
- Check: Board orientation (Z-axis should show ~1g when flat)
- Verify: Range setting matches your expected values (±2g, ±4g, etc.)
- Calibrate: Run calibration routine to establish baseline
- Test: Rotate board 90° - values should change appropriately
- Consider: Sensor might need recalibration after temperature changes
- Solution 1: Apply software filtering (moving average)
- Solution 2: Reduce output data rate (ODR) for less noise
- Solution 3: Enable built-in low-pass filter in sensor settings
- Solution 4: Ensure stable power supply (add decoupling capacitor)
- Solution 5: Keep away from vibration sources
- Error: "LSM6DS3TR.h: No such file or directory"
- Solution: Install the LSM6DS3TR library (see Library Setup section)
- Alternative: Use Adafruit LSM6DS library instead
- Check: Library is in correct Arduino libraries folder
- Try: Restart Arduino IDE after library installation
Video Demonstration
Advanced Motion Sensing Tutorial
Watch how the LSM6DS3TR accelerometer/gyroscope works in action.
See real-world applications and advanced motion tracking techniques.
Subscribe to OLSPACE🎉 Course Completion! 🎉
Congratulations! You've Completed the Vumbua Synapse Kit Course!
You've successfully mastered all 12 lessons and can now:
Understand Electronics
From basic circuits to advanced sensors
Write Complex Code
Arduino programming for real-world applications
Build Advanced Projects
Create professional-grade IoT and robotics projects
You're now ready for advanced projects like:
- CubeSat Development: Apply your skills to space technology
- Robotics: Build autonomous robots with sensor fusion
- IoT Systems: Create smart devices with wireless communication
- Research Projects: Conduct scientific experiments with precise measurements
- Teaching Others: Share your knowledge with the next generation
Resources & Downloads
Download Complete Code
Get all the code files for this lesson: