What Sensors Are Best for Self-Driving Cars?
AbstractSelf-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.
Arduino® is a registered trademark of Arduino SA.
Ping)))™ is a registered trademark of Parallax, Inc.
Evaluate the performance of two different types of sensors for an autonomous vehicle.
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:
- Lidar (light detection and ranging) uses lasers to measure the distance to objects in the environment by measuring the amount of time it takes a laser pulse to bounce off an object and come back to the sensor.
- Radar (radio detection and ranging) is similar to Lidar but uses radio waves instead of light.
- Sonar or ultrasonic sensors emit bursts of sound and measure how long they take to reflect and travel back to the sensor. This is similar to how animals like bats use sound for echolocation.
- Cameras record video of the environment around the car and use image-processing algorithms to identify objects in the field of view.
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.
Figure 1. An ultrasonic distance sensor (left) and an infrared distance sensor (right).
Terms and Concepts
- Self-driving car
- Driverless car
- Autonomous vehicle
Look at the datasheets for both sensors linked in the bibliography and answer the following questions.
- What is each sensor's range?
- What are each sensor's power requirements (supply voltage and current)?
- What is each sensor's communication or output type?
- What external factors can affect the performance of each sensor or cause inaccurate readings?
Read the articles about self-driving cars linked in the bibliography and answer the following questions.
- What types of sensors do real-world self-driving cars use?
- What are the advantages and disadvantages of each type of sensor?
- Sharp Corporation (Dec. 1, 2006). GP2Y0A21YK0F Distance Measuring Sensor Unit. Jameco Electronics. Retrieved January 18, 2022.
- Parallax Inc. (Feb. 4, 2013). PING))) Ultrasonic Distance Sensor (#28015). Jameco Electronics. Retrieved January 18, 2022.
- Udacity Team (Mar. 3, 2021). How Self-driving Cars Work: Sensor Systems. Udacity. Retrieved January 18, 2022.
- Burke, K. (Apr. 15, 2019). How Does a Self-Driving Car See?. NVIDIA. Retrieved January 18, 2022.
- Eglowstein, H. (n.d.). How to Use an Arduino. Science Buddies. Retrieved January 18, 2022.
Materials and Equipment
- Computer with USB port and the Arduino IDE installed
- Arduino UNO
- USB A to B cable
- PING))) ultrasonic distance sensor
- Male to female jumper wires
- Sharp IR distance sensor
- 3-pin JST cable with breadboard pins
- Tape measure or meterstick
- Small box or cup to prop the sensors up on
- Tape to hold the sensor in place
- Assorted objects to test with the sensors. Your objects should be a range of shapes, sizes, and textures. Here are a few examples:
- Paper (different colors)
- Hard materials like metal or plastic
- Soft or porous materials (cloth, fabric, clothing, sponges, foam, stuffed animals, etc.)
- Irregularly-shaped objects (e.g. toys)
- Small or narrow objects (pencil, paperclip, pushpin, etc.)
- Lab notebook
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 firstname.lastname@example.org.
- If you have never used an Arduino before, see the How to Use an Arduino reference in the Bibliography.
- 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.
|Actual distance |
(measured with tape measure, cm)
(measured with Arduino, cm)
- 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.
Figure 2. Example experimental setup.
- To use the ultrasonic sensor:
- Connect the sensor to your Arduino using the male-female jumper wires. Connect the GND pin to GND, 5V pin to 5V, and the SIG pin to Arduino pin 7.
- To run code for the ultrasonic sensor, open the Arduino IDE and select File→Examples→06.Sensors→Ping.
- 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.
- 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.
- To use the infrared sensor:
- 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.
- Example code for the infrared sensor is available on Github. Download the code and save it locally on your computer.
- Download the code to your Arduino and open the serial monitor. The monitor will show the distance measured by the sensor in centimeters.
- 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.
- Analyze your data.
- Calculate an error for each reading by subtracting the actual measurement (with the tape measure) from the electronic measurement.
- Calculate an average error for each distance you tested.
- 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?
- Compare results between the sensors at different distances for the same objects. Is one sensor better at accurately detecting objects at a certain range?
- 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?
Ask an Expert
- 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).
If you like this project, you might enjoy exploring these related careers:
- Science Fair Project Guide
- Other Ideas Like This
- Robotics Project Ideas
- Self-Driving Cars Project Ideas
- My Favorites