Build a 4WD car using the L293D module

Arduino Uno tutorials

🕑 This lesson will take about 30 minutes

In this lesson, you will learn how to build a 4WD car using an Arduino Uno and the L293D motor shield. This motor shield allows you to connect up to four DC motors as well as a battery pack to supply power. The shield connects to the top of an Arduino board.

Required parts

  • Arduino Uno

  • L293D motor shield

  • Car chassis

  • 4 x DC motors (with two wires soldered to each motor)

  • 4 x wheels attached to DC motors

  • 4xAA battery holder

  • 4 x AA batteries

  • Ultrasonic sensor (optional)

  • 4 x female-to-female wires (if using an ultrasonic sensor)

Connecting the parts

The diagram below shows how to connect the four motors and the AA battery pack to the L293D motor shield. The motor shield pins attach to the top of the Arduino.

Sample code (without ultrasonic sensor)

This code can be used to test the L293D motor shield with the Arduino. The program will make the car drive forward and backward, repeatedly. First, you will need to download and unzip the Adafruit-Motor-Shield-library-master library from https://github.com/adafruit/Adafruit-Motor-Shield-library . Extract the ZIP file and copy the folder into the Arduino/libraries directory on your computer (likely inside your Documents folder). You may need to restart the Arduino app after installing the library.

Sample code (with ultrasonic sensor)

This code works with an ultrasonic sensor attached to the L293D motor shield to check if there are any obstacles within 10cm of the car. If there is an obstacle in front of the car, it will reverse and then try driving forward again. This code can be modified to make the car move around an obstacle or find an alternative route. First, you will need to download and unzip the Adafruit-Motor-Shield-library-master library from https://github.com/adafruit/Adafruit-Motor-Shield-library . Extract the ZIP file and copy the folder into the Arduino/libraries directory on your computer (likely inside your Documents folder). You may need to restart the Arduino app after installing the library.