Good afternoon! I am implementing a project on Arduino Uno and faced the following problem. I have an MPU6050 module, and I read data from it and calculate the angle (along the Y axis). I also have a micro vibration motor in my circuit, which is triggered when the angle values fall into the range I need:
And everything would be fine, but there was a problem. The program calculates the angle correctly and the motor is triggered at the right time, but sometimes there is a problem displaying the angle data in the port monitor. That is, I change the orientation of the MPU6050 module, the angle changes in the port monitor, and at one point the data stops updating in the port monitor, the data freezes. And, for example, if this happened in the range: (angle_fy > -20) && (angle_fy < 20), then the motor constantly continues to vibrate, even if I change the orientation of the layout. What could this be related to?
Oh I missed that the variable wasn't unsigned. Let me correct my previous post. The timing code in the OP will fail at a little over half an hour. Not one hour as previously stated.
The motor may require it's own power supply. The Arduino board is not built to supply power to motors, despite so many pictures all over the internet like the one you posted. They're even on this site. But it's still not a good idea.