top of page
Writer's pictureSanskruti Ashtikar

Building a Line Follower Robot Using TinkerCAD

Updated: Nov 23

Line follower robots are an excellent project for beginners in robotics and electronics. These robots use sensors to detect and follow a line, typically a black line on a white surface. In this article, we’ll guide you through designing, simulating, and programming a basic line follower robot using TinkerCAD, an intuitive online platform for 3D design, electronics simulation, and coding.





Materials Needed:


  • Arduino Uno

  • Two IR Sensor Modules

  • Two DC Motors with Motor Driver (L298N or similar)

  • Chassis for the robot (or simulate it)

  • Wheels and Castor Wheel

  • Breadboard

  • Jumper Wires

  • Power Supply (e.g., 9V battery)

  • TinkerCAD account


Step 1: Understanding the Line Follower Robot Circuit


A line follower robot operates by using infrared (IR) sensors to detect the presence or absence of a line beneath it. The IR sensors emit infrared light and measure the reflection; a black line will absorb the light, leading to a low signal, while a white surface reflects the light, leading to a high signal.

In our design, two IR sensors will be used—one on the left side and one on the right. The sensors will send signals to the Arduino, which will process the data and control the motors accordingly to steer the robot along the line.


Step 2: Setting Up the Components in TinkerCAD


  1. Arduino Uno: Place the Arduino Uno on the TinkerCAD workspace. This will be the brain of your line follower robot, receiving signals from the sensors and controlling the motors.

  2. IR Sensor Modules: Place two IR sensor modules on your robot’s front side, one on the left and the other on the right.

    • Left IR Sensor:

      • VCC to 5V on Arduino

      • GND to GND on Arduino

      • OUT to digital pin 2 on Arduino

    • Right IR Sensor:

      • VCC to 5V on Arduino

      • GND to GND on Arduino

      • OUT to digital pin 3 on Arduino

  3. Motor Driver (L298N): Place the L298N motor driver on the breadboard. The L298N is used to control the speed and direction of the motors.

    • IN1 to IN4: These pins control the direction of the motors.

      • IN1 to digital pin 8 on Arduino

      • IN2 to digital pin 9 on Arduino

      • IN3 to digital pin 10 on Arduino

      • IN4 to digital pin 11 on Arduino

    • EN1 and EN2: These enable the motors.

      • EN1 and EN2 to 5V on Arduino (can be connected to PWM pins for speed control)

    • Motor Connections: Connect the left motor to OUT1 and OUT2, and the right motor to OUT3 and OUT4.

    • Power Supply: Connect a 9V battery or other power source to the motor driver’s VCC and GND. Don’t forget to connect the Arduino’s GND to the motor driver’s GND.

  4. DC Motors and Wheels: Attach two DC motors to the robot chassis and connect them to the motor driver as mentioned. Add wheels to the motors and a castor wheel for balance.





Step 3: Writing the Arduino Code


Now that your circuit is set up, it’s time to write the code that will control the line follower robot. The code will read inputs from the IR sensors and adjust the motor speeds to keep the robot on the line.


int leftSensor = 2;
int rightSensor = 3;
int leftMotor1 = 8;
int leftMotor2 = 9;
int rightMotor1 = 10;
int rightMotor2 = 11;
void setup() {
  pinMode(leftSensor, INPUT);
  pinMode(rightSensor, INPUT);
  pinMode(leftMotor1, OUTPUT);
  pinMode(leftMotor2, OUTPUT);
  pinMode(rightMotor1, OUTPUT);
  pinMode(rightMotor2, OUTPUT);
}
void loop() {
  int leftState = digitalRead(leftSensor);
  int rightState = digitalRead(rightSensor);
  if (leftState == HIGH && rightState == LOW) {
    // Turn right
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
  } else if (leftState == LOW && rightState == HIGH) {
    // Turn left
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
  } else if (leftState == HIGH && rightState == HIGH) {
    // Move forward
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
  } else {
    // Stop
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
  }
}




Step 4: Simulating the Circuit in TinkerCAD


Once the circuit is ready, simulate the robot’s behavior in TinkerCAD.

  1. Start the Simulation: Click the "Start Simulation" button. The IR sensors will detect the line and control the motors based on the line’s position.

  2. Observe the Robot’s Behavior: If both sensors detect the line, the robot moves forward. If only one sensor detects the line, the robot turns in the opposite direction to realign itself.

  3. Troubleshooting: If the robot doesn’t behave as expected, check the wiring, sensor placement, and code. Ensure the sensors are positioned correctly to detect the line accurately.


Step 5: Building the Physical Robot


After simulating the circuit successfully in TinkerCAD, you can build the physical robot.

  1. Assemble the Components: Transfer the design from TinkerCAD to a real breadboard and chassis. Secure the components, such as motors and sensors, to the chassis.

  2. Upload the Code: Connect the Arduino to your computer and upload the code.

  3. Test the Robot: Place the robot on a track with a black line on a white surface. Power the robot and observe its movements, adjusting the sensor positions or code as needed for optimal performance.


Conclusion


Congratulations! You have successfully designed, simulated, and programmed a line follower robot using TinkerCAD. This project introduces key concepts in robotics, such as sensor integration, motor control, and algorithm development.

With the basic design in place, you can enhance your line follower robot by adding features like speed control, obstacle detection, or even a more complex path-following algorithm. TinkerCAD provides an excellent platform for experimenting with different ideas before building your robot in the real world.

Keep exploring and tinkering with your robot designs—there's always more to learn and

create! Happy building!


Want us to guide you through your project or make the project for you ?







Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



39 views0 comments

Related Posts

See All

Comentarios


bottom of page