Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Motion Sensor with OLED Display

Image 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

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0

Adafruit 128x64 OLED FeatherWing

  • Description: A 128x64 pixel OLED display.
  • Pins: GND, 3.3V, SDA, SCL, !RESET, 3, 5, 28, 6, 27, 7, 26, 8, 25, 9, 24, 10, 23, 11, 22, 12, J, 13, I, 14, H, 15, 16

MPU-6050

  • Description: A 3-axis accelerometer and 3-axis gyroscope sensor.
  • Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT

Wiring Details

Arduino UNO

  • 5V: Connected to VCC of MPU-6050 and 3.3V of Adafruit 128x64 OLED FeatherWing
  • GND: Connected to GND of MPU-6050 and GND of Adafruit 128x64 OLED FeatherWing
  • A4: Connected to SDA of MPU-6050 and SDA of Adafruit 128x64 OLED FeatherWing
  • A5: Connected to SCL of MPU-6050 and SCL of Adafruit 128x64 OLED FeatherWing

Adafruit 128x64 OLED FeatherWing

  • 3.3V: Connected to 5V of Arduino UNO
  • GND: Connected to GND of Arduino UNO
  • SDA: Connected to A4 of Arduino UNO and SDA of MPU-6050
  • SCL: Connected to A5 of Arduino UNO and SCL of MPU-6050

MPU-6050

  • VCC: Connected to 5V of Arduino UNO
  • GND: Connected to GND of Arduino UNO
  • SDA: Connected to A4 of Arduino UNO and SDA of Adafruit 128x64 OLED FeatherWing
  • SCL: Connected to A5 of Arduino UNO and SCL of Adafruit 128x64 OLED FeatherWing

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.