Self balancing waiter tray. (or almost it)

Sure, the principle is the following:

It reads the inclination angle data given by the accelerometer and gyro, applies Kalman Filter to best predict the real inclination and write to the servo motors the inverse angle to compensate the inclination.

For my luck, I found an already made Kalman Filter algorithm for arduino in this post: Guide to gyro and accelerometer with Arduino including Kalman filtering - Sensors - Arduino Forum

Then I basically used the same code, just adapting it to write the angles to the servos:

// added in the beginning:
#include <Servo.h>
Servo servo1;
Servo servo2;

// added in setup:
servo1.attach(6);
servo2.attach(9);

// added in the end of loop() function:
servo1.writeMicroseconds(1560-yAngle9.55);
servo2.writeMicroseconds(1510+xAngle
9.55);

Where 1560 and 1510 are the values corresponding to the center position of my servos and yAngle and xAngle varies from -90 to +90 and are scaled to fit the observed servo limits.

Any question, please comment! :grin: