The line follower is a popular robot that can follow a black line on a white surface or a white line on a black surface. It is commonly used in industries for automation, in educational institutes to teach robotics, and in many other fields. In this blog, we will discuss the line follower with a single IR sensor using a modular library in Arduino IDE.

line follower

Materials Needed

CPU: A microprocessor board used as the robot’s brain that may be programmed or Bluetooth-controlled to do a variety of tasks. We have four ports on this board, and they are each used for various input and output tasks by connecting to various electronic parts.

Motor Driver: A circuit that enables the robot to regulate the motors’ speed and direction. It uses a separate 9V battery to supply the motors with the necessary power and voltage.

Battery-operated (BO) motors: These are DC (direct current) motors that have a gearbox attached to them, allowing them to operate at lower speeds and with more torque. In robotics and other electrical tasks, they are frequently employed.

motor control

Proximity Sensors: An IR analog proximity sensor is a type of sensor that detects the presence of an object by emitting and measuring infrared light. It provides a continuous output signal, allowing for precise control of the system. It can be used in various applications, including robotics and industrial automation.

proximity sensor

9V Battery: A common battery used in electronic projects, which provides 9 Volts of power for motor driving.

Micro USB Cable: A cable used to connect the CPU to a computer for programming or to power the CPU with a power bank.

Power Bank: A portable battery pack is used to power the robot.

Caster Wheel: A wheel that supports the front of the robot and allows it to turn easily.

Snap Wires: Wires with pre-attached connectors that can be easily snapped on and off the components, making it easy to connect and disconnect components.

Battery to Snap Connector: A connector that allows the 9V battery to be easily connected to the motor driver.

Wheels: Two wheels that drive the robot forward and backward.

Accelero Body Sheet (C1 and C2): A sheet of MDF material that is used to create the body of the robot.

Rubber Bands: Rubber bands are used to attach the body parts to each other.

Screwdriver and Screw Fasteners: Used to attach components to the body of the robot.

Building the Chassis

The robot car’s chassis should initially be constructed using the MDF sheet. Rubber bands can offer a versatile and customizable way to assemble pieces. Use the caster wheel at the front of the chassis and mount the two BO motors on the back two wheels. Mount all the electronics at their place.

Wiring the Circuit

  • According to the diagram please connect all the wires.
  • Use snap wires of different lengths to connect circuit blocks.
  • Use long snap wires for circuit blocks that are farther apart.
Line Followe Single IR

Download Arduino IDE

You can take the following actions to download the Arduino IDE:

  • Go to the official Arduino website at: www.arduino.cc
  • Click on the “Software” menu item in the top navigation bar.
  • Select the “Downloads” option from the drop-down menu.
  • Scroll down to find the section for the Arduino IDE and select the appropriate version for your operating system (Windows, Mac, or Linux).
  • Click on the download link for the selected version to start the download.
  • Once the download is complete, run the installation file and follow the instructions to install the Arduino IDE on your computer.

You can launch the Arduino IDE and begin configuring your Arduino board after installation.

Install Library

Libraries are pre-written code modules that can be used to extend the functionality of the Arduino IDE and make it easier to write code for the Arduino boards. Installing a library saves time and effort as you don’t have to write the code for the required functionality from scratch. You can simply use the pre-written code in the library and modify it according to your needs.

To install the ZIP library in the Arduino IDE, you can follow these steps:

  • Download the ZIP library from a trusted source such as the official Arduino library repository or a verified third-party library repository.
  • Open the Arduino IDE on your computer.
  • Click on the “Sketch” menu and select “Include Library” and then “Add .ZIP Library”.
  • Navigate to the location where you saved the downloaded ZIP library, select the ZIP file and click on the “Open” button.
  • Wait for the installation process to complete. You will see a notification in the Arduino IDE indicating that the library was successfully installed.

Writing the Code

Firstly, we have to include the modular library in the Arduino IDE. Then, initialize the IR sensor and motor driver in the setup() function. In the loop() function, we will read the value of IR sensor and check if the value is greater than 70. If it is greater than 70, then the robot will move left by calling the function steerBotLeftCurve() of the modular library. If it is less than 70, then the robot will move right by calling the function steerBotRightCurve().

The if-else statement is used to check the value of the IR sensor. If the value is greater than 70, the robot will move left. Otherwise, it will move right. This is a basic control statement that helps the robot follow the line.

Line Follower Robot Code using single IR

Copy to Clipboard

Uploading Code

After downloading the .ino file to your computer, you need to open it in the Arduino IDE and upload it to the CPU. Here are the steps to do so:

  • Open the Arduino IDE software on your computer.
  • Connect your CPU to the computer using a USB cable.
  • In the Arduino IDE, click on “File” and then “Open“.
  • Browse and select the .ino file that you downloaded.
  • The code will open in a new window in the Arduino IDE.
  • Before uploading the code to the CPU, make sure that the correct board type and serial port are selected from the “Tools” menu.
  • To upload the code, click on the “Upload” button (right-pointing arrow) in the Arduino IDE toolbar. The IDE will compile the code, and if there are no errors, it will upload the code to the CPU.
  • After uploading the code, the Arduino board will start running the program automatically.

Note: During the upload process, you may see some messages in the bottom section of the Arduino IDE. If the upload is successful, you will see a “Done uploading” message.

In summary, after downloading the .ino file, you need to open it in the Arduino IDE, select the correct board type and serial port, and then upload the code to the CPU. Once the upload is successful, the code will start running on the CPU.

Testing the Line Follower Robot Car

  • Place a black line on a white surface or a white line on a black surface.
  • Place the line follower robot at the starting point of the line.
  • Turn on the robot and check if it follows the line accurately.

Conclusion

In this blog, we have discussed the line follower with a single IR sensor using modular library in Arduino IDE. We have also discussed the hardware requirements, hardware connections, coding section, and testing requirements. The line follower is a basic robot that is easy to make and can be used in many fields for automation.