Hello everyone.
I have four wheel robot that I want to drive it to perform 90-degree turn.
I am using MPU6050 3Dof, however, the below scenarios was making me dizzy!
1) If I am powering the Arduino from the USB port from the computer and the dc motors from external battery 11.3v 3800mAh everything ok and the robot perform almost 90-degree turn
2) if I am powering the Arduino from its Vin and GND pins with 7.3v 3800mAh and the dc motor with 11.3v 3800mAh the readings of the mpu become crazy and the robot performs 30-40 degree turn but after pressing the RESET button on Arduino board the robot back to be normal and perform 90-degree turn!
Some people told me that DC motors create EMI so I added capacitors to the motors but it didn't fix my problem!
I check my connections too many and for now, i am using the following power supplies :
11.3v 3800mAh for dc motors goes to L298n drive
7.3v 3800mAh for Arduino goes from Vin and Gnd
a wire goes from the Gnd of L298n drive to the Gnd of the Arduino!
any help will be appreciated and i am open for any suggestion(s)
It sounds like a wiring problem.
Good photographs showing the wiring of both batteies would be very helpful.
Good photographs showing the wiring of both batteies would be very helpful
thank you for reply the following images show how my setup is connected
Hello everyone.
I have some mysterious problem! The below code I am using to make a four-wheel robot turn 90-degrees to left, I need to press RESET button on the Arduino board to get a real 90-degree turn ( almost and that what i want ), the first power will never work I mean i check the readings from MPU6050 3 Dof and they were jumping like a raw data.
the following scenario may be more clearly :
- first power the MPU6050 data are raw I don't know why!
- pressing the reset button on the Arduino board will turn the robot 90-degree and the readings from mpu6050 are clearly correct
the code that i am using for now
#include <MPU6050_tockn.h>
#include <Wire.h>
// left motor
#define LM1 5
#define LM2 4
#define LMS 3
// right motor
#define RM1 7
#define RM2 8
#define RMS 6
MPU6050 mpu6050(Wire);
bool bo =true;
void setup() {
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
Serial.begin(9600);
for(int i=3;i<9;i++) // intializing some pins for dc motors
{
pinMode(i,OUTPUT);
}
}
void stopAM()
{
digitalWrite(LM1,LOW);
digitalWrite(LM2,LOW);
digitalWrite(RM1,LOW);
digitalWrite(RM2,LOW);
analogWrite(LMS,0);
analogWrite(RMS,0);
}
void moveDir(int side,int spd)
{
if(side == LM1 || side == LM2)
{
digitalWrite(LM1,LOW);
digitalWrite(LM2,LOW);
digitalWrite(side,HIGH);
analogWrite(LMS,spd);
}
else if(side ==RM1 || side == RM2 )
{
digitalWrite(RM1,LOW);
digitalWrite(RM2,LOW);
digitalWrite(side,HIGH);
analogWrite(RMS,spd);
}
}
void test90Turn()
{
int startS =0 , target =0;
mpu6050.update();
startS = mpu6050.getGyroAngleZ();
target = startS + 90;
moveDir(LM1,100);
moveDir(RM1,100);
Serial.println("started : ");delay(500);
while(startS < target)
{
mpu6050.update();
startS = mpu6050.getGyroAngleZ();
Serial.println(startS);
}
stopAM();
}
void loop() {
if(bo){// perform only one 90-degree turn
test90Turn();delay(2000);
}
}
i included the images for my robot and connection.
thank you in advance.
@TheNoneP, please do not cross-post. Threads merged.