#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;
sensors_event_t event;

void setup() {
  Serial.begin(115200);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);

  Serial.println("");
  Serial.println("Hello, XIAO ESP32-C3!");
  Serial.println("Welcome to Wokwi :-)");
  while (!mpu.begin()) {
    Serial.println("MPU6050 not connected!");
    delay(1000);
  }
  Serial.println("MPU6050 ready!");
}

void loop() {
  // Serial.println("Red");
  // digitalWrite(D2, HIGH);
  // delay(500);
  // digitalWrite(D2, LOW);

  // Serial.println("Green");
  // digitalWrite(D3, HIGH);
  // delay(500);
  // digitalWrite(D3, LOW);

  // Serial.println("Blue");
  // digitalWrite(D4, HIGH);
  // delay(500);
  // digitalWrite(D4, LOW);
  mpu.getAccelerometerSensor()->getEvent(&event);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] X: ");
  Serial.print(event.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(event.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(event.acceleration.z);
  Serial.println(" m/s^2");
  delay(500);
}
Loading
xiao-esp32-c3