Jump to main content

What Sensors Are Best for Self-Driving Cars?

Abstract

Self-driving cars use a variety of sensors to evaluate and navigate their environment. Each type of sensor has advantages and disadvantages. In this project you will evaluate two common types of distance sensor (ultrasonic and infrared) and compare their performance in different scenarios.

Summary

Areas of Science
Difficulty
 
Time Required
Short (2-5 days)
Prerequisites
Previous experience with an Arduino is recommended.
Material Availability
A kit is available from our partner Home Science Tools. See the Materials section for details.
Cost
Average ($50 - $100)
Safety
No issues
Credits
Ben Finio, PhD, Science Buddies
Valuable input provided by Analog Devices employees.

Arduino® is a registered trademark of Arduino SA.
Ping)))™ is a registered trademark of Parallax, Inc.

Ultrasonic and infrared distance sensors

Objective

Evaluate the performance of two different types of sensors for an autonomous vehicle.

Introduction

Self-driving cars, also called driverless cars or autonomous vehicles, are cars that can drive without input from a human driver. They therefore cannot rely on human senses like sight and sound to steer—they must use electronic sensors instead. Electronic sensors detect things like lane lines, traffic lights, road signs, pedestrians, and other cars and obstacles in the road. Examples of electronic sensors used by driverless cars include:

Different sensors might work better under different conditions. For example, some might not work as well at night or in the rain. Some might not do a good job detecting small objects. Some might detect some surfaces or materials better than others. Engineers have to evaluate the pros and cons of different sensors when deciding which ones to use for a self-driving car.

In this project you will compare two types of distance sensors that are commonly used with robotics projects involving an Arduino®: an ultrasonic sensor and an infrared sensor (Figure 1). The ultrasonic sensor sends out a burst of ultrasonic sound and measures how long it takes this sound to bounce back to the sensor. You can then calculate the distance to the target object using the speed of sound. The infrared sensor emits infrared light and measures the amount of reflected light, which decreases as the target object gets farther away. You can find the corresponding distance using a graph in the sensor's datasheet.

If you wanted to build your own autonomous car using an Arduino, this project will help you evaluate which sensor(s) you might want to use.

Ultrasonic and infrared distance sensors Image Credit: Ben Finio, Science Buddies / Science Buddies
Figure 1. An ultrasonic distance sensor (left) and an infrared distance sensor (right).

Terms and Concepts

Questions

Look at the datasheets for both sensors linked in the bibliography and answer the following questions.

Read the articles about self-driving cars linked in the bibliography and answer the following questions.

Bibliography

Materials and Equipment Buy Kit

Recommended Project Supplies

Get the right supplies — selected and tested to work with this project.

View Kit

Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at scibuddy@sciencebuddies.org.

Experimental Procedure

Note: If you have never used an Arduino before, please see our How to Use an Arduino page and go through at least the first three tutorials before you attempt the procedure for this project.
  1. Prepare two data tables like Table 1, one for the ultrasonic sensor and one for the infrared sensor. Plan out what objects you will test and how many trials you will conduct. Test each object at a few different distances from the sensor. Check that the distances you plan to test are within the sensor's operating range according to its datasheet. Make sure you measure the same objects/distances with each sensor.
Sensor:
Object Object description
(size/shape/texture etc.)
Actual distance
(measured with tape measure, cm)
Sensor distance
(measured with Arduino, cm)
Error
(cm)
     
     
     
Table 1. Example data table. Make one table for each sensor.
  1. Set up your experiment as shown in Figure 2. Tape the ultrasonic sensor to the top of a cup or other small object to prop it up off the floor or table. This will prevent interference from sound waves reflecting off the table. Aim the sensor along a tape measure so you can use it to measure the distance between the sensor and the target object. Make sure you measure the distance to the part of the object directly in front of the sensor, which is not necessarily the closest part. In Figure 2, that would be the rabbit's stomach, not its feet.

    An Arduino connected to an ultrasonic sensor that is mounted on a cup, with a tape measure showing the distanced to a stuffed bunny rabbit Image Credit: Ben Finio, Science Buddies / Science Buddies
    Figure 2. Example experimental setup.
  2. To use the ultrasonic sensor:
    1. Connect the sensor to your Arduino using the male-female jumper wires. Connect the GND pin to GND, 5V pin to 5V, the Echo pin to Arduino pin 7, and the Trig pin to Arduino pin 8.
    2. To open code for the ultrasonic sensor, open the Arduino IDE and select File→Examples→06.Sensors→Ping.
    3. The example code is for the PING ultrasonic distance sensor, which uses a single pin (alternating between output and input) for the trigger and echo signals. If you purchased the Science Buddies kit and have an HC-SR04 ultrasonic sensor, you need to modify the code as shown in the following video.
    4. Upload the code to your Arduino and open the serial monitor (Tools→Serial Monitor). The monitor will show the distance measured by the sensor in both inches and centimeters.
  3. Collect data for different objects using your ultrasonic sensor and fill out your data table. To take a reading, place an object in front of the sensor. Measure the actual distance between the sensor and the front of the object using the tape measure. Get the electronic sensor reading from the serial monitor. You should do multiple trials for each distance.
  4. To use the infrared sensor:
    1. Connect the sensor to your Arduino using the JST connector. Connect the red wire to 5V, the black wire to GND, and the white wire to pin A5.
    2. Example code for the infrared sensor is available on Github. Download the code and save it locally on your computer.
    3. Download the code to your Arduino and open the serial monitor. The monitor will show the distance measured by the sensor in centimeters.
  5. Collect data for different objects using your infrared sensor and fill out your data table. Use the same process that you used for the ultrasonic sensor.
  6. Analyze your data.
    1. Calculate an error for each reading by subtracting the actual measurement (with the tape measure) from the electronic measurement.
    2. Calculate an average error for each distance you tested.
    3. Compare the errors for the two sensors when measuring different objects. Does one sensor work better for certain types of objects? What causes a sensor to give an inaccurate reading? Can you explain your observations based on your understanding of how the sensors work?
    4. Compare results between the sensors at different distances for the same objects. Is one sensor better at accurately detecting objects at a certain range?
    5. If you were building your own autonomous vehicle using an Arduino (for example, something that would drive around the floor of your house), which sensor would you choose and why? Is cost a factor in your decision (check the links in the materials section for the price of each sensor)? What other factors might influence your decision?
icon scientific method

Ask an Expert

Do you have specific questions about your science project? Our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.

Global Connections

The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.

This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.

Variations

  • The materials list for this project suggests two common types of sensors, but there are many others you can test. The HC-SR04 is a much cheaper alternative to the PING))) ultrasonic sensor. Arduino-compatible Lidar sensors are available, although they are generally quite expensive.
  • Can you test your sensors under a range of simulated weather conditions? For example, test in direct sunlight, in the dark, or simulate rain, snow, or fog (be careful about getting your sensors wet—for example, you could simulate snow by dropping confetti).

Careers

If you like this project, you might enjoy exploring these related careers:

Career Profile
Have you watched "The Transformers" cartoon series or seen the "Transformers" movies? Both shows are about how good and evil robots fight each other and the humans who get in the middle. Many TV shows and movies show robots and humans interacting with each other. While this is, at present, fantasy, in real life robots play a helpful role. Robots do jobs that can be dangerous for humans. For example, some robots defuse landmines in war-stricken countries; others work in harsh environments like… Read more
Career Profile
Cars are an important part of our daily lives. We depend on them to perform everyday tasks—getting to and from school and work, sports practice, grocery shopping, and various errands—and also to keep us safe while doing so. Our cars can keep us cool or warm while we drive them, and they even help us find our way. The automobile is made up of complicated braking, steering, and electrical systems, in addition to the engine and drive train. All of these systems require a tremendous… Read more
Career Profile
Just as a potter forms clay, or a steel worker molds molten steel, electrical and electronics engineers gather and shape electricity and use it to make products that transmit power or transmit information. Electrical and electronics engineers may specialize in one of the millions of products that make or use electricity, like cell phones, electric motors, microwaves, medical instruments, airline navigation system, or handheld games. Read more

Contact Us

If you have purchased a kit for this project from Science Buddies, we are pleased to answer your questions.

In your email, please follow these instructions:
  1. What is your Science Buddies kit order number?
  2. Please describe how you need help as thoroughly as possible:

    Examples

    Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
    Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
    Bad Question I don't understand the instructions. Help!
    Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
    Bad Question Can I use a different part?

Contact Us

News Feed on This Topic

 
, ,

Cite This Page

General citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.

MLA Style

Finio, Ben. "What Sensors Are Best for Self-Driving Cars?" Science Buddies, 6 Dec. 2023, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p043/robotics/autonomous-car-sensors?from=Blog. Accessed 24 Apr. 2024.

APA Style

Finio, B. (2023, December 6). What Sensors Are Best for Self-Driving Cars? Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p043/robotics/autonomous-car-sensors?from=Blog


Last edit date: 2023-12-06
Top
Free science fair projects.