I'm new to the Arduino community and controllers in general. I have recently started looking into MPU6050 and I'm wondering if there is any way that I can utilize this to auto level my electric jacks on a small rig. Something like RV industries are currently doing. Please let me know if you guys have any idea as to how to go about this project? Any help would be much appreciated. Thanks!
Here is simple code to measure the pitch and roll tilt angles, using the MPU-6050. For leveling, most people would use PID control to force those angles to zero.
// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with 3.3V Pro Mini with no external pullups on I2C bus (worked with internal pullups)
// Add 4.7K pullup resistors to 3.3V if required. A4 = SDA, A5 = SCL
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;
void setup() {
Wire.begin(); //begin the wire communication
Wire.beginTransmission(MPU_addr1); //begin, send the slave adress (in this case 68)
Wire.write(0x6B); //make the reset (place a 0 into the 6B register)
Wire.write(0);
Wire.endTransmission(true); //end the transmission
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr1);
Wire.write(0x3B); //send starting register address, accelerometer high byte
Wire.endTransmission(false); //restart for read
Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data
int t = Wire.read();
xa = (t << 8) | Wire.read();
t = Wire.read();
ya = (t << 8) | Wire.read();
t = Wire.read();
za = (t << 8) | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
roll = atan2(ya , za) * 180.0 / PI;
pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied
Serial.print("roll = ");
Serial.print(roll,1);
Serial.print(", pitch = ");
Serial.println(pitch,1);
delay(400);
}
What accuracy do You need?
Ebay sells mercury switches that could be mounted to flip at just passing levelled. If switched the plane is tilted in one direction. If not tilted the plane is tilted in the other direction. Using small motor moves, just pass the trigger point.
This surely looks primitive but this strategy was successfully used for multi level hight indication on commercially sold fork lift trucks. Simple and very reliable.
jremington:
Here is simple code to measure the pitch and roll tilt angles, using the MPU-6050. For leveling, most people would use PID control to force those angles to zero.
// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with 3.3V Pro Mini with no external pullups on I2C bus (worked with internal pullups)
// Add 4.7K pullup resistors to 3.3V if required. A4 = SDA, A5 = SCL
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;
void setup() {
Wire.begin(); //begin the wire communication
Wire.beginTransmission(MPU_addr1); //begin, send the slave adress (in this case 68)
Wire.write(0x6B); //make the reset (place a 0 into the 6B register)
Wire.write(0);
Wire.endTransmission(true); //end the transmission
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr1);
Wire.write(0x3B); //send starting register address, accelerometer high byte
Wire.endTransmission(false); //restart for read
Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data
int t = Wire.read();
xa = (t << 8) | Wire.read();
t = Wire.read();
ya = (t << 8) | Wire.read();
t = Wire.read();
za = (t << 8) | Wire.read();
// formula from How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing-DFRobot
roll = atan2(ya , za) * 180.0 / PI;
pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied
Railroader:
What accuracy do You need?
Ebay sells mercury switches that could be mounted to flip at just passing levelled. If switched the plane is tilted in one direction. If not tilted the plane is tilted in the other direction. Using small motor moves, just pass the trigger point.
This surely looks primitive but this strategy was successfully used for multi level hight indication on commercially sold fork lift trucks. Simple and very reliable.
It doesn't have to be super accurate but just good enough to have a stable platform. So, pretty much what you suggesting is to mount these switches on all four corners and the jacks will keep rising until the switch closes?
abhishekchadha04:
So, pretty much what you suggesting is to mount these switches on all four corners and the jacks will keep rising until the switch closes?
I would mount those switches on one long side and one short side of the table. If the table, the rig, is stiff enough that could do. If the rig might flex a bit I would apply one switch on each side, 4 switches.