Introduction: Robot - Line Follower

Picture of Robot - Line Follower



I began work on my first robot about two years ago. For no particular reason, I decided to begin with a line following robot and truth be told, my first attempt at building it was a complete failure. Looking back at my efforts, I believe, for a beginner, I was rather too ambitious. The circuit that I had designed had a bunch of unnecessary stuff which I then believed would give my robot an edge over the others. But it never worked and I had to start all over from scratch.

In my second attempt, I managed to get the robot on track. As delighted as I was with my first robot, it was nowhere near where I wanted it to be. I took it to a couple of competitions and not much to my surprise, it failed in both of them. I knew it was time to make some major changes in the design.

In my third attempt, (actually, it wasn’t the third, it was a revision of my second attempt) I updated the firmware and came up with a much more stable and accurate version. It performed well when tested and much to my delight, it finished first in two competitions and second in another. Though I was proud with what I had achieved, I felt that the robot was visually rather unappealing. And you’ll come to know why from its picture given above. It had wires running all over it and I had no other option but to rebuild it. A month or so later, I had the robot all ready and that is the current version of my first robot.

In this instructable I will guide you through the steps that I've followed in building the current version of my robot. It’s one of those robots which belong to the “scratch-built” category. You might find it difficult to find all the parts that I have used. So I insist you to read through the steps that I have followed, and then implement it in your own way with the parts that you've found.

This instructable requires that you are familiar with the following:
• Soldering and related equipments
• Hand tools like screwdrivers, wire cutters and strippers
• Reading schematics and connection diagrams
• C/C++ programming for AVR microcontrollers (optional)

Step 1: Gather the Parts

Picture of Gather the Parts

Given below is a list of components that I have used in building this robot.

Electronic Parts
• Atmega32 microcontroller
16x2 alphanumeric LCD
• LM2576 Step-Down Voltage Regulator
L298 Motor Driver Module
Lithium-Ion Rechargeable Battery Pack 11.1V 3000mAh 2C
• 9 x IR Transmitter and Receiver pair (5mm diameter)
• 10K resistor array (9 pin)
• 2N2222 transistor (or any other npn type)
• Resistors and Capacitors
• 2 x Centre Shaft Economy Series DC Motor (100 RPM)
• Switches and Push Buttons

General Parts
• Dot Matrix Prototype PCB
• Plastic Enclosure
• Single-strand Wire
40-pin DIP socket
6 pin FRC right angle male connector
Metal Studs
Plastic Spacers
Nuts and Bolts
Ball Caster Wheel
• 2 x Motor Mounting Clamp
• 2 x Wheel (50mm diameter)
• Cables and Connectors

Tools Required
• Soldering Iron
• Screw Driver
• Wire Cutter and Stripper
• Something to cut and drill plastic

In addition to the above mentioned components, you will also require an AVR programmer and a battery charger.

Now, let’s get started shall we?

Step 2: How Many Sensors?

The number of sensors to be used actually depends on the complexity of the course which the robot is supposed to cover. If the course contains sharp 90 degree turns, intersections and acute angle turns, you will have to go with at least 4 sensors.

The robot presented here has a total of nine sensors - eight of them arranged in a line and the other in front of the line at the center. Choosing the number 8 has the advantage that you can represent the status of all eight sensors using a single byte with each bit representing the state of one sensor. This will be discussed in detail in later steps.

Step 3: Batteries...Which One to Choose?

Picture of Batteries...Which One to Choose?

Batteries come in different varieties and choosing the right one for your application can be a daunting task. Autonomous mobile robots require batteries that last long and are light in weight. Lithium-ion batteries are a good choice. But they are quite costly and require a dedicated charger.
The one shown in the picture is what I have used. It is a Lithium-ion battery pack rated at 11.1V 3000mAh 2C. It has separate cables for charging and discharging. I suggest you read this excellent article on batteries written by ladyada. You can find it here.

Step 4: The Voltage Regulator

Picture of The Voltage Regulator

The robot need a constant 5V supply for the microcontroller, the sensor array and the LCD. In the first version of my robot, the 7805 linear regulator handled this job. After a couple of trial runs, I noticed that the regulator was getting heated up even with a heatsink attached to it. So in the later version, I decided to use a switching regulator and now it works fine.

SELECTING THE COMPONENTS
From the datasheet of LM2576 switching regulator (Page 12, Figure 4), you will find the value of the inductor that is to be used. It depends on the maximum input voltage and maximum output current. In my instance, the maximum input voltage is about 12V and maximum output current does not exceed 200mA. So I must have chosen a 680uH inductor. But unfortunately I couldn’t find one. All I got was a 390uH and it worked just fine.

The value of the input and output capacitors aren’t that critical. Any value above 100uF, 25V should work. The diode should be a fast recovery diode – preferably a Schottky. The one that I have used is 1N5822. The heatsink is not necessary, however I have added one as a measure of safety.

Given below are the schematic and board layout files of the voltage regulator designed in Cadsoft Eagle. You can also download the pdf files from below. You will have to get it ready on PCB or you can make it on a perfboard.

Step 5: The Sensor Array

Picture of The Sensor Array

The sensor array has a total of nine IR emitter-detector pairs. Eight of these are positioned in a line with a spacing of 18mm in between. The spacing is so chosen that the robot can cover tracks of width between 20mm and 40mm without having the need to change the program. The spacing between an emitter and the corresponding receiver is 10mm.

The sensor array circuit can be considered as two parts-one for the emitter array and the other for the detectors. Let's see each of these in detail.

DESIGNING THE IR EMITTER ARRAY
When you open the schematic file, you will notice that the IR emitters are connected in a series-parallel form. I obtained this design from LED series/parallel array wizard. All I had to do was enter the specs of the LED and the array (given below) and the wizard showed me the arrangement that consumes the least amount of power.

Source voltage = 5V
Diode forward voltage = 1.5V
Diode forward current  = 5mA
No. of LEDs in your array = 9

The transistor shown in the picture is used to turn the IR emitters ON and OFF. I have used a 2N2222 but you can use any other n-p-n transistor. The emitters are turned ON only when a reading is to be taken. This method reduces the total power consumed by the sensor array and most importantly, the effect of ambient light on sensor values is also reduced. This is accomplished by taking two readings - one with the emitters ON and the other with the emitters OFF. Subtracting the sensor values obtained in two cases, we will obtain a value that is independent of ambient light.

DESIGNING THE IR DETECTOR ARRAY
The IR detector circuit is essentially a potential divider with the IR detector connected in series with a resistor. The eight sensor array is read using the ADC and the ninth sensor is read using Pin 29 (PC7) of Atmega32. For the eight detectors, I have used a 10K resistor array and for the ninth detector I have used a separate 10K resistor.

Step 6: The Motor Driver

Picture of The Motor Driver

The motor driver is a small circuitry that controls the power supplied to the motor based on the input from a microcontroller.
The module that I have used is based on the L298 motor driver IC. It can drive two motors independently. The operating voltage is between 8V and 48V and the module can handle a maximum current of 2A per motor.

PIN FUNCTIONALITY
- I1 and I2 are logic input pins corresponding to output pins OP1 and OP2. These output pins are connected to the left motor.
- I3 and I4 are logic input pins corresponding to output pins OP3 and OP4. These output pins are connected to the right motor.
- EA is the enable input for OP1 and OP2.
- EB is the enable input for OP3 and OP4.
- VCC and GND are the supply and ground terminals for driving the motor.
- 5V and GN are the supply input to the logic pins.

CONNECTIONS
- EA, EB and 5V pins are connected to 5V supply.
- VCC is connected to battery output.
- I1 is connected to Pin 19 (PWM pin)
- I2 is connected to Pin 20
- I3 is connected to Pin 18 (PWM pin)
- I4 is connected to Pin 21

SPEED AND DIRECTION CONTROL
The microcontroller is programmed to generate a square wave of 500Hz frequency on pins 18 and 19. The dutycycle of these signals can be controlled independently.

When a logic 0 is written to Pin 20 and if dutycycle on Pin 19 is 100%, the left motor rotates in forward direction at full speed. When a logic 1 is written to Pin 21 and if dutycycle on Pin 18 is 0%, the left motor rotates in the opposite direction at full speed.

So the logic level at pins 20 and 21 determines the direction of rotation and dutycycle on Pins 18 and 19 determines the speed of rotation.

Step 7: Wiring the "Brain"

Picture of Wiring the "Brain"

Now for those who have had little experience with perfboards, this might seem as a difficult task but believe me it is a lot simpler. All you have to do is wire the standalone circuit (shown in the picture) and then add some berg connectors. If you haven't used a perfboard before, I would suggest you watch this excellent video - Circuit Skills: Perfboard Prototyping.

Referring to the pin diagram of Atmega32, the connections to be made are given below:

Pins 33 to 40 - sensor array (analog pins)
Pins 31 to 28 - sensor array (gnd, vcc, ninth sensor and emitter ON/OFF pins)

Pin 25 - Top Push Button Pin
Pin 24 - Right Push Button Pin
Pin 23 - Middle Push Button Pin
Pin 22 - Left Push Button Pin

Pins 18 to 21 - motor control pins

Pins 1 to 3 - LCD Control Pins (RS, R/W and Enable)
Pins 14 to 17 - LCD Data pins (DB4 to DB7)

Pins 6 to 11 - ISP header

Step 8: Charging and Programming Headers

Picture of Charging and Programming Headers

The right angled 6-pin programming header is connected to the microcontroller as shown in the picture. The charging header provides external access to charge the battery. It is connected to the bottom left portion of the main circuit. It is made out of berg strips, a 4-pin connector and a small piece of perfboard. Then portions are cut out from the enclosure to accommodate charging and programming headers.

Step 9: Attaching the LCD and the Push Buttons

Picture of Attaching the LCD and the Push Buttons

To connect the LCD to the main circuit, I made a breakout board. The board is built on perfboard and it has got a 10K pot for contrast adjustment. The circuit can be wired in a perfboard as shown in the picture above. The connections for the push buttons are a lot simpler. I have used a 5-pin relimate connector to connect the push button to the microcontroller circuit. The LCD and the push buttons are then attached to the enclosure cover.

Step 10: Attaching the Battery and the Switch

Picture of Attaching the Battery and the Switch

The battery and the switch are connected as shown in the picture above. When the switch is turned ON, the battery will be connected to the supply pins of the motor driver and also to the input pins of the voltage regulator. The battery is charged with the switch in OFF position.

Step 11: Attaching the Motors and the Wheels

Picture of Attaching the Motors and the Wheels

I first attached the motor mount and the wheel to both the motors. The shaft of the motor is 6mm in diameter and has an M3 thread hole for attaching the wheels. The motors are then attached to either end of a pipe extender so that the axis of the motor shafts are perfectly aligned. The whole system is attached to the bottom of the enclosure. Metal studs of 8mm length provide the necessary spacing between the wheel and the enclosure. The wires from the motors are taken out through the pipe extender and are given to the enclosure.

Step 12: Fixing the Caster Wheel

Picture of Fixing the Caster Wheel

The caster wheel is mounted on a plastic base which I cut out to the required shape. The caster wheel is mounted to the base using metal studs, bolts and nuts. The plastic base is then attached to the enclosure by means of metal studs and bolts.

Step 13: Mounting the Sensor Array

Picture of Mounting the Sensor Array

The sensor array is mounted to the same base as to which the caster wheel is attached. Cables connected to the sensor array pins are taken inside the enclosure and is connected to the microcontroller.

Step 14: Connecting the Motor Driver

Picture of Connecting the Motor Driver

To connect the motor driver with the main circuit I have used perfboard and berg connectors. The logic pins on the motor driver and the main circuit are connected by a 'bridge'. The wires of both the motors are then connected to the motor driver.

Step 15: Connecting the Voltage Regulator

Picture of Connecting the Voltage Regulator

The voltage regulator is connected as shown in the picture above. The input to the regulator is taken from the VCC and GND pins of the motor driver. The 5V output cable is connected to the microcontroller circuit.

Step 16: Let's Complete the Hardware

Picture of Let's Complete the Hardware

The charging cable is connected as shown above. Now all that's left to do is to connect the LCD and the push buttons. The cables from the LCD and push buttons are attached as shown in the picture. And finally, the cover of the enclosure is attached.

Step 17: Setting Up the Programmer

Picture of Setting Up the Programmer

Now that the hardware is all ready, let's move on to the programming part. But before starting out, you have to be ready with the following stuff.

• AVR programmer - the one that I have used is USBasp. If you have already got another programmer for AVR you can use that one too.

• USB cable - you will need it to connect the programmer with your PC or laptop.

winAVR - this is a software bundle that comes with a compiler, a programmer and a debugger for the AVR series of microcontrollers. You will have to download and install it.

• The winAVR comes with an editor - the Programmer's Notepad. But the one that I have used is Notepad++ Portable with winAVR plug-in installed in it. You can download it from below.

Now the programmer is connected as shown in the picture. Before uploading the program, we will have to configure the AVR. This is done by writing a pair of bytes called fusebits. This is discussed in detail in the next step.

You can download all the libraries and the program from below.

Step 18: Writing the Fusebits

Picture of Writing the Fusebits

Fusebits are a pair of bytes that configures several parameters of an AVR microcontroller. It decides the frequency at which the AVR operates, the start-up delay required, and many more. I have calculated the required fuses using the Engbedded AVR Fuse Calculator.

I have attached an MS-DOS Batch file which you can download. To write the fusebits, connect the programmer to the AVR and run this batch file. You should be able to see the DOS screen shown above.

In the next few steps, we will see some of the important commands used in the program. There are a total of four libraries, one each for the LCD, the sensor, the motors and the push buttons.

Step 19: Push Button Library Commands

The three functions used in the <pushbutton.h> library are:

init_pushbutton() - activates internal pull-up on push button pins. Call this function once before using any other function of this library.

get_single_button_press() - checks whether any button is pressed. If it detects any keypress, it waits for that particular key to be released and then returns the corresponding keycode.

wait_for_button_press() - waits until a key is pressed. Upon detecting a keypress, it waits for that particular key to be released. Then it returns the corresponding keycode.

Step 20: Motor Library Commands

Two functions are available under the header file <motors.h>

init_motors() - this function sets the motor driver control pins to output mode. Speed control is achieved by Pulse Width Modulation (PWM) technique. This function should be called once before using the function given below.

set_motors() - sets the speed and direction of the two motors. Speed is any value between +250 and -250. A negative value indicates that the direction of rotation is backwards. 

set_motors(250, 250) – move forward at full speed
set_motors(0, 0) – stop the motors
set_motors(-125, -125) – move backward at half the full speed

Step 21: LCD Library Commands

The library <lcd.h> has got a lot of functions but only a few are required for displaying data. They are given below.

init_lcd() - sets lcd data and control pins to outpout mode and initializes the LCD. This function should be called once prior to using any other function in this library.

print_string() - prints a text at the specified location.
print_string(2, 2, "Hello World") displays "Hello World" (without the double quotes) starting from the 2nd position of the 2nd row of the LCD.

print_integer() - prints an integer of specified number of digits at the specified location. 
print_integer(2, 1, number, 3) displays the value present in 'number' starting from the 1st position of 2nd row. The value can have a maximum of 3 digits.

clear_screen() - clears the display.

Step 22: Sensor Library Commands

The functions used in the <sensors.h> library are,

init_sensors() - initializes 10-bit ADC of Atmega32 and also sets the IR emitter control pin in output mode. This function should be called before using any other function in this library.

emitters_on() - turns the IR emitters ON.

emitters_off() - turns the IR emitters OFF.

get_sensors_binary() - reads the state of all 8 sensors and return the value as a byte.

count_binary() - takes a byte as argument and returns the number of bits that are set to 1. This is used along with get_sensors_binary()  to find out the number of sensors that are over the line.

get_front_sensor() - reads the status of the 9th sensor. This function returns a '1' if the sensor is over the line, otherwise it returns a '0'.

The function calibrate_sensors() will be discussed separately. The remaining functions are not used in the main program. I will leave it to you to find out what their purpose is.

Step 23: Algorithm...that's What Matters!

The algorithm is developed keeping in mind the following rules:
• at any intersection, if there exists a forward path, then the robot should take that path and if it doesn't exist, then the robot is free to choose any path.
• if there is any discontinuity in the line, then the robot has to move forward until it detects the line.
• there will not be any dead ends in the track.

Given below are three steps which is repeatedly executed when the robot moves over the line.

Step1
The sensor readings are taken and stored in a byte with each bit representing the status of one particular sensor. If a bit is 1, then the corresponding sensor is over the line and if the bit is 0, then it is not on the line. The following examples will make it clear.

If the value of the byte is 00011000, only the two sensors in the middle are over the line and if the value of the byte is 10000000, only the left most sensor is over the line.

Step2
A count of the number of sensors that are over the line is taken. The count may be any value between 0 and 8.

Step3
For the count obtained, the sensor reading is compared with a set of values. If a compare match is found, then the speed and direction of both motors are adjusted accordingly.

Given below are some of the values with which the sensor reading is compared. Given next to each value is the action that is to be taken.

0000000 - no line detected. Continue previous action.

10000000 - turn sharply to the left.
00000001 - turn sharply to the right.

11000000 - turn left
01100000 - turn left
00110000 - turn left
00011000 - move straight forward at full speed
00001100 - turn right
00000110 - turn right
00000011 - turn right

11100000 - turn left
01110000 - turn left
00111000 - turn left
00011100 - turn right
00001110 - turn right
00000111 - turn right
10011000 - acute angle turn towards left
00011001 - acute angle turn towards right

11110000 - 90 degree turn towards left
00001111 - 90 degree turn towards right
11001100 or 11011000 - acute angle turn towards left
00110011 or 00011011 - acute angle turn towards right
11111000 - 90 degree turn towards left
00011111 - 90 degree turn towards right
11011100 - acute angle turn towards left
00111011 - acute angle turn towards right

11111100 - 90 degree turn towards left
00111111 - 90 degree turn towards right

11111110 or 01111111 or 11111111 - turn either left or right

In the next step, we will see how the robot reacts when it detects an intersection or a sharp turn.

Step 24: Line Detection and Response

Picture of Line Detection and Response

Picture 1 shows the two most common sections which the robot will encounter. When the robot is over a straight line, both the motors are driven at full speed. But when the robot detects a turn, say to the right as shown in the picture, the right motor is slowed down so that the robot turns right. The amount by which the motor is slowed down depends on the degree of the turn.

Picture 2 shows six different sections that are tough to handle. The next six steps perform a detailed analysis on how the robot detects each of these six sections and how it reacts to it.

Picture 3 is a flowchart that depicts the series of events that takes place when a turn is detected.

Step 25: Sharp 90 Degree Turn

Picture of Sharp 90 Degree Turn

When the binary value read is 1111000 and when sensor 9 is not over the line, the robot detects a 90 degree turn to the left. So, the robot moves forward until the sensors 4 and 5 lose the line. Then, counter-clockwise rotation is performed until either sensor 4 or sensor 5 detects the line.

Step 26: Acute Angle Turn

Picture of Acute Angle Turn

When the binary value read is 1001100, the robot detects an acute angle turn to the left. So the robot moves forward until sensors 4 and 5 lose the line. Then counter-clockwise rotation is performed until either sensor 4 or sensor 5 detects the line.

Step 27: 90 Degree Intersection

Picture of 90 Degree Intersection

The binary value read is 11111111, and sensor 9 detects the line. So the turn is skipped and the robot moves forward.

Step 28: T- Shaped Section

Picture of T- Shaped Section

The binary value read is 11111111, and sensor 9 does not detect the line. So the robot moves forward until sensors 4 and 5 lose the line and then performs rotation in any specified direction.

Step 29: Discontinuity in Line

Picture of Discontinuity in Line

When the robot detects a discontinuity, the binary value read is 00000000. So the robot continues its previous action. The previous action was that corresponding to the binary value 00011000 and it is to move forward. So the robot moves forward until it detects the line again.

Step 30: Acute Angle Intersection

Picture of Acute Angle Intersection

When the binary value read is 10011000, the robot detects an acute angle turn towards the left. So it moves forward until sensors 4 and 5 lose the line. In doing so, sensor 7 detects the line before sensors 4 and 5 lose the line. So, the robot skips the turn and moves forward.

Step 31: Let's Upload the Code

Picture of Let's Upload the Code

To upload the program, first we need to set up the hardware. For this, connect the programmer to the robot and the USB cable from the programmer to your PC or laptop (as shown in Step 17). The program has to be compiled before it can be uploaded.

To compile the code, open the main.c file in Notepad++ Portable. Select  Macro and click on winAVR Compile. Alternately, you can type Ctrl+R to compile. After compiling the code, the console window will be as shown above.

Now to upload the code, go to  Macro and select winAVR Program (or type Ctrl+U). Observe the console window.

Now that the program is uploaded,  the next step is to calibrate the line sensors.

Step 32: Line Sensor Calibration



For the robot to detect the line accurately, its sensors should be calibrated. The method that I have used is the median-filter technique. It is explained in detail below. The calibration code can be obtained from the calibrate_sensors() function under the header file <sensors.h>.

The array of eight sensors is placed over the bright surface (here it’s the white line). When the calibration command is received, a set of 100 readings is taken. For each sensor, the median of their 100 readings represents its 'max value'. Next, the sensor array is placed over the dark surface (here it’s the black background) and the same procedure is repeated. This time, the median represents the 'min value'. The threshold value of each sensor is determined from its ‘max value’ and ‘min value’ using the formula given below.

threshold = min value + (max value - min value) /2

If the value read by a sensor is greater than its threshold value, then that sensor is over the bright surface, otherwise it is over the dark surface.
The minimum, maximum and threshold values of each sensor are then written to the EEPROM memory of Atmega32 so that calibration values can be retrieved every time when the robot is turned on.

Note: The ninth sensor cannot be calibrated by software as it is connected to an input pin of Atmega32. The output from the ninth sensor is either a logic 1 or a logic 0 and it depends on the value of the resistor used along with its detector. I have picked a 10K resistor for this. But I recommend that you use a potentiometer instead.

Step 33: Testing the Line Sensors

Picture of Testing the Line Sensors

To test the line sensors, first turn ON the switch. Now select Test (press the right push button). Then place the sensors over different sections of the track and observe the sensor readings.

Step 34: Optimizing the Code

Picture of Optimizing the Code

In the main.c file, there is a function by the name follow_line(). It is shown in the picture above. This function adjusts the speed of both the motors based on the value read by the line senors. For your robot to smoothly follow the line, you will have to modify the values of speed used in this function.

Step 35: A Few Notes...

Picture of A Few Notes...

There are some parameters that you can change depending upon the nature of the track where you test your robot. They are given below.

LINE COLOR
If the color of the line is dark (usually black) when compared to that of the background (usually white), you will have to edit the <sensors.h> library as shown in the picture above.

MOTOR SPEED
There are two parameters that define the speed at which the robot moves. MAXSPEED determines the maximum speed of the robot on a scale from 0 to 250. You can change this value to set the desired speed of the robot. ROTATE_SPEED determines the speed with which the robot takes a turn. These two parameters can be adjusted in the main.c file.

That's it. After 35 steps, this instructable is complete. Now all you got to do is build one on your own and explore the tracks. Good Luck!

Comments

MegaDAS made it! (author)2017-04-28

A step by step guidance to make LINE FOLLOWER ROBOT, follow this project that provides Codes and circuits to make your own robot

----------------------------------------------------------------------------------------------

Watch the complete project video from here:

RahulS54 made it! (author)2015-12-20

I implemented your line following algorithm in Arduino pro mini ........ It works fine ! Thanks :)

SouvanikD (author)RahulS542017-02-26

bro can you please send me the arduino code.

natalyc3 (author)RahulS542016-10-05

could you please send me your code ?

JuninhoALL (author)natalyc32016-11-01

Simple code.

#include <SoftwareSerial.h>

// Portas LED RGB

#define PINLEDR 9

#define PINLEDG 10

#define PINLEDB 11

// Portas Sensor de refletância

#define PINSR01 A0

#define PINSR02 A1

#define PINSR03 A2

#define PINSR04 A3

#define PINSR05 A4

#define PINSR06 A5

// Portas driver motor

#define PININ1 4

#define PININ2 2

#define PININ3 7

#define PININ4 5

#define PINENA 3

#define PINENB 6

// Portas Bluetooth

#define PINBTX 12

#define PINBRX 8

SoftwareSerial serial1(PINBRX, PINBTX);

void setup() {

inicie();

controleLedRGB(255, 0, 0, 1000);

serial1.begin(9600);

Serial.begin(9600);

controleLedRGB(0, 255, 0, 1000);

}

void loop() {

}

void inicie() {

// Portas Led RGB

pinMode(PINLEDR, OUTPUT);

pinMode(PINLEDG, OUTPUT);

pinMode(PINLEDB, OUTPUT);

// Portas Motor

pinMode(PININ1, OUTPUT);

pinMode(PININ2, OUTPUT);

pinMode(PININ3, OUTPUT);

pinMode(PININ4, OUTPUT);

pinMode(PINENA, OUTPUT);

pinMode(PINENB, OUTPUT);

}

void controleLedRGB(int r, int g, int b, int tempo) {

digitalWrite(PINLEDR, LOW);

digitalWrite(PINLEDG, LOW);

digitalWrite(PINLEDB, LOW);

analogWrite(PINLEDR, 255 - r);

analogWrite(PINLEDG, 255 - g);

analogWrite(PINLEDB, 255 - b);

delay(tempo);

}

/**

* Função para controlar motores

*/

void controleMotores(char opcao, int potencia) {

switch (opcao) {

case '4': // Direita

digitalWrite(PININ1, HIGH);

digitalWrite(PININ2, LOW);

digitalWrite(PININ3, HIGH);

digitalWrite(PININ4, LOW);

analogWrite(PINENA, potencia);

analogWrite(PINENB, potencia);

break;

case '6': // Esquerda

digitalWrite(PININ1, LOW);

digitalWrite(PININ2, HIGH);

digitalWrite(PININ3, LOW);

digitalWrite(PININ4, HIGH);

analogWrite(PINENA, potencia);

analogWrite(PINENB, potencia);

break;

case '8': // Frente

digitalWrite(PININ1, LOW);

digitalWrite(PININ2, HIGH);

digitalWrite(PININ3, HIGH);

digitalWrite(PININ4, LOW);

analogWrite(PINENA, potencia);

analogWrite(PINENB, potencia);

break;

case '2': // Trás

digitalWrite(PININ1, HIGH);

digitalWrite(PININ2, LOW);

digitalWrite(PININ3, LOW);

digitalWrite(PININ4, HIGH);

analogWrite(PINENA, potencia);

analogWrite(PINENB, potencia);

break;

case '0':

digitalWrite(PININ1, LOW);

digitalWrite(PININ2, LOW);

digitalWrite(PININ3, LOW);

digitalWrite(PININ4, LOW);

analogWrite(PINENA, 0);

analogWrite(PINENB, 0);

break;

case 'y':

leituraSensor();

break;

}

}

/**

* Função para ler os dados dos sensores via USB

*/

void leituraSensor() {

serial1.print("SR01=");

serial1.print(analogRead(PINSR01));

serial1.print(" ");

serial1.print("SR02=");

serial1.print(analogRead(PINSR02));

serial1.print(";");

serial1.print("SR03=");

serial1.print(analogRead(PINSR03));

serial1.print(" ");

serial1.print("SR04=");

serial1.print(analogRead(PINSR04));

serial1.print(";");

serial1.print("SR05=");

serial1.print(analogRead(PINSR05));

serial1.print(" ");

serial1.print("SR06=");

serial1.print(analogRead(PINSR06));

serial1.println(";");

}

/**

Função para ler os dados dos sensores

*/

void leituraSensorSerial() {

Serial.print("SR01=");

Serial.print(analogRead(PINSR01));

Serial.print(" ");

Serial.print("SR02=");

Serial.print(analogRead(PINSR02));

Serial.print(";");

Serial.print("SR03=");

Serial.print(analogRead(PINSR03));

Serial.print(" ");

Serial.print("SR04=");

Serial.print(analogRead(PINSR04));

Serial.print(";");

Serial.print("SR05=");

Serial.print(analogRead(PINSR05));

Serial.print(" ");

Serial.print("SR06=");

Serial.print(analogRead(PINSR06));

Serial.println(";");

}

FajarS24 (author)RahulS542016-11-01

Please send me this code for arduino Rahul..,thanks

fajar.shellando@gmail.com

thehalleffect (author)RahulS542016-10-12

Good on you! Can you please post a link to your code. pastebin :-)

Niranjan_Niru (author)RahulS542016-10-09

could you plz send me the procedure of replicating the same thing on arduino ? thanks in advance :)

rishabhc7 (author)RahulS542016-01-19

could u plz send ur code ?

FajarS24 (author)2016-11-08

I am try implemented this code but pushbutton not fungtion. In Lcd showing " Launch calibrate test" stop in here, i pres left button no respon. How Mr. Midun?please help,thanks

FajarS24 (author)2016-11-08

Thanks to Mr. Midun..

ashokkvab (author)2016-09-22

Bro can we use arduino uno in place of atmega 32

midhun_s (author)ashokkvab2016-10-02

Yup. Possible.

life rocks (author)2016-05-21

Where, in the rar file, is the main. c please?

life rocks (author)2016-05-19

do you need the programmer to code this awesome robot because when I opened the program.rar it was just gibberish. Also where is the main. c file please, ?

midhun_s (author)life rocks2016-05-20

You will need a programmer. I've used USBasp.

Did you try extracting the rar file? You will find main.c in it. Let me know if there's some issue.

Invento Guy (author)2016-02-21

and to follow black line, is it enough to simply change White to Black?

midhun_s (author)Invento Guy2016-04-14

Yup. That's all you need to do.

ChanakyaB (author)2015-09-29

hi i'm amila please can you tell me the whole electronics parts which were needed to built up this robot and can you please tell me 390 inductor instead of that what we can used

midhun_s (author)ChanakyaB2015-12-25

Kindly go through Step 4. You can use a 470 or 680 or even a 220 inductor. And regarding the electronics part, it will be easy for me if you could be more specific regarding what you need to know.

jali17 (author)2015-09-26

I get this problem when compiling the code, could you help me deal with this one?

hasanbasri_93 (author)jali172015-10-24

how to fix this error..

SumanD5 (author)2015-09-26

I have a question. Say, there is a block on the track. So, the bot cant go any further, it has to turn back. How to deal with that problem?

midhun_s (author)SumanD52015-09-26

You could use an ultrasonic distance sensor. You can program the bot to turn around when the distance from the bot to the block is less than a set value.

SumanD5 (author)midhun_s2015-09-27

And 1 question, I have an arduino module. So, any suggestion on the programming part?

SumanD5 (author)midhun_s2015-09-27

okay thanks.

jali17 (author)2015-09-08

Great instructable. So I have been working on replicating your work, but I'm stuck at the programming part, can you send me your .hex file and does the distance between IR sensor and Emitter is code dependent?(I think everything is good after calibration test)

jali17 (author)jali172015-09-08

send it to: jawwad.zahed@gmail.com

midhun_s (author)jali172015-09-12

Please download the program.rar from Step 17. You will find the .hex file in it.

jali17 (author)midhun_s2015-09-15

Thanks midhun_s, but I'm unable to locate the hex file in program.rar

midhun_s (author)jali172015-09-12

Thank you. The distance between an emitter and its corresponding sensor is not code dependent.

kishors2 (author)2015-08-23

what about invert in a track ??

midhun_s (author)kishors22015-08-24

The answer is in step 35.

Wildground (author)2015-08-14

can you make this with codevisionavr? help me, im confuse with the program.

midhun_s (author)Wildground2015-08-23

I am sorry I ahven't used codevision before.

Jonathanrjpereira (author)2015-08-02

What are the advantages of the extra sensor in the front as compared to a IR array with sensors in a single row(without the one in the front)?

In short Does your custom sensor have any advantages over the sensor in the image below?

In the algorithm in step 24 you can see how the front sensor helps in determining in advance whether the robot is over a turn or over an intersection. You could do this even without the front sensor but in some cases, where the track width is more, it prevents the robot from falsely identifying a straight line for a turn.

MdM10 (author)midhun_s2015-08-20

I would be grateful if you could provide me the PDF file of this book to my email address. My email address is mohib.cse.bd@gmail.com. I would like to work with robotics. Thanks.

consider the sensor in the image has 8 pairs of IR leds but none in front.

midhun_s (author)2015-03-08

There is no separate circuit for calibration. It's all done in the program. If it's the sensor array circuit that you're searching for, you can find that in step 5.

ASHISH2801 (author)2015-02-26

can u plzzz provide with the calibration circuit......i mean how to make.???? connections and all...............plzzzz

usama2000 (author)2014-11-22

what is the minimum rating for battery current wise voltage wise and charge wise

amr.samir.12139 (author)2014-11-19

i want to download the pdf of the line follower ropot

can i get help?

gary.g.singh (author)2014-10-28

can someone pls explain to me what is the device in step 17. must it be made or can be purchased?

rimolive (author)gary.g.singh2014-11-08

Just look for "AVR Programmers" and follow vendor instructions about how to program your ATMEGA32. Here's one suggestion:

https://www.sparkfun.com/products/9825

usama2000 (author)2014-10-12

Should there be a Piece paper between emitter and receiver

midhun_s (author)usama20002014-10-14

You could use heat shrink tubes instead. I've tried and it worked just fine. 5mm heat shrink tube should fit snugly on the emitter.

usama2000 (author)2014-10-10

There are four dip switches in the usbasp programmer what is their function

midhun_s (author)usama20002014-10-10

Switch 1 turns the programmer circuit on/off.
Switch 2, if turned on, provides 5V supply from USB port to the target.
Switch 3 sets slow programming mode on/off. You will have to turn this on when you are flashing program or writing bootloader into an Atmega for the first time.
Switch 4 is rarely used and it allows to update the firmware on the programmer through the same 6 pin ISP used for programming.

amaljoshy95 (author)2014-09-24

what is the use of 1st and 8th sensor? can't we make it with 7 sensors and one front sensor?it would make a byte as well