accurate 90-degree turn suggestions

Hello everyone.
i would like to know from you any suggestions for the following problem and any help will be really appreciated:).
i have a 4 wheel robot that able to perform moving forward and backward, for my project I need to perform 90-degree turn for left or right on the normal surfaces (ground, carpet, etc ) while the robot is not moving! to be more clear the following scenario what i need (if there is a front wall the robot will stop moving then perform left/right 90-degree turn ), my robot has the following parts:-

  1. 4 dc motors (gear motors ) without encoders
  2. motor drive (L293n)

I tried to calculate the time that the robot could take to perform almost 90-degree turn but this is working for a period of time but after the voltage drop the motors will move slowly and the time I assumed will not be accurate and the 90-degree turn will not be as it the first time!
the bellow code I used it but as I mentioned before this is just like workaround solution!

unsigned long start = millis();
turnLeft()
while(true)
{
      if((millis()-start)>=300){
      forceStopAM();
      break;
      }
}

i heard about a sensor called Digital Compose Ex: mpu 9 axis sensor that could help , is it true that i could use it to perform the 90-degree turn? if not can you advice me for another solution ?
thank you in advance .
NOTE ! , i modify the post to include the schema, photographic pic to my setup and a simple gif that show the accurate degrees i got by turning the robot by hand to left when i am using the cable to powering the Arduino

turning.gif

A magnetometer can be used as a digital compass, to measure the yaw angle (deviation from magnetic North).

All magnetometers need to be calibrated to be useful, which at the very least requires you to calculate scale and offset factors for each axis. Several tutorials are available on line, depending on what sensor you decide to use. Example.

Calibration has to be done in the robot.

Using just the time on to determines motor’s movement is a very poor idea and is seldom satisfactory. Using a shaft encoder is better as that counts the amount of movement a motor makes and you can make the wheels move quite precisely.

However that does not account for any wheel slip between wheel and surface, that is what sensors do.

Sadly these sort of sensors are not as accurate and repeatable as you hope them to be. What sounds like a simple problem is quite hard and the answer is often to use as many techniques as you can.p to supplement each other.

jremington:
A magnetometer can be used as a digital compass, to measure the yaw angle (deviation from magnetic North).

Well, thank you for all what you said , i would like to know from you is it hard to make the calibration and other stuff because i’m totally new and I don’t want to buy extra components that I cannot handle it !

Grumpy_Mike:
Using just the time on to determines motor’s movement is a very poor idea and is seldom satisfactory. Using a shaft encoder is better as that counts the amount of movement a motor makes and you can make the wheels move quite precisely.

Thank you for that comment, is it dead end for me or i could do something to perform the 90 degree turn ,however, i am not seeking for precisely 90 degree turn , i just want to ensure that my robot turn at least more than 80 degree to specific direction!

Jack + servo: have the first lift the robot, then the servo can turn it by 90° quite accurately, and put it down on the ground again.

A properly calibrated electronic compass is usually accurate to +/- 2 degrees, which is fine for your purpose.

i would like to know from you is it hard to make the calibration

I think it is easy. But read the article linked in reply #1, and a few others, so you can judge for yourself.

jremington:
A properly calibrated electronic compass is usually accurate to +/- 2 degrees, which is fine for your purpose.

ok thank you a lot , at the time where I can't buy from famous stores such as Amazon, etc , I have to buy each component from local stores and almost they are selling not good ones, however, I found an MPU 6050 triple sensor with only 5$ ! is that ok for me because I think this sensor will not be sufficient, should I go and buy it ?

The MPU6050 does not have a magnetometer, but it does have a gyro. It is not as easy to use and doesn't work as well as a compass to measure turns.

There is an implication here that the 90 degree turn has to be pretty accurate, why ?
If the robot turns exactly 90deg , won’t it then just scrape along the wall when it moves on and get stuck ?
Why can’t you turn it “about “. 100 degrees, then it can move away.

If you want it to follow the wall, that is a different problem

jremington:
The MPU6050 does not have a magnetometer

I found this video on youtube and it's quite easy to use it to get angles!
How to get angles using MPU 6050
as well as I found sensor called FC-33 that calculate the number of rotation per second, so I thought if I count the number of rotations to get almost 90-degree maybe solve my problem! should I try that in bellow link?
calculate the rpm

hammy:
If you want it to follow the wall, that is a different problem

well, sir, I'm not seeking for really accurate 90-degree I just want the robot to turn to left or right if it finds a turn.
Indeed my robot is a wall follower and I tried with only using the ultrasonic sensor HC-SR04 to make the turns but it is keeping to fail after the X number of turns

Walls do not only have 90° turns. So that's one problem. You have to make sure you're following the wall, not moving away from it, nor moving into it. Feelers would make more sense to me.

Another problem with ultrasound is that you have a rather wide cone, so when you're right next to the wall the reflection you get can be from where the sound cone (approx. 30° field of vision) hits that wall.

wvmarle:
Walls do not only have 90° turns.

my maze is really simple the path is straightforward that means whenever a turn occurs the robot will only need to turn a 90-degree and carry on to the new path the degree between the two connected walls is 90.

it's quite easy to use it to get angles!

Good to hear. Try it, and let us know if the angles you get are actually useful.

TheNoneP:
my maze is really simple

Your project is for a maze following robot?
As a hint, that would have been good information to put into the original post. :smiley:

Even if does a fairly accurate 90 deg , after several turns , the errors will add up
And it will be hitting the walls at a angle.

Most maze robots have multiple sensors and use them to maintain a course down the middle of the path. Likely by measuring the distance to each wall and adjusting course until those distances are equal.

Hello again.
i updated the post to include my schematic of the connections, however, I am facing a problem!the problem is that when I am using the Serial Monitor I get the right result from 0-target degree but if I upload the code to the Arduino the robot physically turned less than 40-degree, I just shocked and created Master-Slave between two boards to use the Serial Monitor of the slave board and the data i received were just jumping data 0,6,24,30,43,etc

int start = mpu6050.getGyroAngleX();
    int target =0;
      if(start < 0) // working only with positive angles 
      {
          start *= -1;
      }
      start = start%360; // to operate only with 360 circle 
      target = start + 85; 
      while(start < target) // perform the almost 90-degree turn
      {
          mpu6050.update();
          turnLeft();delay(5);
          forceStopAM();delay(10);
          start = mpu6050.getGyroAngleX();
          //Serial.write(start); // the bluetooth is connected to rx,tx of the arduino board
      }

Someone has already mentioned the need for calibration.

Maybe have a look here.....