Infrared Distance Sensor Experiment

Introduction

This experiment demonstrates how to use an infrared distance sensor to measure the distance of objects using an Arduino.

Infrared Distance Sensor

Components Needed

Circuit Setup

  1. Connect the VCC and GND pins of the infrared sensor to the 5V and GND pins on the Arduino.
  2. Connect the output of the infrared sensor to an analog input pin (e.g., A0) on the Arduino.

The infrared sensor detects the distance to objects based on the reflection of infrared light.

Infrared Distance Circuit Setup

Code for Infrared Distance Measurement

Upload the following code to your Arduino to measure distance:


const int sensorPin = A0;
int distance;

void setup() {
  Serial.begin(9600);
}

void loop() {
  distance = analogRead(sensorPin);
  Serial.print("Distance: ");
  Serial.println(distance);
  delay(1000);
}
            

Explanation

The infrared sensor sends out infrared light and measures the amount of reflection that comes back, calculating the distance to the object based on this feedback.

Troubleshooting