Wemos D1 Mini and MPU-6050 Based Motion Sensor with Real-Time Serial Output
View and Edit Project In Cirkit Designer
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
- Description: A compact microcontroller board based on the ESP8266 WiFi module.
- Pins: RST, A0, D0, D5, D6, D7, D8, 3V3, 5V, G, D4, D3, D2, D1, RX, TX
- Purpose in Circuit: Acts as the main microcontroller, handling data acquisition from the MPU-6050 and communication via Serial Monitor.
MPU-6050
- Description: A 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
- Purpose in Circuit: Measures roll, pitch, and yaw values and sends this data to the Wemos D1 Mini via I2C.
Wiring Details
Wemos D1 Mini
- 5V: Connected to VCC of MPU-6050
- G: Connected to GND of MPU-6050
- D2: Connected to SDA of MPU-6050
- D1: Connected to SCL of MPU-6050
MPU-6050
- VCC: Connected to 5V of Wemos D1 Mini
- GND: Connected to G of Wemos D1 Mini
- SDA: Connected to D2 of Wemos D1 Mini
- SCL: Connected to D1 of Wemos D1 Mini
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.