Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use Distance Sensor: Examples, Pinouts, and Specs

Image of Distance Sensor
Cirkit Designer LogoDesign with Distance Sensor in Cirkit Designer

Introduction

A distance sensor is an electronic device designed to measure the distance between itself and an object. It utilizes various technologies such as ultrasonic waves, infrared light, or laser beams to determine the distance and outputs a signal proportional to the measured value. Distance sensors are widely used in robotics, automation, obstacle detection, and industrial applications where precise distance measurement is critical.

Explore Projects Built with Distance Sensor

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module
Image of Home security system: A project utilizing Distance Sensor in a practical application
This circuit features an Arduino UNO connected to an HC-SR04 ultrasonic sensor for distance measurement and a SIM800L GSM module for communication. The Arduino controls an LED, which lights up based on the distance detected by the ultrasonic sensor. When a certain distance threshold is exceeded, the Arduino uses the SIM800L module to make a phone call, indicating motion detection. A 48V to 5V converter supplies power to the SIM800L and the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Battery-Powered Robotic System with Ultrasonic Sensors and Magnetometer
Image of Autonomous Mobile robot v1: A project utilizing Distance Sensor in a practical application
This circuit is a sensor-based robotic system controlled by an Arduino UNO. It includes three HC-SR04 ultrasonic sensors for distance measurement, a QMC5883L magnetometer for orientation detection, and an L298N motor driver to control two DC motors, all powered by a Li-ion 18650 battery.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Controlled Dual TF LUNA LIDAR Distance Measurement System
Image of LIDAR_UNO: A project utilizing Distance Sensor in a practical application
This circuit is designed to measure distances using two TF LUNA LIDAR sensors, which are interfaced with an Arduino UNO microcontroller via I2C communication. The Arduino is programmed to read distance measurements from the LIDAR sensors and output the data serially. The entire system is powered by a 5V battery, ensuring portability and ease of use.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Ultrasonic Distance Sensor with OLED Display and SIM900A Communication
Image of SENSOR: A project utilizing Distance Sensor in a practical application
This circuit is a distance measurement and communication system using an Arduino UNO, an ultrasonic sensor, an OLED display, and a SIM900A module. The ultrasonic sensor measures the distance to an object, which is then displayed on the OLED screen and transmitted via the SIM900A module. The system is powered by a 18650 Li-ion battery.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Distance Sensor

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Home security system: A project utilizing Distance Sensor in a practical application
Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module
This circuit features an Arduino UNO connected to an HC-SR04 ultrasonic sensor for distance measurement and a SIM800L GSM module for communication. The Arduino controls an LED, which lights up based on the distance detected by the ultrasonic sensor. When a certain distance threshold is exceeded, the Arduino uses the SIM800L module to make a phone call, indicating motion detection. A 48V to 5V converter supplies power to the SIM800L and the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Autonomous Mobile robot v1: A project utilizing Distance Sensor in a practical application
Arduino UNO-Based Battery-Powered Robotic System with Ultrasonic Sensors and Magnetometer
This circuit is a sensor-based robotic system controlled by an Arduino UNO. It includes three HC-SR04 ultrasonic sensors for distance measurement, a QMC5883L magnetometer for orientation detection, and an L298N motor driver to control two DC motors, all powered by a Li-ion 18650 battery.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of LIDAR_UNO: A project utilizing Distance Sensor in a practical application
Arduino UNO Controlled Dual TF LUNA LIDAR Distance Measurement System
This circuit is designed to measure distances using two TF LUNA LIDAR sensors, which are interfaced with an Arduino UNO microcontroller via I2C communication. The Arduino is programmed to read distance measurements from the LIDAR sensors and output the data serially. The entire system is powered by a 5V battery, ensuring portability and ease of use.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of SENSOR: A project utilizing Distance Sensor in a practical application
Arduino UNO-Based Ultrasonic Distance Sensor with OLED Display and SIM900A Communication
This circuit is a distance measurement and communication system using an Arduino UNO, an ultrasonic sensor, an OLED display, and a SIM900A module. The ultrasonic sensor measures the distance to an object, which is then displayed on the OLED screen and transmitted via the SIM900A module. The system is powered by a 18650 Li-ion battery.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications

  • Obstacle detection in robotics
  • Automated parking systems
  • Industrial automation and conveyor systems
  • Proximity sensing in smart devices
  • Distance measurement in drones and autonomous vehicles

Technical Specifications

The technical specifications of a distance sensor can vary depending on the type and model. Below is an example specification for an ultrasonic distance sensor (e.g., HC-SR04):

General Specifications

Parameter Value
Operating Voltage 5V DC
Operating Current 15 mA
Measuring Range 2 cm to 400 cm
Accuracy ±3 mm
Operating Frequency 40 kHz
Output Signal Pulse width (proportional to distance)
Operating Temperature -15°C to 70°C

Pin Configuration

Pin Name Pin Number Description
VCC 1 Power supply pin (5V DC)
Trig 2 Trigger pin: Sends an ultrasonic pulse
Echo 3 Echo pin: Receives the reflected pulse
GND 4 Ground pin

Usage Instructions

How to Use the Component in a Circuit

  1. Power the Sensor: Connect the VCC pin to a 5V power source and the GND pin to ground.
  2. Trigger the Sensor: Send a 10 µs HIGH pulse to the Trig pin to initiate a measurement.
  3. Receive the Echo: Measure the duration of the HIGH signal on the Echo pin. This duration corresponds to the time taken for the ultrasonic pulse to travel to the object and back.
  4. Calculate Distance: Use the formula below to calculate the distance: [ \text{Distance (cm)} = \frac{\text{Time (µs)} \times 0.034}{2} ] The factor 0.034 represents the speed of sound in cm/µs, and the division by 2 accounts for the round trip of the pulse.

Example Circuit

Connect the distance sensor to an Arduino UNO as follows:

  • VCC to 5V
  • GND to GND
  • Trig to digital pin 9
  • Echo to digital pin 10

Example Arduino Code

// Define pins for the distance sensor
const int trigPin = 9;  // Trigger pin connected to digital pin 9
const int echoPin = 10; // Echo pin connected to digital pin 10

void setup() {
  pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
  pinMode(echoPin, INPUT);  // Set the echo pin as an input
  Serial.begin(9600);       // Initialize serial communication at 9600 baud
}

void loop() {
  // Send a 10 µs HIGH pulse to the trigger pin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the duration of the HIGH signal on the echo pin
  long duration = pulseIn(echoPin, HIGH);

  // Calculate the distance in cm
  float distance = (duration * 0.034) / 2;

  // Print the distance to the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  delay(500); // Wait for 500 ms before the next measurement
}

Important Considerations and Best Practices

  • Ensure the sensor is mounted securely and aligned properly for accurate measurements.
  • Avoid using the sensor in environments with high humidity or extreme temperatures outside its operating range.
  • Minimize interference from other ultrasonic devices operating at the same frequency.
  • Use a capacitor across the VCC and GND pins to reduce noise and stabilize the power supply.

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Output Signal:

    • Verify the wiring connections and ensure the sensor is powered correctly.
    • Check the trigger signal from the microcontroller.
  2. Inaccurate Measurements:

    • Ensure there are no obstructions or reflective surfaces near the sensor.
    • Verify the calculation formula and ensure the correct speed of sound is used.
  3. Interference from Other Devices:

    • Use shielding or increase the distance between sensors operating at the same frequency.

FAQs

Q: Can the sensor detect transparent objects?
A: Ultrasonic sensors may struggle to detect transparent objects like glass. Infrared or laser-based sensors are better suited for such applications.

Q: What is the maximum range of the sensor?
A: The maximum range depends on the sensor model. For the HC-SR04, it is 400 cm.

Q: Can I use this sensor with a 3.3V microcontroller?
A: The HC-SR04 requires a 5V power supply. Use a level shifter for compatibility with 3.3V systems.