info_arduinoooooo
Published © Apache-2.0

Balancing LED project using MPU6050

The tilt will be analyzed and shown as outputs on LEDs using MPU6050 and Arduino Uno.

BeginnerFull instructions provided2,128
Balancing LED project using MPU6050

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
5 mm LED: Red
5 mm LED: Red
×15
Inertial Measurement Unit (IMU) (6 deg of freedom)
Inertial Measurement Unit (IMU) (6 deg of freedom)
×1

Story

Read more

Schematics

Balancing LED schematic

Code

CODE

C/C++
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
int L1 = 13;
int L2 = 12;
int L3= 11;
int L4 = 10;
int L5 = 9;
int L6 = 8;
int L7 = 7;
int L8 = 6;
int L9 = 5;
int L10 = 4;
int L11 = 3;
int L12 = 2;
int L13 = A0;
int L14 = A1;
int L15 = A2;
int Mpu;

Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  // set accelerometer range to +-8G
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);

  // set gyro range to +- 500 deg/s
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);

  // set filter bandwidth to 21 Hz
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);

  delay(100);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(L5, OUTPUT);
  pinMode(L6, OUTPUT);
  pinMode(L7, OUTPUT);
  pinMode(L8, OUTPUT);
  pinMode(L9, OUTPUT);
  pinMode(L10, OUTPUT);
  pinMode(L11, OUTPUT);
  pinMode(L12, OUTPUT);
  pinMode(L13, OUTPUT);
  pinMode(L14, OUTPUT);
  pinMode(L15, OUTPUT);
}

void loop() {
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  if(a.acceleration.y<=-6.00 && a.acceleration.y>-7.00 ){
    digitalWrite(L1,HIGH);
    }
      else
    {
      digitalWrite(L1,LOW);
      }
  if(a.acceleration.y<=-5.00 &&a.acceleration.y>-6.00 ){
    
    digitalWrite(L2,HIGH);
    
    }else
    {
      digitalWrite(L2,LOW);
      }
   if(a.acceleration.y<=-4.00&&a.acceleration.y>-5.00 ){
    
    digitalWrite(L3,HIGH);
    
    }else
{
      digitalWrite(L3,LOW);
      }
    
    if(a.acceleration.y<=-3.00&&a.acceleration.y>-4.00 ){
    
    digitalWrite(L4,HIGH);
    
    }else
    {
      digitalWrite(L4,LOW);
      }
    if(a.acceleration.y<=-2.00&&a.acceleration.y>-3.00 ){
    
    digitalWrite(L5,HIGH);
    
    }else
    {
      digitalWrite(L5,LOW);
      }
    if(a.acceleration.y<=-1.00&&a.acceleration.y>-2.00 ){
    
    digitalWrite(L6,HIGH);
   
    }else{
     
      digitalWrite(L6,LOW);
      }

       if(a.acceleration.y<0.00&&a.acceleration.y>-1.00 ){
    
    digitalWrite(L7,HIGH);
  
    }else{
     
      digitalWrite(L7,LOW);
      }
      
       if(a.acceleration.y==0 ){
    
    digitalWrite(L8,HIGH);
  
    }else{
     
      digitalWrite(L8,LOW);
      }

  if(a.acceleration.y<=1.00 && a.acceleration.y>0.01 ){
   
    digitalWrite(L9,HIGH);
    }
    else
    {
      digitalWrite(L9,LOW);
      }
  if(a.acceleration.y<=2.00 &&a.acceleration.y>1.00 ){
    
    digitalWrite(L10,HIGH);
    
    }else
    {
      digitalWrite(L10,LOW);
      }
   if(a.acceleration.y<=3.00&&a.acceleration.y>2.00 ){
    
    digitalWrite(L11,HIGH);
    
    }else
{
      digitalWrite(L11,LOW);
      }
    
    if(a.acceleration.y<=4.00&&a.acceleration.y>3.00 ){
    
    digitalWrite(L12,HIGH);
    
    }else
    {
      digitalWrite(L12,LOW);
      }
    if(a.acceleration.y<=5.00&&a.acceleration.y>4.00 ){
    
    digitalWrite(L13,HIGH);
    
    }else
    {
      digitalWrite(L13,LOW);
      }
    if(a.acceleration.y<=6.00&&a.acceleration.y>5.00 ){
   
    digitalWrite(L14,HIGH);
   
    }else
    
       {
     
      digitalWrite(L14,LOW);
      }

       if(a.acceleration.y<=7.00&&a.acceleration.y>6.00 ){
  
    digitalWrite(L15,HIGH);
  
    }else{
     
      digitalWrite(L15,LOW);
      }
    
    }

Credits

info_arduinoooooo
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.