VEEROBOT Docs
StoreBlogWiki
  • 🌐Introduction
  • ROS Based Robots
    • 🐺Wolf Robot
      • ROS Introduction
      • Getting Started with ROS 2
      • Introduction to Wolf Robot
      • ROS 2 Setup
      • ROS Concepts
      • Using Wolf Examples
      • Creating a URDF File
      • Visualising in Gazebo
      • Controlling motors from ROS
      • LiDAR Basics & Control
      • Using a Camera with ROS2
      • ROS 2 Cleanup
      • ROS 2 Controller
      • Teleoperation
      • Slam Navigation
      • Wolf : Conclusion
  • Arduino Based Robots
    • 🚜Micro:Xbot
      • Preparations before First Use
      • Programming the Board
      • Powering the Board
      • Pin Mapping
      • Basic Programs
        • Blinking LED
        • Buzzer Program
        • Fading LED
        • RGB LED
        • Light Detection
        • Battery Voltage
        • Line Follower Module
        • Ultrasonic Sensor
        • Infrared Remote Control
        • Motor Control
        • Bluetooth Control
        • Display Test
        • Test Me
      • Robot Assembly
      • Advanced Programs
        • Bluetooth Controlled Robot
        • Obstacle Avoidance Robot
        • Line Follower Robot
  • ROS2 Repo
    • Introduction
    • Page 1
      • Sub Page 1
    • Page 2
Powered by GitBook
On this page
  1. Arduino Based Robots
  2. Micro:Xbot
  3. Basic Programs

Line Follower Module

Micro:Xbot board comes with three infrared sensor modules on the back side of the board. These three sensors together help the robot follow a line.

 0 - 0 - 0
 0 - 0 - 1
 0 - 1 - 0
 0 - 1 - 1
 1 - 0 - 0
 1 - 0 - 1
 1 - 1 - 0
 1 - 1 - 1

In the table above, if we consider a black line detection as 0 and a white space as 1, then there are eight possibilities and accordingly we can utilise the values to drive a robot and tell it to follow a line.

/*
  Line Follower Module: Reads values from three different infrared modules and suggests actions

  At VEEROBOT, we invest time and resources providing this open source code,
  Please support VEEROBOT and open-source hardware by purchasing products
  from us @ http://veerobot.com
  -----------------------------------------------------------------------------
  You are free to redistribute it and/or modify it under the terms of the GNU
  Lesser General Public License as  published by the Free Software Foundation,
  either version 3 of the License, or (at your option) any later version.

  This Code is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  See <http://www.gnu.org/licenses/>
*/

#include "config.h"

void setup() {
  Serial.begin(9600);
}

void loop() {
  byte linecolor_threshold = 100; // tune this value measuring against the lines
  int s1, s2, s3;
  s1 = analogRead(LF1); // Right
  s2 = analogRead(LF2); // Center
  s3 = analogRead(LF3); // Left
  Serial.print((String)"Right Sensor :" + s1 + " | Center Sensor :" + s2 + " | Left Sensor :" + s3); // Print to serial monitor

  // 0 is black and 1 is white
  if ((s1 < linecolor_threshold) && (s2 < linecolor_threshold) && (s3 < linecolor_threshold))       Serial.println(" | 0 - 0 - 0 : Go Straight");
  else if ((s1 < linecolor_threshold) && (s2 < linecolor_threshold) && (s3 > linecolor_threshold))  Serial.println(" | 0 - 0 - 1 : Slow Right");
  else if ((s1 < linecolor_threshold) && (s2 > linecolor_threshold) && (s3 < linecolor_threshold))  Serial.println(" | 0 - 1 - 0 : Split Lines");
  else if ((s1 < linecolor_threshold) && (s2 > linecolor_threshold) && (s3 > linecolor_threshold))  Serial.println(" | 0 - 1 - 1 : Turn Right");
  else if ((s1 > linecolor_threshold) && (s2 < linecolor_threshold) && (s3 < linecolor_threshold))  Serial.println(" | 1 - 0 - 0 : Slow Left");
  else if ((s1 > linecolor_threshold) && (s2 < linecolor_threshold) && (s3 > linecolor_threshold))  Serial.println(" | 1 - 0 - 1 : Go Straight");
  else if ((s1 > linecolor_threshold) && (s2 > linecolor_threshold) && (s3 < linecolor_threshold))  Serial.println(" | 1 - 1 - 0 : Turn Left");
  else if ((s1 > linecolor_threshold) && (s2 > linecolor_threshold) && (s3 > linecolor_threshold))  Serial.println(" | 1 - 1 - 1 : Stop");
  delay(300);
}

Once the program is uploaded, open serial monitor and move your finger against each of the sensors. The program checks the status of each sensor and suggests what the robot has to do when a certain criteria is met.

PreviousBattery VoltageNextUltrasonic Sensor

Last updated 2 years ago

🚜