Tekko BDSimSimulatorProjects

MPU6050 টিল্ট কন্ট্রোলার (৪টা LED দিক দেখায়)MPU6050 tilt controller (4 LEDs show the direction)

▶ ফ্রি চালিয়ে দেখো / Run it free Parts অর্ডার করো (WhatsApp)

সার্কিট ডায়াগ্রাম · Circuit diagram

MPU6050 tilt controller (4 LEDs show the direction) circuit diagram — Arduino Uno, Motion sensor MPU6050 (GY-521), Resistor 220Ω, LED (green), LED (yellow), LED (red), LED (blue), Jumper wires

যা যা লাগবে · Parts you need

তার লাগানো · Wiring

Motion sensor MPU6050 (GY-521) VCC→Arduino Uno 5V
Motion sensor MPU6050 (GY-521) GND→Arduino Uno GND
Motion sensor MPU6050 (GY-521) SDA→Arduino Uno A4
Motion sensor MPU6050 (GY-521) SCL→Arduino Uno A5
Arduino Uno D2→Resistor a
Resistor b→LED A
LED K→Arduino Uno GND.3
Arduino Uno D3→Resistor a
Resistor b→LED A
LED K→Arduino Uno GND.3
Arduino Uno D4→Resistor a
Resistor b→LED A
LED K→Arduino Uno GND.3
Arduino Uno D5→Resistor a
Resistor b→LED A
LED K→Arduino Uno GND.3

Code (Arduino C++)

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
// Tilt controller: the MPU6050 measures acceleration in m/s squared on three axes.
// Lying flat, Z reads 9.8 (gravity). Tilt it and X or Y picks up some of that pull,
// which tells you which way it leans. One LED lights for the leaning direction.
// Slide the Accel X / Accel Y controls on the sensor to tilt it.
Adafruit_MPU6050 mpu;
const int up = 2, down = 3, left = 4, right = 5;

void setup() {
  pinMode(up, OUTPUT); pinMode(down, OUTPUT); pinMode(left, OUTPUT); pinMode(right, OUTPUT);
  Serial.begin(9600);
  if (!mpu.begin()) { Serial.println("MPU6050 not found"); while (1) delay(10); }
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
  float x = a.acceleration.x, y = a.acceleration.y;
  digitalWrite(up,    y >  2 ? HIGH : LOW);
  digitalWrite(down,  y < -2 ? HIGH : LOW);
  digitalWrite(left,  x < -2 ? HIGH : LOW);
  digitalWrite(right, x >  2 ? HIGH : LOW);
  if (x > 2 || x < -2 || y > 2 || y < -2) {
    Serial.print("Tilt x="); Serial.print(x, 1);
    Serial.print(" y="); Serial.println(y, 1);
  } else {
    Serial.println("LEVEL");
  }
  delay(200);
}

আরো project · More projects