# PID Line Follower Atmega328P

10,027

16

9

### INTRODUCTION

Hi guys am a 3rd Year University Student of Lovely Professional University, India currently pursuing Electronics and Communication Engineering .

GitHub :::: https://github.com/arnabdasbwn

Wordpress :::: https://arnabdasbwn.wordpress.com/

This instructable is about making a efficient and reliable Line Follower with PID (proportional-integral-derivative) Control (Mathematical) running inside its brain (Atmega328P).

Line follower is an autonomous robot which follows either black line in white are or white line in black area. Robot must be able to detect particular line and keep following it.

So there will be few parts/steps to make a LINE FOLLOWER I will be discussing all of them step by step.

1. Sensor (Eye to see the line)
2. Microcontroller (Brain to do some calculations)
3. Motors (Muscle Power)
4. Motor Driver
5. Chassis
6. Battery (Energy Source)
7. Wheel
8. Misc

Here is the VIDEO OF THE LINE FOLLOWER

IN THE NEXT STEPS I WILL BE DISCUSSING IN DETAILS ABOUT EVERY COMPONENTS

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Sensor ( Eye ) QTR 8RC

Thanks toPololufor manufacturing this awesome sensor.

The module is a convenient carrier for eight IR emitter and receiver (phototransistor) pairs evenly spaced at intervals of 0.375" (9.525 mm). To use a sensor, you must first charge the output node (Charging the capacitor) by applying a voltage to its OUT pin. You can then read the reflectance by withdrawing the externally supplied voltage and timing how long it takes the output voltage to decay due to the integrated phototransistor. Shorter decay time is an indication of greater reflection. This measurement approach has several advantages, especially when coupled with the ability of the QTR-8RC module to turn off LED power:

• No analog-to-digital converter (ADC) is required.
• Improved sensitivity over voltage-divider analog output.
• Parallel reading of multiple sensors is possible with most microcontrollers.
• Parallel reading allows optimized use of LED power enable option

Specifications

• Dimensions: 2.95" x 0.5" x 0.125" (without header pins installed)
• Operating voltage: 3.3-5.0 V
• Supply current: 100 mA
• Output format: 8 digital I/O-compatible signals that can be read as a timed high pulse
• Optimal sensing distance: 0.125" (3 mm)Maximum recommended sensing distance: 0.375" (9.5 mm)
• Weight without header pins: 0.11 oz (3.09 g)

Interfacing the QTR-8RC Outputs to Digital I/O Lines

The QTR-8RC module has eight identical sensor outputs that, like the Parallax QTI, require a digital I/O line capable of driving the output line high and then measuring the time for the output voltage to decay. The typical sequence for reading a sensor is:

1. Turn on IR LEDs (optional).
2. Set the I/O line to an output and drive it high.
3. Allow at least 10 μs for the sensor output to rise.
4. Make the I/O line an input (high impedance).
5. Measure the time for the voltage to decay by waiting for the I/O line to go low.
6. Turn off IR LEDs (optional).

These steps can typically be executed in parallel on multiple I/O lines.

With a strong reflectance, the decay time can be as low as several dozen microseconds; with no reflectance, the decay time can be up to a few milliseconds. The exact time of the decay depends on your microcontroller’s I/O line characteristics. Meaningful results can be available within 1 ms in typical cases (i.e. when not trying to measure subtle differences in low-reflectance scenarios), allowing up to 1 kHz sampling of all 8 sensors. If lower-frequency sampling is sufficient, substantial power savings can be realized by turning off the LEDs. For example, if a 100 Hz sampling rate is acceptable, the LEDs can be off 90% of the time, lowering average current consumption from 100 mA to 10 mA.

## Step 2: Microcontroller (Brain) Atmega328P

Thanks toAtmel CorporationFor Manufacturing this Awesome Microcontroller AKA Atmega328 .

Key parameters for ATmega328P

Parameter Value

• Flash (Kbytes): 32 Kbytes
• Pin Count: 32
• Max. Operating Freq. (MHz): 20 MHz
• CPU: 8-bit AVR
• Max I/O Pins: 23
• Ext Interrupts: 24
• SPI: 2
• TWI (I2C): 1
• UART: 1
• SRAM (Kbytes): 2
• EEPROM (Bytes): 1024
• I/O Supply Class: 1.8 to 5.5
• Operating Voltage (Vcc):1.8 to 5.5
• Timers: 3

For Detailed Information go through the Datasheet of Atmega328P.

In this project I am using Atmega328P for Few Reason

1. Cheap
2. Has enough RAM For computation
3. Sufficient I/O Pins for This Project
4. Atmega328P is used In Arduino .... U may notice in the Picture and Video an Arduino Uno but nighter i am using Arduino IDE or Any Arduino .. I have Used Only the hardware as an interfacing board. I have erased the bootloader and used USB ASP for Programming the chip.

For Programming The Chip i have used Atmel Studio 6

All THE SOURCE CODE IS IN GitHub Download It and Check test.c file.

To Compile this package you have to download and install The POLOLU AVR LIBRARY SETUP Check The Attachments ...

I am also UPLOADING a Atmega328P Development Board Schematic and Board File ... You Can Manufacture It by Yourself...

## Step 3: Motor and Motor Driver

I have Used 350RPM 12V BO Type Geared DC motor as actuator. To know more info... MOTOR LINK

As a motor driver i have used L293D H- bridge IC.

I am attaching the Schematic and Board File for the same.

## Step 4: Chassis and Misc

The Bot is made UP of Ply Wood Of 6mm Thickness.

## Recommendations

• ### Internet of Things Class

22,711 Enrolled

## 9 Discussions

Hi Arnab. Awesome Project! Im just wondering that the Github link is not working. do you know why it is doing that?

I'd like to know if I can achieve the same level of line following using an arduino.

2 replies

Yes you can achieve .. but in terms of learning without arduino ide is better mail me and subscribe to my channel on Youtube :: Arnab Das

Can u send me code sir. my mail id is yuvsinghraj2@gmail.com

Bro, may i know how to Code ?