Accelormeter Reading
Week 8 Input Devices
Project Description
I am planning to use Accelormeter for final project. I mainly want the oreintation of a moving part.
I mainly need to get the orientation for accelormeter.
I used the MPU 6050 after a series of research and a lot of recommendation online for it.
I am planning to use twelve of these so I have to get something that is of reasonable price too.
Test Results
![](../assets/week8/p1.jpg)
![](../assets/week8/p2.jpg)
![](../assets/week8/p3.jpg)
![](../assets/week8/p4.jpg)
Testing Accelormeter at different angles to see if the values changes
What didn't work
Somehow failed with my XIAO PCB, so the above I plugged the accelormeter directly to my XIAO RP2040. a spare one that I have
Somehow it works on my spare XIAO board, but not on my PCB one. I actually don't know the reason why, however, I need to look more into it.
Wiring
![](../assets/week8/p5.jpg)
![](../assets/week8/p6.jpg)
Coding in Arduino
Arduino Code -> this was one of the example files to get the angle of the x y and z . I uploaded the example code and it work.
#include "Wire.h"
#include
MPU6050 mpu(Wire);
unsigned long timer = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
Serial.println("Done!\n");
}
void loop() {
mpu.update();
if((millis()-timer)>10){ // print data every 10ms
Serial.print("X : ");
Serial.print(mpu.getAngleX());
Serial.print("\tY : ");
Serial.print(mpu.getAngleY());
Serial.print("\tZ : ");
Serial.println(mpu.getAngleZ());
timer = millis();
}
Group Project with Danny Griffin
![](../assets/week8/t1.jpg)
![](../assets/week8/t2.jpg)