AVR ATmega8 Bases Line Follower.

Easy to make PID LFR Robot.

PID Algorithm generates a control variable from the current value, and the required value. Since the aim is to keep the line always beneath the center sensor so the required value is 3 (second parameter). The first argument is the current sensor reading. The more the difference between the two greater is the control variable. This control variable is used to produce turning in the robot. When current value is close to required value is close to 0.

**Arguments:**

- current line position, range is from 1-5 (1= LEFT Most sensor, 5= right most)cur_valuedata type: float.

- desired position, since sensor 3 is the middle sensor and the aim is to keep the line below middle sensor so this value is 3.req_valuedata type: float

**Return Value:**

control variable, the amount of correction required. When the control variable is more than 0 that means line is towards the left, so we need to take right turn to correct the error and bring the robot back to track.

Similarly if control variable is less than 0 that means line is towards the right, so we need to take left turn to correct the error and bring the robot back to track.

**Implementation**

```
```**float** PID(**float** cur_value,**float** req_value)
{
**float** pid;
**float** error;
error = req_value - cur_value;
pid = (pGain * error) + (iGain * eInteg) + (dGain * (error - ePrev));
eInteg += error; *// integral is simply a summation over time*
ePrev = error; *// save previous for derivative*
**return** pid;
}

Return to Help Index.