Turning 90 degrees

I want my robot to turn 90 degrees. So far I have used a delay; but I have to keep changing the value of delay used.
When I browsed a bit, I found I could use encoders. But I couldn't find out which encoder or how to use it.
A perfect 90 degree turn is required.
Please guide.

How to make robot go straight? I read on the internet the PID controller can be used.How will i use it?
I have arduino version 1.0 is it possible for me to use it?.

straight is a concept. the Earth travels in a straight line as regards the Earth, however, due to the bending of space, we also think it orbits in a circle.

so, you have to have some reference in order to perform that task.

you know the meaning of ASS-u-me....

IF - your wheels are the EXACT same circumference
IF - your motors move at the EXACT same speed
IF - there is no drag on your drive train
IF - the floor is perfectly level
then, your wheels will rotate at the same speed and your robot will go straight.

if you use an encoder on each wheel, you can make the left one go the same number of revolutions as the right one.
after 10 revolutions, if both rotated the exact same number of times, you would know if the diameter of the wheels are the exact same because of how your robot tracked. if you have to have your left wheel rotate 100 clicks on the encoder and the right wheel 99 clicks, then you can set that up to make corrections as needed.

if you are having problems, it might be easier to address the problem. this is all theoretical and does not arrive at a solution, only possibilities.

pid is a control algorithm that uses your feedback from some sensor, calculates where it is based on that input, and calculates how from where you want it to be, then outputs a control to bring those two together in some programmed manner, usually making huge corrections when you are far off, and smaller corrections the closer to being dead on. since it's influence is continuously variable it mimics what humans do naturally.

an out of turn PID controller will introduce process upsets, a well tuned one will keep it near perfect.

look at your drive train. it may have options for encoders and if it does, then you have a source for encoders that will fit what you have.

if you find an encoder from your drive train supplier, things will be simpler because most robot stores offer code to use.

but, an encoder is basically a spoked wheel. you count spokes. if the left wheel moves 200 spokes per full revolution and the right wheel rotates 200 spokes per revolution, you can move in a straight line. if you lock one in place and have the other move 100 spokes, then the distance or wheel base will form part of the calculation. the circumference of the wheel will make another part of the calculation and you can program a locked wheel turn.

if you want to have your robot drive around an point at say, 1 meter, then your inner wheel circumference and spokes per revolution can be calculated and the outer wheel circumference and spokes can be calculated.

then if you know the outter has to drive 1 more spoke for every 10 the other wheel moves, you can calculate the diameter of the turning radius.

since your questions are almost the exact same, you should not have two threads.

your real question is how to use encoders.

Another way of expressing what @dave-in-nj has said (in what is now Reply #2) is "you need something to tell you when it is not going straight so you can correct the steering"

...R

In general you should NOT use the delay() function except in short demo programs. The demo Several Things at a Time illustrates the use of millis() to manage timing.

A rotary encoder can be attached to a shaft to enable the Arduino to know how many degrees the shaft has turned.

However my guess is that you will find it impossible to get "A perfect 90 degree turn" no matter how carefully you measure the rotation of the wheels due to imperfections in the way the wheels interact with the ground.

I reckon you need a compass module to tell your code how far the robot has turned.

...R

sulivuli:
How to make robot go straight?

Robots anonymous.

Thank you all. I'll try the compass module.