Self balancing robot - crashing

I am trying to construct a self-balancing robot and I have attached the specifications below.
The problem is that when I try to tune the PID constants for the robot, I jitters and then the program crashes, making the wheel move in one direction. The only way to stop the robot is to reset.

I have tried using a 9V duracell battery and a HIW battery, but both give the same results. I think that it is a problem with the current rating of the motor and the battery, but not so sure. Is there an alternative? Thanks in advance!

P.S the circuit diagram I’ve attached shows 2 AA batteries which are not the case - it is a single 9V battery

Components used:

motors: https://robu.in/product/300-rpm-l-shape-bo-motor/

Arduino Uno
MPU6050
LM298N

Last attachment shows the output of the serial monitor as the code crashes

final_code.ino (6.61 KB)

serial moitor.txt (1 KB)

IMG_20200319_145858154.jpg

Circuit-Diagram-for-DIY-Self-Balancing-Robot-using-Arduino.png

anusha4599:
I have tried using a 9V duracell battery

A what? A smoke alarm battery? To power a motor? Surely you jest? :astonished:

anusha4599:
and a HIW battery

What on earth is that? :roll_eyes:

Oh, wait - I see - it's even worse! :roll_eyes: I don't know what that battery is useful for, not smoke alarms!

anusha4599:
I think that it is a problem with the current rating of the motor and the battery, but not so sure.

We are pretty sure. :grinning:

The minimal robot battery is the same as a model car - a pack of six alkaline "AA" cells. Lithiums (rechargeable) are an option; you would need a matching charger.

Please read the instructions for posting to find out how to cite your code. Item 7.

Thanks Paul! I'll buy an adapter for the same and check if the problem persists.