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 Boot Raspberry Pi from USB without SD Card

Want to boot your Raspberry Pi from USB instead of unreliable SD cards? If you've used a Raspberry Pi long enough, you've probably faced the dreaded SD card failure. Maybe it corrupted right after a power outage, or maybe it just wore out from thousands of log writes. That's when I finally decided no more SD cards. They're great for getting started with Raspberry Pi, but when you want reliability and speed, it’s best to boot Raspberry Pi from USB.

And with the newer Raspberry Pi models, boot raspberry from USB is not only just possible, it's surprisingly easy once you know which Pi you're dealing with. I went through the process for multiple models – Pi 3B, 3B+, 4B, and even the new Pi 5. So if you're wondering whether your Pi can ditch the microSD and run from USB alone, this guide is for you.

Why Boot Raspberry Pi from USB Instead of SD Card?

By default, Raspberry Pi boots from a microSD card. It's cheap and works fine, until it doesn't. Performance aside, SD cards wear out over time, especially with heavy I/O. If you're running anything that involves a lot of reads and writes, such as databases or frequent logging, this can become a real issue.

But there's also a speed factor. I found out that the Raspberry Pi 4's SD interface maxes out at around 50 MB/s. Older models like the 3B and 3B+ are even slower, topping out at roughly 25 MB/s. And in reality, even the best SD cards only deliver around 38 MB/s write speeds. That's just not ideal for running an operating system or doing any kind of heavy disk activity.

Now compare that to a USB 3.0 SSD. In real-world tests it was able to hit read speeds of 208 MB/s and write speeds of 140 MB/s. That's over five times faster than the best SD cards.

The difference is noticeable. Booting, installing packages, file operations, and even just browsing the Raspberry Pi OS desktop all feel significantly snappier with USB boot. If you’re moving beyond basic projects, configuring your setup to Raspberry pi boot from SSD can significantly boost performance.

How to Boot Raspberry Pi from USB ?

I quickly learned that not all Raspberry Pi models behave the same when figuring out how to boot Raspberry Pi from USB without SD card.

Raspberry Pi Model

USB Boot Support

Description

Pi 3B

With one-time config

Needs an OTP flag set via SD card

Pi 3B+

Out of the box

USB boot enabled by default

Pi 4

Native with EEPROM

Supports USB 3.0 boot

Pi 5

Full support

Supports USB, PCIe NVMe boot

Raspberry Pi 3B: The One-Time USB Unlock

This one took a bit of digging. The Pi 3B doesn't support USB booting out of the box, you need to flip a hidden internal switch. More specifically, you need to set a flag in the Pi's OTP (One-Time Programmable) memory. It's permanent, but once set, you can boot from USB raspberry pi forever, even without a microSD card present.

⇒ Step 1: Boot from an SD Card with Raspberry Pi OS

To get started, I flashed the standard Raspberry Pi OS onto a microSD card and booted the Pi 3B from it. You can use Raspberry Pi Imager to do this. Once the OS is running, open up a Terminal window, you'll need it for the next steps.

⇒ Step 2: Enable USB Boot Mode via config.txt

Here's the command I ran:

USB Boot Mode on Raspberry Pi
echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt

What this does:

echo program_usb_boot_mode=1

writes the config flag to enable USB boot.

The(pipe)

sends that string into the next command.

sudo tee -a /boot/config.txt

appends that line to the file /boot/config.txt using superuser privileges.

By adding program_usb_boot_mode=1 to the config file, the Pi knows to write a flag to its OTP memory on the next reboot. This only needs to be done once in the Pi's lifetime, it won't harm the Pi or prevent future SD card boots.

⇒ Step 3: Reboot to Apply the Change

After modifying config.txt, I ran:

sudo reboot

This reboots the Pi and triggers the bootloader to read that new config option. If it sees program_usb_boot_mode=1, it writes the USB boot flag to the Pi's OTP memory.

⇒ Step 4: Verify OTP Flag is Set

Once the Pi restarted, I wanted to make sure the USB boot flag had been written correctly. So I ran:

vcgencmd otp_dump | grep 17:
OTP Verification to Boot Raspberry Pi from USB

Here's what that does:

vcgencmd otp_dump

dumps the contents of the Pi’s OTP memory (One-Time Programmable).

| grep 17:

filters for line 17, which contains the specific USB boot bit.

If the command returns something like:

17:3020000a

That's your confirmation, to boot Raspberry Pi from USB is now permanently enabled on your Pi 3B.

⇒ Step 5: Boot from USB (No SD Card!)

I flashed Raspberry Pi OS to a USB stick (just like I would with an SD card), plugged it into the Pi 3B's USB port, and removed the SD card. When I powered the Pi back on, it booted straight from USB. No more SD cards needed!

Raspberry Pi 3B+: USB Boot That Just Works

If you're using a Raspberry Pi 3B+, you're in luck. USB boot is already enabled from the factory. That means you don't need to tweak any config files or run terminal commands. You just flash the OS to a USB drive and can boot raspberry from USB immediately.

Here's exactly what I did using Raspberry Pi Imager:

⇒ Step 1: Open Raspberry Pi Imager: I started by opening the Raspberry Pi Imager on my PC. It's the official tool for flashing OS images onto SD cards or USB drives.

⇒ Step 2: Choose Your Pi Model: On Raspberry Pi Imager lets you specify the target board. I clicked the "Choose Device", and I selected Raspberry Pi 3B+. This helps the tool optimize the OS for your model.

Choose Raspberry Pi Model In Imager

⇒ Step 3: Choose Your Raspberry Pi OS: I clicked "Choose OS" and selected Raspberry Pi OS (32-bit) from the list. You can also use Raspberry Pi OS Lite if you're setting up a headless Pi (no monitor).

Choose Raspberry Pi OS In Imager

⇒ Step 4: Select the USB Drive: Next, I clicked "Choose Storage" and selected my USB stick from the list. Make sure you're selecting the correct drive, it will be erased during flashing.

Select USB Drive Raspberry Pi

⇒ Step 5: Write the OS: I clicked "Write", confirmed the warning, and let it flash the OS to my USB stick. This part took about 5-10 minutes.

⇒ Step 6: Boot the Pi 3B+ from USB: With the USB stick ready, I unplugged the SD card from the Pi (if there was one), inserted the USB stick into one of the Pi's USB ports, and powered it on.

And that was it. The Pi 3B+ booted from USB without any extra setup. No config files, no flashing bootloaders, just plug and go.

Raspberry Pi 4: Bootloader with EEPROM

The Raspberry Pi 4 is a major step forward. Instead of hard-coded boot logic, it uses a dedicated EEPROM chip to store its bootloader. That means you can update it and change how the Pi boots. By default, older Pi 4 boards may still prioritize microSD boot, but this can be reconfigured to allow a Raspberry Pi 4 boot from USB without SD card.

Option 1: CLI Method

⇒ Step 1: Boot from SD and Open Terminal

As before, I booted from an SD card loaded with Raspberry Pi OS and opened Terminal

⇒ Step 2: Update Everything

I ran the following to make sure my system and bootloader were fully up to date:

sudo apt update
Boot Raspberry Pi from SD and Open Terminal

sudo apt update: Fetches the latest package info from the repositories.

sudo apt full-upgrade -y

sudo apt full-upgrade: Installs updates for everything, including firmware and kernel.

Then I ran:

sudo rpi-eeprom-update -a

EEPROM Raspberry Pi

This command checks for the latest bootloader update and installs it if necessary. The -a flag means "apply any available updates automatically."

⇒ Step 3: Set Boot Order to USB

Next, I opened the Raspberry Pi configuration tool:

sudo raspi-config
Raspberry Pi Configuration Tool

Then navigated to: "Advanced Options → Boot Order → USB Boot"

Raspberry Pi ConfigurationBoot Order SelectSD Card BootRaspberry Pi Reboot

This sets the EEPROM bootloader to look for a USB drive first, before falling back to microSD.

⇒ Step 4: Reboot and Remove SD Card

Once the boot order was set, I rebooted, powered down the Pi, removed the SD card, and plugged in my USB SSD with Raspberry Pi OS installed. On the next power-up, you can now boot raspberry pi 4 from usb, faster than ever.

Option 2: Raspberry Pi Imager Bootloader Update

If you want to know how to boot a Raspberry Pi from USB without an SD card and avoid terminal, Raspberry Pi Imager offers a user-friendly solution. Here is how.

1.Open Raspberry Pi Imager on your PC and choose the Board.

Choose Raspberry Pi Model In Imager

2.Click "Choose OS" → scroll down to Misc Utility ImagesBootloader → select USB Boot.

Boot Raspberry Pi from USB

 

3.Click "Choose Storage" and select an SD card.

Select USB Drive Raspberry Pi

4.Click Write and wait for it to finish.

Erase SD from Raspberry Pi

5.Insert the SD card into your Pi and power it on.

In about 10 seconds, the green LED will blink rapidly or the screen may turn green, this means the bootloader update succeeded. Power off, remove the SD card, and you're now USB-boot ready.

Raspberry Pi 5 with Native USB and NVMe Boot

The Pi 5 is the most powerful Raspberry Pi yet and it comes with native support for USB 3.0 and PCIe booting right out of the box. No updates, no flags, no EEPROM tweaks required.

Here's All I Did:

  • Used Raspberry Pi Imager to flash Raspberry Pi OS to a USB SSD.
  • Plugged the SSD into one of the blue USB 3.0 ports.
  • Powered on the Pi 5 (with no SD card).

For insane performance on a Pi 5, use its PCIe port with a compatible NVMe adapter to make your Raspberry pi boot from ssd just like a mini PC.

Should You Boot Raspberry Pi From USB?

If you're tired of SD card failures, want faster performance, or just want your Pi to feel more like a real computer, yes, the reliability you gain when you learn how to boot Raspberry Pi from USB without SD card is 100% worth it.

For casual projects, SD cards are fine, but to add speed and reliability for servers or media centers, the best move is to boot Raspberry from USB.

If you want help flashing Raspberry Pi OS to a USB SSD, choosing the best drives, or even trying out NVMe booting on the Pi 5, especially for Raspberry Pi 4 boot from USB without SD card setups, I'd be happy to walk you through that next.

Q1 How do I know if my Raspberry Pi 4 supports USB boot?

All Pi 4 models support USB boot, but units manufactured before mid-2020 may need a bootloader update. Check your bootloader version with vcgencmd bootloader_version - you need version 2020-04-16 or later for stable USB boot support.

Q2 Is boot raspberry from USB faster than SD card boot?

Yes, but the speed improvement depends on your storage and Pi model. USB 3.0 SSDs can achieve enables significantly faster data transfer rates vs SD cards. However, the Pi 4's USB controller shares bandwidth with Ethernet, and actual performance varies by workload.

Q3 How do I troubleshoot USB boot failures?

Check systematically: verify bootloader version (vcgencmd bootloader_version), ensure USB drive has proper boot partition structure, test with known-good USB device, try different USB ports, check power supply adequacy (especially for SSDs), and verify boot order in raspi-config for Pi 4.

Raspberry Pi Setup Tutorials

Basic Raspberry Pi setup and configuration tutorials for beginners. If your goal is a seamless Raspberry pi boot from SSD, start by solidifying your foundation with these basic configuration steps.

 Getting Started with Raspberry Pi - Introduction

Getting Started with Raspberry Pi - Introduction

New to Raspberry Pi? This beginner-friendly guide guide you through the setup, OS installation, and basic usage of Raspberry Pi boards with practical tips.

 How to install Android on Raspberry Pi

How to install Android on Raspberry Pi

In this tutorial we will convert the Raspberry Pi in an Android device using a popular platform - emteria.OS.

How to setup DietPi on Raspberry Pi

How to setup DietPi on Raspberry Pi

Learn how to install DietPi on Raspberry Pi with this step-by-step guide. Set up a lightweight, optimized OS for your Pi with better speed and control.

 

Have any question related to this Article?

Understanding SR Latches: Complete Guide to Set-Reset Latch, Gated & Clocked Versions

An SR latch is a basic memory element in digital electronics that stores binary data using Set and Reset inputs. This SR latch tutorial covers the SR latch truth table, the SR latch circuit diagram, and the working principle of basic, gated, and clocked SR latch variants. 

Initially, after the introduction of transistors, engineers constructed simple latch circuits using transistors. After several stages of evolution, dedicated latches were built using logic gates like the NAND gate and NOR gate. These latches were used to store data, essentially binary data. The primary types of latches include SR latch, D latch, JK latch, and T latch. In this article, we’ll briefly take a look at the SR Latch, along with its Gated SR Latch and Clocked SR Latch versions.

What is an SR Latch?- Complete Definition

The SR Latch, also known as the Set-Reset Latch, is a fundamental digital memory circuit that stores one bit of binary data using two inputs, namely Set (S) and Reset (R). When Set is activated, the latch outputs '1' (HIGH), and when Reset is activated, it outputs '0' (LOW). The stored value remains stable even after inputs are removed, making it a basic memory element. This latch can be built using either NOR or NAND gates, with the key difference being that NAND implementation uses inverted (active LOW) inputs compared to NOR gates.

Note: If a latch circuit, such as an SR Latch, is edge-triggered using a clock pulse, it becomes a flip-flop. So, ideally, latches and flip-flops are two different things and should not be confused for the same. In our case, if the SR latch is given a clock pulse, it becomes a clocked SR latch, which is also called an SR Flip-Flop. If you are completely new to flip-flops and latches, check out our tutorial on Basics of Flip-Flops in Digital Electronics

Key Elements of SR Latches

  • Set (S) Input: Forces Q output to the HIGH state (logic 1)
  • Reset (R) Input: Forces Q output to the LOW state (logic 0) 
  • Q Output: Primary output (representing stored bit)

Sometimes you may also see a Q̅, which is nothing but an inverted output of Q. In the image below, you can see the symbol and a simple SR Latch truth tableFrom the table, you can notice that the logic is straightforward since it's a memory element.

SR Latch Truth Table - Complete Analysis

The SR latch truth table defines all possible input combinations and corresponding outputs. This table serves as the foundation for understanding SR latch behaviour in digital circuits.

SR Latch Truth Table - Set Reset Logic States and Output

SR Latch Diagram States Explained

There are four possible logic states for this latch:

  1. When both inputs are LOW, the output remains unchanged. Initially, the output will be undefined (random), but after any other condition is applied, the “both LOW” state will retain the last output.
  2. When Set is LOW and Reset is HIGH, the output Q goes to the Reset state, which is LOW.
  3. When Set is HIGH and Reset is LOW, the output Q enters the Set state, which is HIGH.
  4. In the rare case where both Set and Reset are HIGH, the output Q becomes unstable due to the racing condition. Therefore, this state is considered invalid.

SR Latch Circuit Diagram - NAND and NOR Implementations

The SR latch circuit diagram can be implemented using either NAND gates or NOR gates, each with distinct characteristics and input polarities. Below, you can see a working simulation of a simple SR Latch made using NAND gates, built using Proteus. You can notice how the output values Q and Q̅ change based on the input values S and R. 

SR Latch NAND Gate Circuit Working Animation - Digital Logic Tutorial

Now, let’s take a look at the Gated and Clocked versions of the SR Latch.

Gated SR Latch - Enhanced Control Mechanism

For the most part, the gates SR Latch is similar to the standard SR Latch. The only difference is the addition of one extra input, known as Enable. Below, you can see the Gated SR latch truth table and symbol for better understanding.

Gated SR Latch Truth Table with Enable Input

It looks quite similar to the standard SR Latch. The Enable input allows us to enable or disable the latch, providing more control compared to the basic version. Below is a Gated SR Latch built using NAND logic gates in Proteus. This simulation will help you understand the concept clearly.

Gated SR Latch NAND Implementation - Enable Control Working Demo

The logic here is generally the same as a standard SR Latch, with the only addition being the Enable input.

  1. If the Enable input is HIGH, the Gated SR Latch works as expected.
  2. If the Enable input is LOW, regardless of the S and R inputs, the output remains unchanged—in other words, the previous state is held.

Clocked SR Latch

The Clocked SR Latch, also known as the SR Flip-Flop, is very similar to the Gated SR Latch, except that the Enable input is replaced by a Clock input. Instead of a stable enable line, the output now depends on the rising or falling edge of the clock signal. This is called edge-triggered behaviour.

Below, you can see the symbol and the SR Latch truth table for a better grasp of the concept.

Clocked SR Latch Truth Table - SR Flip Flop Working Principle

Clocked SR Latch Benefits

  • Edge Triggered: Changes in state occur with the clock transition; the latch is insensitive to the input during any other time
  • Noise-Immunity: Glitches get through only when the clock is not transitioning
  • Synchronous Operation: Enables timing coordination in consecutive processes
  • Timing Predictability: Sidesteps race hazards in systems with complex timing

So, this Clocked SR Latch is essentially an SR Flip-Flop. To learn more about this, you can check out the Flip-Flop in Digital Electronics article for additional information and practical demonstrations. You can also view the simulation result using Proteus in the simulation image below.

Clocked SR Latch Working Animation - Edge Triggered Flip Flop


As mentioned earlier, the Clocked SR Latch is an edge-triggered device, which makes it more reliable for timed operations in sequential circuits. The working logic is slightly different from that of a regular latch circuit.

To keep it simple, here’s how it works:

  1. No Change (S = R = 0): The flip-flop retains its previous state.
  2. Set (S = 1, R = 0): Output Q becomes ‘1’ (Set).
  3. Reset (S = 0, R = 1): Output Q becomes ‘0’ (Reset).
  4. Invalid (S = R = 1): Both outputs (Q and Q̅) may become ‘1’, leading to instability. This condition is generally avoided in practical designs.

All these transitions happen only on the positive or negative clock edge, depending on the specific components used in the circuit.

Frequently Asked Questions on SR Latch Table

⇥ 1. What is the difference between an SR latch and a D latch? 
An SR latch works with two distinct inputs, Set and Reset, and careful activation of only one of the inputs is required to avoid race conditions. By contrast, a D latch has one data input; the complementing actions take place automatically, hence preventing invalid states and providing a simpler and more reliable operation for digital systems.

⇥ 2. What is invalid for the SR latch if S=1, R=1? 
By establishing both inputs of the latch as HIGH and consequently trying to set a 1 at Q and reset a 0 at Q̅, creates an indeterminate state of either 0 or 1. This indeterminate state can initiate an oscillating output and/or lead to unpredictable or undefined behaviour of the circuit. More importantly, the race condition invalidates that Q and Q̅ must be complementary values at any stable output state.

⇥ 3. What is the limiting factor of the SR latch propagation delay? 
Propagation delay can restrict switching speed and timing margins. Propagation delay governs the maximum operating frequency of sequential circuits and the setup and hold time, and gated SR latches based on NAND typically achieve about 2-5ns of propagation delay, and NOR is assumed to be slower.

⇥ 4. What will happen to the output of the SR latch at power-on?
The latch will not have a defined output as it will be unpredictable due to component variation, as well as noise at startup. Most latch/systems would contain a power-on reset circuit to force a specific initial state and highly likely take advantage of RC networks or power-on reset integrated circuits for reliable startup at system power-on.

⇥ 5. How much power does an SR latch consume? 
For CMOS implementations, static power consumption will be almost negligible, with the exception of leakage current; however, dynamic power will depend on switching frequency. At moderate switching speeds, it would be quite minute, about 0.1 - 1 mW. Generally, a NAND implementation will consume less power than the NOR counterparts for most logic families.

⇥ 6. How will temperature affect the SR latch's behaviour? 
Increased temperature will increase propagation delays while also compromising noise margins. Commercial-rated devices will be operable within a temperature range of 0 °C - 70 °C, with the industrial counterparts rated -40 °C - 85 °C. Compensation circuits may thus be needed for some applications that require exactness.

⇥ 7. How fast can SR latches operate at?
Most modern CMOS implementations of the SR latch can operate at a frequency of a few GHz, limited by the propagation delay of the latch and parasitic capacitances that result from wiring in the implementation.  The practical frequency of operation will depend on what logic family the latch is in: TTL (50 - 100 MHz), CMOS (500 MHz - 2 GHz), and newer processes have demonstrated even greater speeds.

This SR latch tutorial covered the fundamental working principle, truth table, and circuit diagrams of basic SR latch, gated SR latch, and clocked SR latch implementations. Understanding these digital logic building blocks is essential for sequential circuit design and memory applications in electronics. If you have any questions, leave them in the comment sections at the bottom of this page, and we will be happy to answer them. You can also join our community or forums to start a discussion. 

More Digital Electronics Tutorials

Sequential Logic Circuits:

Similar Tutorials on SR Flip Flops

If you would like to learn more about SR Flip-Flops, these tutorials include helpful diagrams, truth tables, and logic circuits to guide you through the concepts.

Clocked SR Flip Flop: Complete Guide with Circuit, Truth Table, and Working

Clocked SR Flip Flop: Complete Guide with Circuit, Truth Table, and Working

Learn how Clocked SR Flip-Flops work using NAND and NOR gates. Includes truth tables, logic diagrams, and real-world timing applications.

SR Flip-Flop with NAND Gates: Circuit, Truth Table and Working

SR Flip-Flop with NAND Gates: Circuit, Truth Table and Working

Learn how to build an SR Flip-Flop circuit using NAND gates. Understand the logic, truth table, working principle, and output behaviour with a complete circuit diagram and explanation

 What is Switch Bouncing and How to prevent it using Debounce Circuit

What is Switch Bouncing and How to prevent it using Debounce Circuit

Learn how switch bouncing can affect SR Flip-Flop circuits and how to prevent false triggering using debounce techniques like RC filters and Schmitt triggers in digital logic systems.

Have any question related to this Article?