Introduction: Self Balancing Robot ArduinoUno/mpu6050/l298n

This is a two wheel self balancing robot

Step 1: Materials and Tools

Picture of Materials and Tools

The components are :

1) Sensor : 1 of Mpu6050 Gy521 Cost : 1$-2$ USD

2) Brain : 1 of Arduino Uno clone Cost 3$-4$ USD

3) Motor driver :1 of Module L298N Cost : 1-2$ USD

4) Batteries + batteries holder(prefer to have at least 1 with 3.5mm jack to power arduino uno) : can use AA, 9V or 18650 or phone power bank Cost : $5 to $20

The cheapest options are to use 2x 9V batteries or 8x AA batteries, I used 18650 because I have some around.

5) Frame: 3d printed with PLA weight = 300grams Cost : 5-10$ USD

6) Motor : 2 of TT gear motor 200rpm Cost : $4 to6$ USD

7) Ceramic Capacitor : 2 of value around 0.1mF

8) M3 screws or other mean to fit the board and motors

https://www.thingiverse.com/thing:2457928

The frame structure is quite simple and can be constructed by other methods and material easily.

Total cost : About $25 to 50$ USD

Tools :

Soldering iron or other method of connecting wire and capacitor to motors

Step 2: Wire Connections

Picture of Wire Connections

Wire the connections as shown in the picture

1) First Battery connect to 3.5 power jack of the arduino ( can be a 9V battery or 4x AA batteries or other as long as in the range of 6 to 12V).

2) MPU6050 Gy521 connect to the Arduino Uno (same pin for Arduino Nano) :

Vcc ------- 3.3V

GND ------- GND

SCL ------- A5

SDA------- A4

INT-------PIN2

3) Second battery connect to L298N module :

Positive + ------- to +12V

Negavtive - ------- to GND

4) Second battery connect to Arduino Uno :

Negative - ------- to GND

5) L298N to Arduino Uno:

ENA ------- PIN10

INT1-------PIN8

INT2-------PIN7

INT3--------PIN6

INT4-------PIN5

ENB-------PIN9

6) Motors to L298N OUT1 and OUT2

7) 2 capacitor to two motor (solder or attach)

TO BE CONTINUE ...........

Step 3: Software :

Step 4: Comment and Troubleshoot

1)The heavy weight components (batteries in this case) should be place on top of the robot.

2)Using one power supply source for both arduino and motor will still work, however when motor draw too much current might cause the arduino turn on and off. Hence why two separated power supply were used.

3)The system can still work without the capacitors added to motor, however the motors can produce noise into the system, try without capacitors if you dont have them available.

4) When start the robot, make sure both motors are running in the same directions(either forward or backward, if you notice motors run in opposite direction, swap 1 of the motor pair wire from out1 or out2 on the L298N board.

5)The IMU mpu6050 is not perfectly position, when start the robot, observe and adjust so that when the robot in straight up balance position neither motor turns or only turn slightly. To adjust: physically tilt the IMU mpu6050 until reach the desire position, fit with tape or glue gun or other mean to fix the IMU mpu6050. Other option is to calibrate the software

Comments

andon1 (author)2017-11-17

Thank You. Managed to make this work. Used Nano 328 and was ok and a power supply to run motors about 8 volts worked well, less than 5 would not. Played around with settings for some time without a result but after thinking for a while I realized wheels were going in the wrong direction to self right. Swapped wire polarity to motors and it worked, very pleased. Made a bracket to hold MPU 6050 so it could be moved in different places to get it in the right plane and angle.

I would like some information to help me get this to turn when tilting the MPU6050 in the direction I would like it to go if possible, Thanks

Setting used were:(in comments settings tried)

// use calibration program to get your own values
mpu.setXGyroOffset(44);//(220 44 22 100);
mpu.setYGyroOffset(-21);//(76 -21);
mpu.setZGyroOffset(-30);//(-85 -30);
mpu.setXAccelOffset(-50);//(1788 -1875 17 -20 40 30); // 1688 factory default for my test chip
mpu.setYAccelOffset(-1426);
mpu.setZAccelOffset(2215);

sri24 (author)2017-09-26

my one not working brother

About This Instructable

1,655views

17favorites

License:

More by TranThinh:Self Balancing Robot ArduinoUno/mpu6050/l298nMotor with encoder, how to read input value from encoderPS2 Wire Controller and Arduino (control LEDs)
Add instructable to: