Build an Arduino Self-Driving Car
Summary
Overview
This eight-part lesson will guide you through building and programming Arduino-controlled autonomous cars with your students. Each part contains a detailed step-by-step video and a supplemental lesson plan PDF with learning objectives, assessment opportunities, and appendices with circuit diagrams and example code. You can present the material yourself or have students follow along with the videos and pause to work on their autonomous cars.
Learning Objectives
- Learn to build circuits and program individual parts of an autonomous car, including:
- Using an H-bridge to control speed and direction of motors
- Using an ultrasonic sensor to detect obstacles
- Using infrared sensors to detect lines
- Design and implement an algorithm for self-driving behavior, such as automatic obstacle avoidance and automatic lane following
NGSS Alignment
This lesson helps students prepare for these Next Generation Science Standards Performance Expectations:- HS-ETS1-2. Design a solution to a complex real-world problem by breaking it down into smaller, more manageable problems that can be solved through engineering.
|
Science & Engineering Practices
Constructing Explanations and Designing Solutions. Design a solution to a complex real-world problem, based on scientific knowledge, student-generated sources of evidence, prioritized criteria, and tradeoff considerations.
|
Disciplinary Core Ideas
ETS1.C: Optimizing the Design Solution.
Criteria may need to be broken down into simpler ones that can be approached systematically, and decisions about the priority of certain criteria over others (trade-offs) may be needed.
|
Crosscutting Concepts
Influence of Science, Engineering, and Technology on Society and the Natural World. New technologies can have deep impacts on society and the environment, including some that were not anticipated. Analysis of costs and benefits is a critical aspect of decisions about technology.
|
Materials
Each group of students will need:
- Science Buddies BlueBot Robotics Kit
- Electronics Kit for Arduino
-
Windows or Mac computer. See this page if you have a Chromebook. Your computer will need:
- Access to the Arduino IDE, either installed local version or web-based editor (note that Chromebooks can only use the web version). Watch this video for a comparison of the two options.
- USB port. The Science Buddies kit comes with a USB-A to B cable. The "B" end plugs into the Arduino and the "A" end plugs into your computer. You will need an adapter or different cable if your computer only has USB-C ports. Watch this video to learn about the different types of cables and adapters.
You will also need materials to make at least one test track for your classroom, such as posterboard, construction paper, and colored tape. See the track creation guide for suggestions.
Background Information for Teachers
This section contains a quick review for teachers of the science and concepts covered in this lesson.Note: This course assumes that students have worked with Arduino before and are familiar with some of the basics like blinking an LED and using a button. If you are introducing your students to Arduino for the first time, please see the Introduction to Arduino lesson plan at Science Buddies before starting this lesson. That way, your students will be ready to dive right into the more advanced topics in this course, like controlling the sensors and motors that you will need for an autonomous vehicle.
Self-driving, or autonomous, cars are becoming a part of daily life. Even if they are too young to drive, students might be curious about how self-driving cars work, or wonder whether they're safe. Having students build, program, and test their own self-driving cars is a great way to introduce them to new programming and electronics topics. First, students will learn how to control the speed and direction of motors with an Arduino, and how to use the motors to steer their car. Next, they will learn how to use two different types of sensors — ultrasonic and infrared — to detect obstacles and lane lines. Finally, they will synthesize everything they have learned to program a self-driving car that can autonomously navigate a track.
Each lesson in this course contains a video that walks students step-by-step through building the circuit and programming one key feature of a self-driving Arduino car, culminating in designing a full algorithm for the car's operation. You can choose to have your students follow the videos directly, or use the supplemental lesson plan PDFs and present the material yourself. Each PDF contains appendices with the relevant circuit diagrams and example code for the lesson, along with learning objectives and assessment opportunities.
Note that you will need to assemble the BlueBot chassis for each vehicle. Once assembled, these chassis can be re-used year after year. Instructions for assembling the chassis are available in this video:
Note that the video shows the battery pack mounted on top of the chassis. When adding an Arduino to the car, you should put it on the top plate so it is next to the breadboard. You can mount the batteries on the lower plate. Double-sided foam tape works well to quickly attach parts to the chassis, as opposed to using screws.
Many of the videos in these lessons use Tinkercad Circuits, an online circuit simulator, to demonstrate building circuits and programming the Arduino. Your students can follow along with a physical Arduino, but you can also use Tinkercad Circuits as a teaching tool. This video provides an introduction to Tinkercad Circuits:
More high-quality computer science lessons can be found at Infosys' Pathfinders Online Institute.
Additional Background Links
- How to Use an Arduino, Science Buddies
- How to Use a Breadboard for Electronics and Circuits, Science Buddies
- Resistor Guide, Science Buddies
Prep Work (time varies)
- Make sure your classroom computers are set up so students can use the Arduino IDE. There are several different options. To install the IDE locally, follow the instructions on the Arduino software page for the correct operating system. Follow these getting started instructions to use the web-based editor (this will require students to create an online account). If your students use Chromebooks, see the Use Arduino with Chromebook page.
- Assembling the Bluebot chassis is not included in the time estimate for this lesson. If you are going to have students assemble their own chassis, plan to use one class period for that before starting the rest of the lesson.
- You need to set up at least one track for students to test their cars. See the track creation guide for suggestions.
Lessons
Part 1: Controlling a Motor
In this part of the lesson students will learn how to control a single motor with an Arduino and a chip called an H-bridge. This circuit can be built without the BlueBot chassis.
Part 2: Steering with Two Motors
In this lesson students will learn how to simultaneously control two motors, and how to use the motors to steer their vehicle. The initial circuit to test the motors can be built without the BlueBot chassis. You will need to mount the Arduino and breadboard on an assembled chassis to make a car steer.
Part 3: Controlling Motor Speed
In this part of the lesson students will learn how to change a motor's speed instead of just turning it fully on or off. This lets students drive and steer their car more gently at lower speeds, which is especially useful to avoid overshooting curves when testing on a track.
Part 4: Using the Ultrasonic Distance Sensor
In this part of the lesson students will learn how to use the ultrasonic sensor to measure the distance to a target object. The sensor can be tested standalone using an Arduino without the motor control circuit from previous lessons or attached to an assembled car.
Part 5: Detecting Obstacles
In this part of the lesson students will apply what they have learned so far to make their autonomous car automatically stop when it detects an obstacle.
Part 6: Using the Infrared Sensors
In this part of the lesson students will learn how to use the infrared sensor to differentiate between light and dark surfaces. The sensors can be tested standalone using an Arduino without the motor control circuit from previous lessons, or attached to an assembled car.
Part 7: Following a Lane
In this part of the lesson students will apply what they have learned so far to make their self-driving car automatically stay in between two lane lines when driving.
Part 8: Designing an Algorithm
In this lesson students will design an algorithm for their autonomous vehicle and implement it using Arduino code to control their self-driving car using input from multiple sensors.
Optional: if you are incorporating NGSS into your lesson plan, this is a good place to include the engineering design standards. For example:
- What criteria would the students define for a successful algorithm?
- Can they break their algorithm down into smaller parts to make it more manageable?
- Are there any trade-offs between different criteria?
- What could the real-world effects of these tradeoffs be? This is a very real problem faced by the engineers designing autonomous cars. For example, if the car could not stop quickly enough to avoid an obstacle, should it turn off the road? How would a human driver make these decisions? How should we program autonomous cars to make them? What impacts could these decisions have on road safety and how we drive?
Teacher Tool Box
Make Career Connections
Discussing or reading about these careers can help students make important connections between the in-class lesson and STEM job opportunities in the real world.
Lesson Plan Variations
There are many ways you can extend these lessons to provide additional challenges to students. Some of them may require purchasing additional parts. Here are a few suggestions:
- Add LEDs to the cars to act as headlights, brake lights, turn signals, etc.
- Add a light sensor to the car to make the LED "headlights" turn on automatically in the dark.
- Use multiple ultrasonic sensors pointed in different directions to get a better sense of where an obstacle is relative to the vehicle. Or mount a single ultrasonic sensor on a servo motor so it can scan in multiple directions.
- Use additional infrared sensors to give better resolution for line detection.
- Have a race to see which car can navigate through a track the fastest.
- Use color sensors instead of (or in addition to) infrared sensors so the cars can detect different color lines.
- Advanced: add a Bluetooth module and a remote-control feature to control the car with a smartphone.




























