Human Following Robot Using Arduino and Ultrasonic Sensor

Submitted by Gourav Tak on

Working of Human Following Robot Using Arduino

In recent years, robotics has witnessed significant advancements, enabling the creation of intelligent machines that can interact with the environment. One exciting application of robotics is the development of human-following robots. These robots can track and follow a person autonomously, making them useful in various scenarios like assistance in crowded areas, navigation support, or even as companions. In this article, we will explore in detail how to build a human following robot using Arduino and three ultrasonic sensors, complete with circuit diagrams and working code. Also, check all the Arduino-based Robotics projects by following the link.

The working of a human following robot using Arduino code and three ultrasonic sensors is an interesting project. What makes this project particularly interesting is the use of not just one, but three ultrasonic sensors. This adds a new dimension to the experience, as we typically see humans following a robot built with one ultrasonic, two IR, and one servo motor.  This servo motor has no role in the operation and also adds unnecessary complications. So I removed this servo and the IR sensors and used 3 ultrasonic sensors. With ultrasonic sensors, you can measure distance and use that information to navigate and follow a human target. Here’s a general outline of the steps involved in creating such a robot.

 

 

Components Needed for Human Following Robot Using Arduino

  • Arduino UNO board ×1

  • Ultrasonic sensor ×3

  • L298N motor driver ×1

  • Robot chassis

  • BO motors ×2

  • Wheels ×2

  • Li-ion battery 3.7V ×2

  • Battery holder ×1

  • Breadboard

  • Ultrasonic sensor holder ×3

  • Switch and jumper wires

Human Following Robot Using Arduino Circuit Diagram

Here is the schematic diagram of a Human-following robot circuit.

Arduino Human Following Robot Circuit Diagram

This design incorporates three ultrasonic sensors, allowing distance measurements in three directions front, right, and left. These sensors are connected to the Arduino board through their respective digital pins. Additionally, the circuit includes two DC motors for movement, which are connected to an L298N motor driver module. The motor driver module is, in turn, connected to the Arduino board using its corresponding digital pins. To power the entire setup, two 3.7V li-ion cells are employed, which are connected to the motor driver module via a switch.

Overall, this circuit diagram showcases the essential components and connections necessary for the Human-following robot to operate effectively.

arduino human following robot circuit

Circuit Connection:

Arduino and HC-SR04 Ultrasonic Sensor Module:

HC-SR04 Ultrasonic sensor Module

  • Connect the VCC pin of each ultrasonic sensor to the 5V pin on the Arduino board.

  • Connect the GND pin of each ultrasonic sensor to the GND pin on the Arduino board.

  • Connect the trigger pin (TRIG) of each ultrasonic sensor to separate digital pins (2,4, and 6) on the Arduino board.

  • Connect the echo pin (ECHO) of each ultrasonic to separate digital pins (3,5, and 7) on the Arduino board.

Arduino and Motor Driver Module:

  • Connect the digital output pins of the Arduino (digital pins 8, 9, 10, and 11) to the appropriate input pins (IN1, IN2, IN3, and IN4) on the motor driver module.

  • Connect the ENA and ENB pins of the motor driver module to the onboard High state pin with the help of a female header.

  • Connect the OUT1, OUT2, OUT3, and OUT4 pins of the motor driver module to the appropriate terminals of the motors.

  • Connect the VCC (+5V) and GND pins of the motor driver module to the appropriate power (Vin) and ground (GND) connections on the Arduino.

Power Supply:

  • Connect the positive terminal of the power supply to the +12V input of the motor driver module.

  • Connect the negative terminal of the power supply to the GND pin of the motor driver module.

  • Connect the GND pin of the Arduino to the GND pin of the motor driver module.

Human Following Robot Using Arduino Code

Here is a simple 3 Ultrasonic sensor-based Human following robot using Arduino Uno code that you can use for your project.

Ultrsonic Sensors on Robot

This code reads the distances from three ultrasonic sensors (‘frontDistance’, ‘leftDistance’, and ‘rightDistance’). It then compares these distances to determine the sensor with the smallest distance. If the smallest distance is below the threshold, it moves the car accordingly using the appropriate motor control function (‘moveForward()’, ‘turnLeft()’, ‘turnRight()’). If none of the distances are below the threshold, it stops the motor using ‘stop()’.

In this section, we define the pin connections for the ultrasonic sensors and motor control. The S1Trig, S2Trig, and S3Trig, variables represent the trigger pins of the three ultrasonic sensors, while S1Echo, S2Echo, and S3Echo, represent their respective echo pins.

The LEFT_MOTOR_PIN1, LEFT_MOTOR_PIN2, RIGHT_MOTOR_PIN1, and RIGHT_MOTOR_PIN2 variables define the pins for controlling the motors.

The MAX_DISTANCE and MIN_DISTANCE_BACK variables set the thresholds for obstacle detection.

// Ultrasonic sensor pins
#define S1Trig 2
#define S2Trig 4
#define S3Trig 6
#define S1Echo 3
#define S2Echo 5
#define S3Echo 7
// Motor control pins
#define LEFT_MOTOR_PIN1 8
#define LEFT_MOTOR_PIN2 9
#define RIGHT_MOTOR_PIN1 10
#define RIGHT_MOTOR_PIN2 11
// Distance thresholds for obstacle detection
#define MAX_DISTANCE 40
#define MIN_DISTANCE_BACK 5

Make sure to adjust the values of ‘MIN_DISTANCE_BACK’ and ‘MAX_DISTANCE’ according to your specific requirements and the characteristics of your robot.

The suitable values for ‘MIN_DISTANCE_BACK’ and ‘MAX_DISTANCE’ depend on the specific requirements and characteristics of your human-following robot. You will need to consider factors such as the speed of your robot, the response time of the sensors, and the desired safety margin

Here are some general guidelines to help you choose suitable values.

MIN_DISTANCE_BACK’ This value represents the distance at which the car should come to a stop when an obstacle or hand is detected directly in front. It should be set to a distance that allows the car to back safely without colliding with the obstacle or hand. A typical value could be around 5-10 cm.

MAX_DISTANCE’ This value represents the maximum distance at which the car considers the path ahead to be clear and can continue moving forward. It should be set to a distance that provides enough room for the car to move without colliding with any obstacles or hands. If your hand and obstacles are going out of this range, the robot should be stop. A typical value could be around 30-50 cm.

These values are just suggestions, and you may need to adjust them based on the specific characteristics of your robot and the environment in which it operates.

These lines set the motor speed limits. ‘MAX_SPEED’ denotes the upper limit for motor speed, while ‘MIN_SPEED’ is a lower value used for a slight left bias. The speed values are typically within the range of 0 to 255, and can be adjusted to suit our specific requirements.

// Maximum and minimum motor speeds
#define MAX_SPEED 150
#define MIN_SPEED 75

The ‘setup()’ function is called once at the start of the program. In the setup() function, we set the motor control pins (LEFT_MOTOR_PIN1, LEFT_MOTOR_PIN2, RIGHT_MOTOR_PIN1, RIGHT_MOTOR_PIN2) as output pins using ‘pinMode()’ . We also set the trigger pins (S1Trig, S2Trig, S3Trig) of the ultrasonic sensors as output pins and the echo pins (S1Echo, S2Echo, S3Echo) as input pins. Lastly, we initialize the serial communication at a baud rate of 9600 for debugging purposes.

void setup() {
  // Set motor control pins as outputs
  pinMode(LEFT_MOTOR_PIN1, OUTPUT);
  pinMode(LEFT_MOTOR_PIN2, OUTPUT);
  pinMode(RIGHT_MOTOR_PIN1, OUTPUT);
  pinMode(RIGHT_MOTOR_PIN2, OUTPUT);
  //Set the Trig pins as output pins
  pinMode(S1Trig, OUTPUT);
  pinMode(S2Trig, OUTPUT);
  pinMode(S3Trig, OUTPUT);
  //Set the Echo pins as input pins
  pinMode(S1Echo, INPUT);
  pinMode(S2Echo, INPUT);
  pinMode(S3Echo, INPUT);
  // Initialize the serial communication for debugging
  Serial.begin(9600);
}

This block of code consists of three functions (‘sensorOne()’, ‘sensorTwo()’, ‘sensorThree()’) responsible for measuring the distance using ultrasonic sensors.

The ‘sensorOne()’ function measures the distance using the first ultrasonic sensor. It's important to note that the conversion of the pulse duration to distance is based on the assumption that the speed of sound is approximately 343 meters per second. Dividing by 29 and halving the result provides an approximate conversion from microseconds to centimeters.

The ‘sensorTwo()’ and ‘sensorThree()’ functions work similarly, but for the second and third ultrasonic sensors, respectively.

// Function to measure the distance using an ultrasonic sensor
int sensorOne() {
  //pulse output
  digitalWrite(S1Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(S1Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(S1Trig, LOW);
  long t = pulseIn(S1Echo, HIGH);//Get the pulse
  int cm = t / 29 / 2; //Convert time to the distance
  return cm; // Return the values from the sensor
}
//Get the sensor values
int sensorTwo() {
  //pulse output
  digitalWrite(S2Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(S2Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(S2Trig, LOW);
  long t = pulseIn(S2Echo, HIGH);//Get the pulse
  int cm = t / 29 / 2; //Convert time to the distance
  return cm; // Return the values from the sensor
}
//Get the sensor values
int sensorThree() {
  //pulse output
  digitalWrite(S3Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(S3Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(S3Trig, LOW);
  long t = pulseIn(S3Echo, HIGH);//Get the pulse
  int cm = t / 29 / 2; //Convert time to the distance
  return cm; // Return the values from the sensor
}

In this section, the ‘loop()’ function begins by calling the ‘sensorOne()’, ‘sensorTwo()’, and ‘sensorThree()’ functions to measure the distances from the ultrasonic sensors. The distances are then stored in the variables ‘frontDistance’, ‘leftDistance’, and ‘rightDistance’.

Next, the code utilizes the ‘Serial’ object to print the distance values to the serial monitor for debugging and monitoring purposes.

void loop() {
  int frontDistance = sensorOne();
  int leftDistance = sensorTwo();
  int rightDistance = sensorThree();
  Serial.print("Front: ");
  Serial.print(frontDistance);
  Serial.print(" cm, Left: ");
  Serial.print(leftDistance);
  Serial.print(" cm, Right: ");
  Serial.print(rightDistance);
  Serial.println(" cm");

In this section of code condition checks if the front distance is less than a threshold value ‘MIN_DISTANCE_BACK’ that indicates a very low distance. If this condition is true, it means that the front distance is very low, and the robot should move backward to avoid a collision. In this case, the ‘moveBackward()’ function is called.

if (frontDistance < MIN_DISTANCE_BACK) {
    moveBackward();
    Serial.println("backward");

If the previous condition is false, this condition is checked. if the front distance is less than the left distance, less than the right distance, and less than the ‘MAX_DISTANCE’ threshold. If this condition is true, it means that the front distance is the smallest among the three distances, and it is also below the maximum distance threshold. In this case, the ‘moveForward()’ function is called to make the car move forward.

else if (frontDistance < leftDistance && frontDistance < rightDistance && frontDistance < MAX_DISTANCE) {
    moveForward();
    Serial.println("forward");

If the previous condition is false, this condition is checked. It verifies if the left distance is less than the right distance and less than the ‘MAX_DISTANCE’ threshold. This condition indicates that the left distance is the smallest among the three distances, and it is also below the minimum distance threshold. Therefore, the ‘turnLeft()’ function is called to make the car turn left.

else if (leftDistance < rightDistance && leftDistance < MAX_DISTANCE) {
    turnLeft();
    Serial.println("left");

If neither of the previous conditions is met, this condition is checked. It ensures that the right distance is less than the ‘MAX_DISTANCE’ threshold. This condition suggests that the right distance is the smallest among the three distances, and it is below the minimum distance threshold. The ‘turnRight()’ function is called to make the car turn right.

else if (rightDistance < MAX_DISTANCE) {
    turnRight();
    Serial.println("right");

If none of the previous conditions are true, it means that none of the distances satisfy the conditions for movement. Therefore, the ‘stop()’ function is called to stop the car.

 else {
    stop();
    Serial.println("stop");

In summary, the code checks the distances from the three ultrasonic sensors and determines the direction in which the car should move based on the 3 ultrasonic sensors with the smallest distance.

 

Important aspects of this Arduino-powered human-following robot project include:

  • Three-sensor setup for 360-degree human identification
  • Distance measurement and decision-making in real-time
  • Navigation that operates automatically without human assistance
  • Avoiding collisions and maintaining a safe following distance

 

 

Technical Summary and GitHub Repository 

Using three HC-SR04 ultrasonic sensors and an L298N motor driver for precise directional control, this Arduino project shows off the robot's ability to track itself. For simple replication and modification, the full source code, circuit schematics, and assembly guidelines are accessible in our GitHub repository. To download the Arduino code, view comprehensive wiring schematics, and participate in the open-source robotics community, visit our GitHub page.

Code Schematics Download Icon

 

Frequently Asked Questions

⇥ How does an Arduino-powered human-following robot operate?
Three ultrasonic sensors are used by the Arduino-powered human following robot to determine a person's distance and presence. After processing this data, the Arduino manages motors to follow the identified individual while keeping a safe distance.

⇥ Which motor driver is ideal for an Arduino human-following robot?
The most widely used motor driver for Arduino human-following robots is the L298N. Additionally, some builders use the L293D motor driver shield, which connects to the Arduino Uno directly. Both can supply enough current for small robot applications and manage 2-4 DC motors.

⇥ Is it possible to create a human-following robot without soldering?
Yes, you can use motor driver shields that connect straight to an Arduino, breadboards, and jumper wires to construct a human-following robot. For novices and prototyping, this method is ideal.

⇥ What uses do human-following robots have in the real world?
Shopping cart robots in malls, luggage-carrying robots in airports, security patrol robots, elderly care assistance robots, educational demonstration robots, and companion robots that behave like pets are a few examples of applications.

 

Conclusion

This human following robot using Arduino project and three ultrasonic sensors is an exciting and rewarding project that combines programming, electronics, and mechanics. With Arduino’s versatility and the availability of affordable components, creating your own human-following robot is within reach.

Human-following robots have a wide range of applications in various fields, such as retail stores, malls, and hotels, to provide personalized assistance to customers. Human-following robots can be employed in security and surveillance systems to track and monitor individuals in public spaces. They can be used in Entertainment and events, elderly care, guided tours, research and development, education and research, and personal robotics.

They are just a few examples of the applications of human-following robots. As technology advances and robotics continues to evolve, we can expect even more diverse and innovative applications in the future.

Explore Practical Projects Similar To Robots Using Arduino

Explore a range of hands-on robotics projects powered by Arduino, from line-following bots to obstacle-avoiding vehicles. These practical builds help you understand sensor integration, motor control, and real-world automation techniques. Ideal for beginners and hobbyists, these projects bring theory to life through interactive learning.

 Simple Light Following Robot using Arduino UNO

Simple Light Following Robot using Arduino UNO

Today, we are building a simple Arduino-based project: a light-following robot. This project is perfect for beginners, and we'll use LDR sensor modules to detect light and an MX1508 motor driver module for control. By building this simple light following robot you will learn the basics of robotics and how to use a microcontroller like Arduino to read sensor data and control motors.

Line Follower Robot using Arduino UNO: How to Build (Step-by-Step Guide)

Line Follower Robot using Arduino UNO: How to Build (Step-by-Step Guide)

This step-by-step guide will show you how to build a professional-grade line follower robot using Arduino UNO, with complete code explanations and troubleshooting tips. Perfect for beginners and intermediate makers alike, this project combines hardware interfacing, sensor calibration, and motor control fundamentals.

Have any question related to this Article?

How to Use Height Hold Mode in LiteWing ESP32 Drone?

Flying a drone manually requires constant attention to throttle control. One moment of distraction and your drone either crashes into the ground or flies away into the ceiling. If you're building your LiteWing from scratch, check out our detailed step-by-step LiteWing assembly guide to get started with your build.  This is where Drone height hold mode becomes a game-changer for drone pilots of all skill levels. Height hold drone automatically maintains your drone at a specific height, letting you focus on horizontal movement while the flight controller handles the vertical stability.

LiteWing drone demonstrating height hold mode with automatic altitude control and hovering stability

The LiteWing drone, an open-source ESP32-powered drone that evolved from our popular DIY WiFi-controlled drone project, makes implementing altitude hold mode drone surprisingly straightforward. Unlike expensive commercial drones that come with this feature built in, height hold mode in LiteWing allows you to understand and build this functionality yourself. In this tutorial, we'll walk you through adding height hold capability to your LiteWing using the VL53L1X Time-of-Flight (ToF) sensor using both the cfclient software and our updated LiteWing mobile App. The LiteWing includes dedicated solder pads on the bottom side of the PCB frame to attach the off-the-shelf VL53L1X module directly.

LiteWing VL53L1X Solder pad GIF

This laser-ranging sensor provides millimetre-accurate distance measurements up to 4 meters, making it perfect for indoor flight applications and precise altitude control drone operations. The VL53L1X communicates over I2C and integrates seamlessly with LiteWing's existing flight control firmware. Once connected, the sensor continuously measures the distance to the ground, and the flight controller uses this data to adjust motor speeds and maintain your desired height automatically.

Comparison chart showing manual drone control vs automated height hold mode with altitude stabilisation

 

Manual Control vs Height Hold Mode

FeatureManual ControlHeight Hold Mode
Throttle ManagementConstant pilot input requiredAutomatic altitude maintenance
Skill Level RequiredIntermediate to advancedBeginner-friendly
StabilityDepends on pilot skillConsistent hovering height
Battery EfficiencyVariable (pilot-dependent)Optimized for longer flight time
Best Use CaseAcrobatic flying, racingAerial photography, surveying, learning

What is Height Hold Mode in Drones?

Height hold mode will convert your drone from being operated manually on your behalf to an autonomous height-holding platform. This mode uses multiple sensors along with advanced algorithms to hold a set height without input from the user, which is necessary for reliable operations.

The Significance of Height Hold:

  • Hands-free hover: Can maintain an altitude and gives the operator the ability to concentrate on video capture or avoiding obstacles.
  • Decreased workload: Relieves the pilot from frequent throttle control, particularly important for less experienced pilots.
  • More time in the air: Allows for optimal performance of the motors to gain more time in the air by not using unnecessary power to gain or lose height.
  • Increased safety: Prevents unintended loss of controlled altitude that could cause a crash or fly-away.
  • Better Aerial Photography: A stable platform allows for smoother video and pictures, and will produce higher quality.
  • Increased accuracy: A must for indoor pilots and for inspection work and confined spaces.

How Height Hold Mode Works

Height hold in drone mode transforms your drone from a manually controlled aircraft into an autonomous hovering platform. This advanced altitude control drone uses multiple sensors and sophisticated algorithms to maintain a constant height without pilot intervention.

Drone's height hold operates as a closed-loop feedback control system that continuously compares the drone's actual height with a predetermined target height. When you activate height hold mode, the flight controller captures the current height as the reference point and works to maintain this position regardless of external disturbances.

The height hold in drone systems consists of several interconnected components working in perfect harmony:

  • Sensor Array: Multiple height measurement devices provide redundant height data
  • Flight Controller: The central processing unit that interprets sensor data and makes control decisions
  • PID Controller: A mathematical algorithm that calculates precise motor adjustments
  • Motor Control System: Electronic speed controllers that modify rotor speeds based on flight controller commands
  • Feedback Loop: Continuous sensor readings create a responsive system that adapts to changing conditions
Flowchart diagram showing drone height hold control loop with sensor input, PID controller, and motor output for altitude maintenance

Types of Sensors Used for Altitude Control in Drones

Modern altitude hold mode drone systems employ various sensor technologies for height measurement, each with distinct advantages and limitations. Understanding these differences helps you choose the right sensor for your specific altitude control drone application.

Sensor TypeRangeAccuracyBest ForLimitations
Barometric PressureUnlimited altitude±1-3 metersOutdoor high-altitude flightWeather-dependent, measures altitude not ground distance
Ultrasonic0-8 meters±2-5 cmLow-cost indoor applicationsAffected by soft surfaces, wind interference
ToF Laser (VL53L1X)0-4 meters±1 mmPrecision indoor hoveringLimited range, bright sunlight interference
GPS + BarometerUnlimited±2-5 metersOutdoor navigation, waypointsNo indoor functionality, GPS dependency

Barometric Pressure Sensors for Height Hold

Barometric Pressure Sensors measure atmospheric pressure changes to determine altitude. These sensors work well for maintaining height over large areas, but can be affected by weather changes and air currents. They're particularly useful for outdoor flight at higher altitudes where pressure differences are more pronounced. 

Technically, this is altitude hold rather than height hold, since barometric sensors measure altitude above sea level (absolute altitude) rather than distance from the ground below (relative height). A drone using only barometric sensors will maintain the same pressure altitude even if flying over terrain that rises or falls, potentially resulting in varying distances from the ground. For this reason, barometric sensors are often combined with ground-relative sensors like ToF or ultrasonic for comprehensive altitude control drone systems.

LiteWing drone adjusting altitude in real-time using barometric pressure sensor for altitude hold mode

Ultrasonic Sensors for Height Hold

Ultrasonic Sensors emit sound waves and measure the time for echoes to return from the ground. While cost-effective and reliable at close range (typically under 8 meters), they can struggle with soft surfaces like grass or carpet that absorb sound waves. Wind can also deflect the sound waves, causing inaccurate readings and affecting drone height hold performance.

Ultrasonic sensor emitting sound waves for measuring ground distance in drone height hold system

Time-of-Flight (ToF) Laser Sensors for Precision Height Hold

Time-of-Flight (ToF) Laser Sensors use infrared laser pulses to measure distance with high precision. These sensors offer excellent accuracy across various surface types and lighting conditions, making them ideal for indoor flight and precise hovering applications. ToF sensors are the preferred choice for height hold mode in LiteWing and similar DIY drone projects.

ToF sensor calculating and displaying precise drone height measurement for altitude control

PID Controller: The Brain Behind Height Hold Mode

The heart of height hold in drone functionality lies in the PID controller algorithm, just as with other flight controller functionalities that utilise PID. This mathematical system doesn't just react to height errors—it predicts and prevents them. The PID controller continuously adjusts motor speeds dozens of times per second to maintain the desired height.

VL53L1X ToF Sensor for Implementing Drone Height Hold

The VL53L1X Time-of-Flight sensor represents cutting-edge technology specifically designed for precise distance measurement in drone measurement in drone height hold applications. This laser-ranging sensor provides the accuracy and reliability essential for effective altitude hold mode drone functionality. The VL53L1X operates using Class 1 laser safety standards, emitting infrared light at a 940nm wavelength.

VL53L1X Time-of-Flight sensor chip for precise altitude measurement in drone height hold systems

VL53L1X Technical Specifications for Height Hold

Measurement Range:4cm to 4 meters with high accuracy
Update Rate: Up to 50Hz for real-time altitude feedback
Accuracy: ±3% at 1 meter distance under optimal conditions
Field of View: Narrow 27° cone for precise ground targeting
Supply Voltage: 2.6V to 3.5V operation
Interface: I2C communication protocol
Current Consumption: 20mA active, 5μA standby

VL53L1x Sensor Working Principle
The VL53L1X uses Direct Time-of-Flight measurement, where the sensor emits short infrared laser pulses and measures the precise time required for light to travel to the target and return. Unlike indirect ToF methods that measure phase differences, direct ToF provides absolute distance measurements independent of surface reflectivity variations.

The sensor incorporates a Vertical Cavity Surface Emitting Laser (VCSEL) array and a Single Photon Avalanche Diode (SPAD) detector array. This combination enables the detection of individual photons, allowing measurements even from surfaces with low reflectivity. For optimal flight time with height hold enabled, selecting the right battery is essential, learn more in our comprehensive guide on how to choose the right battery for your LiteWing drone.

Limitations of VL53L1x ToF Sensor

While highly effective, the VL53L1X has operational limitations:

  • Bright Light Interference: Intense sunlight or bright artificial lighting can saturate the photon detector, reducing accuracy
  • Maximum Range: A 4-meter limit requires alternative sensors for higher altitude operations
  • Power Consumption: Active laser operation draws more current than passive sensors
  • Reflective Surfaces: Highly reflective surfaces may cause measurement errors due to specular reflection

VL53L1X Module

VL53L1x Module

For ease of use, we have used an off-the-shelf VL53L1x module with the LiteWing. We have connected it to the LiteWing drone using SMD male pin headers. Keep in mind that there are different modules with different boards and pin layouts in the market. So, choose the one that looks similar to the one shown in the above picture if you are planning to attach it to the bottom pads of the LiteWing.

VL53L1X Module Parts Marking

The image below shows the typical component arrangement in a VL53L1x module. As you can see, the module has a bare minimum of components. Apart from the VL53L1x sensor itself, the module has a 3.3V regulator along with level-shifting circuitry and some bypass capacitors. The inbuilt voltage regulator and the level-shifting circuit ensure that the module can be used with either 5V or 3.3V circuits.

Height Hold Sensor Parts Marking VL53L1x module

VL53L1X Module Pinout and Connections

Standard breakout modules feature the following pin configuration:

VL53L1x Module Pinout

 VIN  - Positive Voltage Input Pin.

 GND  - Ground Voltage Input Pin.

 SCL  - I2C Serial Clock Pin.

 SDA  - I2C Serial Data Pin.

 GPIO1  - Interrupt output.

 XSHU  - Shutdown Pin, Active Low.

The VIN pin is used to supply power to the module. It typically accepts a regulated input voltage such as 3.3V or 5V, depending on the board design. The GND pin serves as the electrical ground, providing a common reference point for the power supply and signal levels. Communication with the module is achieved via the I2C interface, which uses two pins: SCL for synchronising data transfer, and SDA for sending and receiving data between the sensor and the microcontroller. In addition to these, the module includes a GPIO1 pin, which can be configured as an interrupt output to notify the host system when new ranging data is available or when a specific condition is met. Lastly, the XSHUT pin functions as a hardware shutdown control. It is an active low input, meaning the module enters a low power state when this pin is pulled to ground, and resumes normal operation when driven high.

Installing VL53L1X Sensor for Height Hold Mode in LiteWing

In the LiteWing platform, the VL53L1X connects to the flight controller via the secondary I2C interface, since the primary I2C in LiteWing is used to connect with the IMU onboard. The sensor mounts on the drone's underside with the laser aperture facing downward. You can either use the dedicated pads on the bottom side of the LiteWing or the SDA1 and SCL1 pins available on the GPIO header to interface the VL53L1x sensor module with LiteWing, streamlining the drone height hold setup process.

.

VL53L1X ToF sensor properly mounted on LiteWing drone bottom for height hold altitude control

Flying LiteWing in Height Hold Mode

Now that we are familiar with how the drone height hold works, let's look at how to use it. Flying the LiteWing drone is pretty easy. For that, make sure to attach the VL531X sensor module securely to the LiteWing drone. Once done, all you have to do is first install the latest version of the LiteWing App from the Google Play Store or the Apple App Store. To know more details about configuring and using the LiteWing app, please check out our LiteWing app tutorial( hyperlink). Once the app is configured properly, open the app and connect to the drone. Once it's connected, click on the height hold button. Flying the LiteWing with height hold mode in LiteWing activated transforms your piloting experience, making stable hovering as simple as pressing a button.

LiteWing App with Height Hold Button

Now, when the set target height option is shown, set your desired height for the drone and click on the start button.

LiteWing App Target Height Settings

The drone will count down to three and take off on its own. Once the set height is reached, the LiteWing will automatically hold the height and hover at that. Now you can start flying the LiteWing drone by simply using the roll and pitch controls.

Using cfClient Software for Advanced Height Hold Control

To use the height hold in drone in cfClient, make sure to install and configure the cfClient following the instructions in the How to use Crazyflie cfClient with Litewing tutorial. One thing to keep in mind that to don’t forget to configure the assist control button in the input device configuration. You can also find detailed instructions to do that in the previously linked tutorial. Once everything is configured correctly, turn on the LiteWing drone with the ToF sensor installed and connect to its WiFi. Once the WiFi is connected, connect to the LiteWing using the connect button in the cfClient. Once connected, you can see that the height hold mode in the Assist mode menu is now active.

LiteWing mobile app interface showing height hold button for altitude hold mode activation

Now, to use the height hold mode, make sure to select the height hold mode in the Assist mode dropdown menu. You can set your preferred height at which the LiteWing drone needs to be hovering in the gamepad input menu. You can see the default value is around 0.4 meters. Make sure this value is between 0.1 and 3meters for the best result.

LiteWing app target height settings screen for configuring drone altitude hold parameters

Once the desired height is set, press and hold the assist control button in the controller. The drone will automatically take off and hover at the set height. To keep flying the drone, you must keep pressing the assist control button, and to land, just release the button; the drone will reduce the motor speed and land. Here is a demo showcasing the height hold functionality of the LiteWing drone.

LiteWing Take off Height Hold Demo

 

FAQ - Height Hold Mode in LiteWing

⇥ 1. Why does the height hold not work with the LiteWing drone?
Make sure to attach the VL53L1X sensor module to the drone.

⇥ 2. Even after connecting the ToF sensor, the height hold mode is not working with the LiteWing.
Make sure all the connections are correct. And you can check if the sensor is detected or not in the boot log.

⇥ 3. The height hold is working fine indoors, but not outdoors. Why?
Since the Vl53L1X sensor is an optical sensor, bright light can affect its functionality. If the outdoors is too sunny, it can affect the sensor. We would recommend using the height hold mode indoors.

⇥ 4. Height hold is working fine with the app, but not with cfclient. Why?
In the cfClient, the assist mode must be set to height hold. Also, you should use the assist control button for takeoff.

Other LiteWing Related Projects & Tutorials

Ready to take your LiteWing drone to the next level? Check out these related projects and tutorials that expand your drone's capabilities with gesture control, mobile apps, and advanced flight features.

DIY Gesture Control Drone using Python with LiteWing and ESP32

DIY Gesture Control Drone using Python with LiteWing and ESP32

In this article, we are going to show you how you can build a gesture control drone using the ESP32 dev module along with an MPU-6050.

LiteWing-ESP32 Drone gets New Mobile App

LiteWing-ESP32 Drone gets New Mobile App

Fly your LiteWing ESP32 drone with the new mobile app. Enjoy height hold, battery alerts, smooth landing, and easy controls on both Android and iOS 

 How to Program LiteWing Drone using Python with Crazyflie Cflib Python SDK

How to Program LiteWing Drone using Python with Crazyflie Cflib Python SDK

In this article, we will focus only on Cflib, which is a Python SDK from Crazyflie that allows you to write your own Python code to control your LiteWing drone. If you are not a fan of Python programming, you can also program your LiteWing using Arduino and directly reflash your ESP32, but that is for a different tutorial.

Have any question related to this Article?