Arduino and MPU dont work properly when not connected to laptop

I have a microcontroller connected to a gyroscope and an active buzzer. Once the angle in the Z direction crosses 45 degrees, the arduino makes the buzzer beep. This code works fine when the arduino is connected to the laptop, I can read the angle, acceleration and velocity values.

When I disconnect the arduino from the laptop and instead provide power through a battery, the code doesnt work exactly right. Here is what I mean by this, the code does make the buzzer beep, it pretty much does everything that doesnt include or is not dependent by the gyroscope. But when I ask for it to make the buzzer beep ONLY when angle > 45, it fails. This would mean that something is wrong with the gyroscope, but when I switch back to the laptop, the gyro works perfectly. I assume the gyro or microcontroller are not reading acceleration and velocity when connected to the battery but I have no way to check since I dont have a display on this circuit.

Does anyone know whats going on? Is this a hardware, electrical or coding problem? What is happening between the laptop to battery switch that is making the gyroscope act wierd?

Welcome! I am not sure but it sounds like a hardware problem. The best way to get an answer is to post an annotated schematic showing ll connections, power, ground and power sources.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.