Detect Fall

Note

🌟 Welcome to the SunFounder Facebook Community! Whether you’re into Raspberry Pi, Arduino, or ESP32, you’ll find inspiration, help ideas here.

  • ✅ Be the first to get free learning resources.

  • ✅ Stay updated on new products & exclusive giveaways.

  • ✅ Share your creations and get real feedback.

  • 👉 Need faster updates or support? Click [here] join our Facebook community

  • 👉 Or join our WhatsApp group: Click [here]

Kit purchase

Looking for parts? Check out our all-in-one kits below — packed with components, beginner-friendly guides, and tons of fun.

../_images/elite_explore_kit.png

Name

Includes Arduino board

PURCHASE LINK

Ultimate Sensor Kit

Arduino Uno R4 Minima

BUY

Elite Explorer Kit

Arduino Uno R4 WiFi

BUY

3 in 1 Ultimate Starter Kit

Arduino Uno R4 Minima

BUY

Universal Maker Sensor Kit

×

BUY

Course Introduction

In this lesson, you’ll learn how to use the MPU6050 sensor with the Arduino to build a simple tilt detection system.

When the device is tilted beyond a set threshold, an LED lights up and a buzzer sounds, providing a quick visual and audio alert.

Note

If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.

Required Components

In this project, we need the following components:

SN

COMPONENT INTRODUCTION

QUANTITY

PURCHASE LINK

1

Arduino UNO R4 Minima/Arduino UNO R4 WIFI

1

BUY

2

USB Type-C cable

1

3

Breadboard

1

BUY

4

Wires

Several

BUY

5

220Ω resistor

1

BUY

6

LED

1

BUY

7

MPU6050 Module

1

BUY

8

Active Buzzer

1

Wiring

../_images/detect_falling_bb.png

Common Connections:

  • LED

    • Connect the LED anode to a 1kΩ resistor then to the negative power bus on the breadboard, and the LED cathode to 8 on the Arduino.

  • MPU6050

    • SDA: Connect to A4 on the Arduino.

    • SCL: Connect to A5 on the Arduino.

    • GND: Connect to breadboard’s negative power bus.

    • VCC: Connect to breadboard’s red power bus.

  • Active Buzzer

    • Connect to breadboard’s negative power bus.

    • Connect to 9 on the Arduino.

Writing the Code

Note

  • You can copy this code into Arduino IDE.

  • To install the library, use the Arduino Library Manager and search for MPU6050 and install it.

  • Don’t forget to select the board(Arduino UNO R3) and the correct port before clicking the Upload button.

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

const int LED_PIN = 8;
const int BUZZER_PIN = 9;

// Threshold angle (adjustable)
const float TILT_THRESHOLD = 45.0;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();

  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed!");
    while (1);
  }

  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  Serial.println("Tilt detection system ready!");
}

void loop() {
  // Get acceleration data
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);

  // Convert acceleration to angles (simple approximation)
  float angleX = atan2(ay, az) * 180 / PI;
  float angleY = atan2(ax, az) * 180 / PI;

  Serial.print("AngleX: "); Serial.print(angleX);
  Serial.print("  AngleY: "); Serial.println(angleY);

  // Check tilt
  if (abs(angleX) > TILT_THRESHOLD || abs(angleY) > TILT_THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  }

  delay(200);
}