Hello

Welcome lekule blog

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation.
together in the world. #lekule86
Join us on

How to Build a Robot - Line Follower

Overview

This is part 4 of a series of articles on my experiences building a robot that can do various things. I thought it would be neat to create a robot that was easy to put together with a single soldering iron and was also affordable. I made up the following requirements for my robot:

    Many kits are expensive, so it must be relatively inexpensive.
    It must be easily put together without special equipment.
    It must be easily programmable without a complicated IDE or programmer.
    It must be powerful enough for expandability.
    It should run off a simple power source.
    It should be able to follow a line or a wall, and avoid obstacles.

In this article I'll talk about how to program the robot to be a line follower.


Follow a line?


A line follower is the easiest way to make a robot follow a pre-determined path. You only need a way to move and a sensor to determine if the robot is on the line or not. There have been may algorithms developed to keep the robot on the line. The field of engineering that covers these algorithms is called control theory. For this article, I'm going to make a really simple algorithm. In pseudo code:



                 
is robot to the left of the line?
    turn right
is the robot to the right of the line?
    turn left
is the robot on the line?
    move forward

               


Finding a suitable surface

Many people use black electrical tape on the floor to do robots. This is a huge pain and creates a mess. A white dry erase board is a great surface to try out different line following courses. I found this 2x4' board at Home Depot for $10. You can easily add tracks by drawing with a black marker. The white background and the black marker have enough contrast so that the sensors can easily distinguish the line. Rather than calibrate the sensors for every surface, I'm going to assume that they all read approximately the same for a given color. Then I can compare them relative to one another to determine which sensor is currently reading the darkest value. As long as the line I draw only covers up one sensor at a time, this algorithm will provide a reliable way to determine the position of the robot.


Writing the Program

The code below begins by initializing the robot driver and then waiting 5 seconds. This allows me enough time to put the robot on the track before it starts moving. After that, the robot continuously checks the sensors and determines how to move using the algorithm above. The forward speed can be set using the ROBOT_SPEED define. This is a number out of 255. If the robot moves too fast, the algorithm may not have enough time to correct the motion. I also added a check for if the robot is picked up or is about to fall off the course. If all the sensors are reading 1000, that means the robot is most likely off the ground because none of the light is reflecting back. This is useful if you want the robot to stop while you're moving it around.
Potential Improvements

This algorithm does not use averaging or keep track of error. You'll notice in the video below that sometimes the robot looks like it's shaking back and forth. This is caused by oscillations in the algorithm because the robot overshoots the line. One method to fix this would be to use a PID (proportional-integral-derivative) algorithm. In a nut shell, this type of algorithm keeps track of where the robot was (integral), where it might be going (derivative), and where it currently is (proportional). The algorithm I implemented only cares about what is currently happening to the robot. If you wanted to have a faster robot, you would likely need to remove the oscillations (over-corrections) that are slowing the robot down.



                 
#include "robot.h"
#define ROBOT_SPEED  100

void setup()
{
  Serial.begin(38400);
  Serial.println("Boot");
  rbt_init();
  delay(5000);
}

uint16_t lleft,lmid,lright;
boolean wleft,wmid,wright;
void loop()                  
{
  rbt_sns(&lleft,&lmid,&lright,&wleft,&wmid,&wright);
  Serial.print("Left: ");
  Serial.print(lleft);
  Serial.print("Mid: ");
  Serial.print(lmid);
  Serial.print("Right: ");
  Serial.println(lright);
  //off the line
  if(lleft == 1000 && lmid == 1000 && lright == 1000){
    rbt_move(BRAKE,0);
  }
  //follow track
  else{
    if(lleft > lmid && lleft > lright){
      rbt_move(LEFT,ROBOT_SPEED);
    }
    if(lmid > lleft && lmid > lright){
      rbt_move(FWD,ROBOT_SPEED);
    }
    if(lright > lmid && lright > lleft){
      rbt_move(RIGHT,ROBOT_SPEED);
    }
  }
}

               




Follow a line!



Conclusion

In this article I showed the process of writing a control algorithm to follow a line. A line follower is a neat way to learn about control theory and watch a robot navigate a course completely autonomously! In the next article, I'll make the robot navigate around a floor and avoid bumping into obstacles and walls.

Share this:

ABOUTME

Hi all. This is deepak from Bthemez. We're providing content for Bold site and we’ve been in internet, social media and affiliate for too long time and its my profession. We are web designer & developer living India! What can I say, we are the best..

Post a Comment
My photo

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation. I believe everyday can become a Electrician with the right learning materials.
My goal with BLOG is to help you learn Electrical.

Labels

LEKULE TV EDITORIALS ARTICLES DC ROBOTICS DIGITAL SEMICONDUCTORS GENERATOR AC EXPERIMENTS MANUFACTURING-ENGINEERING REFERENCE FUNDAMENTAL OF ELECTRICITY ELECTRONICS ELECTRICAL ENGINEER MEASUREMENT TRANSDUCER & SENSOR VIDEO ARDUINO RENEWABLE ENERGY AUTOMOBILE TEARDOWN SYNCHRONOUS GENERATOR DIGITAL ELECTRONICS ELECTRICAL DISTRIBUTION CABLES AUTOMOTIVE MICROCONTROLLER SOLAR PROTECTION DIODE AND CIRCUITS BASIC ELECTRICAL ELECTRONICS MOTOR SWITCHES CIRCUIT BREAKERS CIRCUITS THEORY PANEL BUILDING ELECTRONICS DEVICES MIRACLES SWITCHGEAR ANALOG MOBILE DEVICES WEARABLES CAMERA TECHNOLOGY COMMUNICATION GENERATION BATTERIES FREE CIRCUITS INDUSTRIAL AUTOMATION SPECIAL MACHINES ELECTRICAL SAFETY ENERGY EFFIDIENCY-BUILDING DRONE CONTROL SYSTEM NUCLEAR ENERGY SMATRPHONE FILTER`S POWER BIOGAS BELT CONVEYOR MATERIAL HANDLING RELAY ELECTRICAL INSTRUMENTS ENERGY SOURCE PLC`S TRANSFORMER AC CIRCUITS CIRCUIT SCHEMATIC SYMBOLS DDISCRETE SEMICONDUCTOR CIRCUITS WIND POWER C.B DEVICES DC CIRCUITS DIODES AND RECTIFIERS FUSE SPECIAL TRANSFORMER THERMAL POWER PLANT CELL CHEMISTRY EARTHING SYSTEM ELECTRIC LAMP FUNDAMENTAL OF ELECTRICITY 2 BIPOLAR JUNCTION TRANSISTOR 555 TIMER CIRCUITS AUTOCAD BLUETOOTH C PROGRAMMING HOME AUTOMATION HYDRO POWER LOGIC GATES OPERATIONAL AMPLIFIER`S SOLID-STATE DEVICE THEORRY COMPUTER DEFECE & MILITARY FLUORESCENT LAMP INDUSTRIAL ROBOTICS ANDROID ELECTRICAL DRIVES GROUNDING SYSTEM CALCULUS REFERENCE DC METERING CIRCUITS DC NETWORK ANALYSIS ELECTRICAL SAFETY TIPS ELECTRICIAN SCHOOL ELECTRON TUBES FUNDAMENTAL OF ELECTRICITY 1 INDUCTION MACHINES INSULATIONS USB ALGEBRA REFERENCE HMI[Human Interface Machines] INDUCTION MOTOR KARNAUGH MAPPING USEUL EQUIATIONS AND CONVERSION FACTOR ANALOG INTEGRATED CIRCUITS BASIC CONCEPTS AND TEST EQUIPMENTS DIGITAL COMMUNICATION DIGITAL-ANALOG CONVERSION ELECTRICAL SOFTWARE GAS TURBINE ILLUMINATION OHM`S LAW POWER ELECTRONICS THYRISTOR BOOLEAN ALGEBRA DIGITAL INTEGRATED CIRCUITS FUNDAMENTAL OF ELECTRICITY 3 PHYSICS OF CONDUCTORS AND INSULATORS SPECIAL MOTOR STEAM POWER PLANTS TESTING TRANSMISION LINE C-BISCUIT CAPACITORS COMBINATION LOGIC FUNCTION COMPLEX NUMBERS CONTROL MOTION ELECTRICAL LAWS INVERTER LADDER DIAGRAM MULTIVIBRATORS RC AND L/R TIME CONSTANTS SCADA SERIES AND PARALLEL CIRCUITS USING THE SPICE CIRCUIT SIMULATION PROGRAM AMPLIFIERS AND ACTIVE DEVICES APPS & SOFTWARE BASIC CONCEPTS OF ELECTRICITY CONDUCTOR AND INSULATORS TABLES CONDUITS FITTING AND SUPPORTS ELECTRICAL INSTRUMENTATION SIGNALS ELECTRICAL TOOLS INDUCTORS LiDAR MAGNETISM AND ELECTROMAGNETISM PLYPHASE AC CIRCUITS RECLOSER SAFE LIVING WITH GAS AND LPG SAFETY CLOTHING STEPPER MOTOR SYNCHRONOUS MOTOR AC METRING CIRCUITS BECOME AN ELECTRICIAN BINARY ARITHMETIC BUSHING DIGITAL STORAGE MEMROY ELECTRICIAN JOBS HEAT ENGINES HOME THEATER INPECTIONS LIGHT SABER MOSFET NUMERATION SYSTEM POWER FACTORS REACTANCE AND IMPEDANCE INDUCTIVE RECTIFIER AND CONVERTERS RESONANCE SCIENTIFIC NOTATION AND METRIC PREFIXES SULFURIC ACID TROUBLESHOOTING TROUBLESHOOTING-THEORY & PRACTICE 12C BUS APPLE BATTERIES AND POWER SYSTEMS DC MOTOR DRIVES ELECTROMECHANICAL RELAYS ENERGY EFFICIENCY-LIGHT INDUSTRIAL SAFETY EQUIPMENTS MEGGER MXED-FREQUENCY AC SIGNALS PRINCIPLE OF DIGITAL COMPUTING QUESTIONS REACTANCE AND IMPEDANCE-CAPATIVE SEQUENTIAL CIRCUITS SERRIES-PARALLEL COMBINATION CIRCUITS SHIFT REGISTERS WIRELESS BUILDING SERVICES COMPRESSOR CRANES DIVIDER CIRCUIT AND KIRCHHOFF`S LAW ELECTRICAL DISTRIBUTION EQUIPMENTS 1 ELECTRICAL DISTRIBUTION EQUIPMENTS B ELECTRICAL TOOL KIT ELECTRICIAN JOB DESCRIPTION INDUSTRIAL DRIVES LAPTOP SCIENCE THERMOCOUPLE TRIGONOMENTRY REFERENCE UART oscilloscope BIOMASS CONTACTOR ELECTRIC ILLUMINATION ELECTRICAL SAFETY TRAINING ELECTROMECHANICAL FEATURED FILTER DESIGN HARDWARE JUNCTION FIELD-EFFECT TRANSISTORS NASA NUCLEAR POWER VALVE COLOR CODES ELECTRIC TRACTION FLEXIBLE ELECTRONICS FLUKE GEARMOTORS INTRODUCTION LASSER PID PUMP SEAL ELECTRICIAN CAREER ELECTRICITY SUPPLY AND DISTRIBUTION MUSIC NEUTRAL PERIODIC TABLES OF THE ELEMENTS POLYPHASE AC CIRCUITS PROJECTS REATORS SATELLITE STAR DELTA VIBRATION WATERPROOF