Yet Another Line Following / Obstacle Avoidance 2WD Car




About: My goal is to captivate, inspire and engage young engineers through intriguing robotics projects. I use Arduino at my robotics workshops since it is the most cost-effective way to build a robot using commod...

This robot car is nothing new. Instructables and Youtube are peppered with a robot car similar to this one and honestly those postings inspired me to put together this affordable robotics kit that I could handout at my Robotics workshop (level 1) for grades 6-12. As far as what it does, the title says it all (or see the video) so I won’t bore you with details. This robot isn’t going to win any competitions or awards for being best of _whatever_ but it is an affordable kit which is perfect for educational purposes.

(Update: I made a line-following billboard bot with this platform)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Parts

This is a standard kit for my Robotics workshop (Level 1) and you can find parts on-line (except bumper). However, if you like to support my mission* of teaching youth Robotics, you may be able to order the same kit in the future. (*I only assess materials fee for the workshop.)

The kit contains:

  • 2WD car chassis w/ 2 motors, caster, and 6v battery holder (added extra holes for custom mods)
  • custom-made bumper to attach sensors (I couldn't find anyone selling this so I made it out of corner protector you can buy at Home Depot)
  • 9V battery holder
  • Arduino Uno compatible board
  • Motor shield
  • Ultrasonic sensor
  • 2 x infrared sensor
  • Mini breadboard
  • 20 x wire tie
  • 8 x 1in square foam tape
  • 20 x MF 20cm Dupont connector
  • 10 x MM 20cm Dupont connector
  • USB to mini USB cable
  • 4 x AA battery
  • 1 x 9v battery
  • Velcro strap for 6v battery holder (batteries pop out from time to time)
  • Additional flathead M3 7mm and 10mm screws for the bumper and the 9v battery holder.
  • Precision screwdriver set

While motor connectors are pre-soldered with Dupont connectors, soldering is still required for the switch. The plan for the next release is to have all Dupont connections. No soldering! Also, all the flathead screw holes have been counter-sink.

Step 2: Assemble the Car

See the presentation below for assembling the car.

Part 1: Chassis, Motor, Motor Shield, and Arduino (or compatible) board

Part 2: Sensors

Step 3: Compile and Upload

Download following codes into your Arduino IDE, compile, and upload based on your scenario.

1) Obstacle Avoidance Bot

2) Line Following Bot

Step 4: Run

If you have followed my wire connections and pin assignment, the 2 codes for obstacle avoidance and line follower should run out of box. Through my Robotics workshop, my aim is to inspire younger generations to love science and engineering by making something with their hand and learn from doing it...rather than just playing games on smartphones.

If you enjoyed my tutorial and video, please vote for this Instructables for the "Full Spectrum Laser" contest. The laser-cutter would allow me and the kids to fabricate additional parts for future workshops - robot laser tag, self balacing bot, drone, etc.

Full Spectrum Laser Contest 2016

Participated in the
Full Spectrum Laser Contest 2016

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    14 Discussions

    Kyle WinstonC

    Question 8 months ago on Step 3

    Hi im using an arduino uno, i have also checked both codes. What should i do if I want my robot to stop when there is an obstacle while following a line? thanks

    1 answer
    botdemyKyle WinstonC

    Answer 8 months ago

    Basically you have to have ultrasonic sensor check supersedes line following:


    if ultrasensor value < some distance (maybe 10cm) {
    else {
    line following code here


    1 year ago

    This project is Great for me!

    but I want to make a obstacle avoiding and line following car.
    how to combine and use three sensors value.


    Question 1 year ago on Step 4

    This project is Great for me!

    but I want to make a obstacle avoiding and line following car.
    how to combine and use three sensors value.


    2 years ago

    mình thay bằng mạch cầu H L298N được không


    2 years ago

    Can i use adafruit motor shield instead of your motor shield and how that changes the code?

    2 replies

    Reply 2 years ago

    I'm not sure what type of Adafruit motor shields you have but I believe adafruit has a good tutorial on how to use their products. Adafruit may even have a library so you could use the library and their functions in your code.

    Basically you have 6 pins to control: left +, left -, left pwm/ena, right +, right -, and right pwm/ena. If you're not going to use PWM, set PWM/ENA pins to always high. (Mine came with jumpers to set them always high). If you do that, you now have 4 pins to control - 2 for each motors. Just play with the code until it works. That's the best way to learn.


    Reply 3 years ago

    You will have to figure out on your own. That shouldn't be too difficult. Basically, your main loop has to check 3 sensors (2 IR and 1 Ultransonic) for their values and decide what you want to do. For example, below is another version I have worked on. It checks for all 3 sensors.


    3 years ago

    Hello, thank you for the tuto.

    I would like to make the line follower, but it doesn't work and i try to know why.
    I use a L293D motor Driver expansion instead of your motor shield. How that changes the code ?

    Thanks for the help

    1 reply

    Reply 3 years ago

    I am not sure but for two wheel configuration, you just need to control 6 input - 2 for motor and one pwm per wheel.


    3 years ago

    This is great! What would you estimate the total cost to be to build it?

    1 reply

    Reply 3 years ago

    I buy 10 pcs at a time and total cost of each comes out less than $40 including the plastic container. If you're buying for just one, the cost would be slightly higher.