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

Wemos D1 Mini and MPU-6050 Based Motion Sensor with Real-Time Serial Output

View and Edit Project In Cirkit DesignerImage of Wemos D1 Mini and MPU-6050 Based Motion Sensor with Real-Time Serial Output

Circuit Documentation

Summary

This circuit involves a Wemos D1 Mini microcontroller connected to an MPU-6050 sensor. The MPU-6050 is an accelerometer and gyroscope sensor that communicates with the Wemos D1 Mini via the I2C protocol. The sensor is powered by the 5V and GND pins of the Wemos D1 Mini. The microcontroller reads roll, pitch, and yaw values from the sensor and prints them to the Serial Monitor.

Component List

Wemos D1 Mini

MPU-6050

Wiring Details

Wemos D1 Mini

MPU-6050

Code Documentation

#include <Adafruit_MPU6050.h>
/*
 * This Arduino Sketch reads roll, pitch, and yaw values from the MPU-6050
 * sensor connected to a Wemos D1 Mini. The MPU-6050 is connected via I2C
 * with SCL on D1 and SDA on D2. The sensor is powered by the 5V and GND
 * pins of the Wemos D1 Mini. The code initializes the sensor, reads the
 * values, and prints them to the Serial Monitor.
 */

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

MPU6050 mpu;

void setup() {
  Serial.begin(115200);
  Wire.begin(D2, D1); // SDA, SCL
  mpu.initialize();
  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed");
    while (1);
  }
  Serial.println("MPU6050 connection successful");
}

void loop() {
  int16_t ax, ay, az;
  int16_t gx, gy, gz;
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  float roll = atan2(ay, az) * 180 / PI;
  float pitch = atan2(-ax, sqrt(ay * ay + az * az)) * 180 / PI;
  float yaw = atan2(gy, gx) * 180 / PI; // Simplified yaw calculation

  Serial.print("Roll: "); Serial.print(roll);
  Serial.print(" Pitch: "); Serial.print(pitch);
  Serial.print(" Yaw: "); Serial.println(yaw);

  delay(500);
}

This code initializes the MPU-6050 sensor, reads the accelerometer and gyroscope values, calculates the roll, pitch, and yaw, and prints these values to the Serial Monitor every 500 milliseconds.