Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Motion Sensor with OLED Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Motion Sensor with OLED Display

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with an MPU-6050 accelerometer and gyroscope sensor and an Adafruit 128x64 OLED FeatherWing display. The Arduino UNO reads data from the MPU-6050 sensor and displays the accelerometer and gyroscope data on the OLED display.

Component List

Arduino UNO

Adafruit 128x64 OLED FeatherWing

MPU-6050

Wiring Details

Arduino UNO

Adafruit 128x64 OLED FeatherWing

MPU-6050

Code Documentation

Arduino UNO Code

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Create MPU6050 object
MPU6050 mpu;

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

  // Initialize MPU6050
  Wire.begin();
  mpu.initialize();
  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed");
    while (1);
  }

  // Initialize OLED display
  if(!display.begin(SSD1306_I2C_ADDRESS, 0x3D)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop() {
  // Read raw accelerometer and gyroscope data
  Vector accel = mpu.getAcceleration();
  Vector gyro = mpu.getRotation();
  
  float ax = accel.x;
  float ay = accel.y;
  float az = accel.z;
  float gx = gyro.x;
  float gy = gyro.y;
  float gz = gyro.z;
  
  // Clear display
  display.clearDisplay();
  
  // Print data on OLED
  display.setCursor(0,0);
  display.print("Accel X: ");
  display.println(ax);
  display.print("Accel Y: ");
  display.println(ay);
  display.print("Accel Z: ");
  display.println(az);
  display.print("Gyro X: ");
  display.println(gx);
  display.print("Gyro Y: ");
  display.println(gy);
  display.print("Gyro Z: ");
  display.println(gz);
  
  display.display();
  
  delay(500); // Update every 500ms
}

This code initializes the MPU-6050 sensor and the OLED display. It reads the accelerometer and gyroscope data from the MPU-6050 and displays it on the OLED screen, updating every 500 milliseconds.