Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Ultrasonic sensor with NRF24LE1 (Part 11/14)

By Amanpreet Singh November 14, 2021

Today we are going to interface a very interesting sensor with NRF module.

Have you ever heard bats communicating with each other? We can’t hear them because they use ultrasonic frequency to communicate with each other. Ultrasonic frequencies cannot be heard by human ears. Human can only hear sound between 20 – 20 KHz frequency whereas ultrasonic frequency lies above 20 KHz and expands up to several GHz.

Prototype of NRF24LE1 Interfacing with Ultrasonic Sensor

Fig. 1: Prototype of NRF24LE1 Interfacing with Ultrasonic Sensor

The ultrasonic waves have different travelling speed in air, liquid and gases. In air they usually travel at 340 m/s. They have the tendency to get reflected from a solid surface. Due to this functionality they are used in distance measurement. If the time between transmission and reception is known then the distance of the solid surface form the transmitter can be calculated.

We will use HCSR04 ultrasonic sensor that has transmitter, receiver and control circuit inbuilt. We will interface this sensor with NRF24LE1 using input/output pins.

HCSR04 has 4 pins:

1.     VCC – 5V

2.     Trig – Trigger input pin

3.     Echo – Output pin

4.     Gnd – Ground

Some specifications of this sensor are:

·        2cm – 400 cm distance measurement range

·        Working frequency – 40Khz

·        Uses 10 uS (micro second) Trigger pulse.

·        Transmits eight 40khz pulses when triggered

·         Receives echo and outputs high pulse with range in proportion to distance.

·        60 mS of delay should be given between next triggering.

Calculation of distance

Image of NRF24LE1 Interfacing with Ultrasonic Sensor

Fig. 2: Image of NRF24LE1 Interfacing with Ultrasonic Sensor

There are two ways to measure distance:

1. First determine the time between transmission and reception of echo. Then use the formula = Time * velocity / 2. In air velocity is 340 m/s.

2. Calculate the time for which the output pin of sensor is high. Then, use the predetermined formula, distance in cm = time/58 or distance in inch = time/148. The time will be in uS.

We will be using the second method for calculation of distance.

Please make sure that you have read our previous articles on Timers and NRF24LE1.

The NRF module will be used to trigger the senor with a 10 us pulse. After triggering, the sensor will send 40 KHz signal and will wait for the echo. If echo is received it will output a high pulse. This high pulse will have a width range in proportion to distance.

In NRF, the pin0 of port0 or P00 is used as output pin for triggering the sensor while pin 1 of port0 or P01 is used as input pin to receive the high pulse from sensor.

We are using Timer0 to measure time period for which the output pin remains high. Timer0 is initialized in Mode1 that is 16-bit mode. This means that we can measure time up to (0.75 * 65536) = 49152 uS. To calculate the time measured by timer0 we use, time = (timer0 register value * 0.75) uS. To calculate distance of solid object we can use, distance in cm = time/ 58.

We have written the code for you to understand the working.

You may also like:


  • What are the components of robotic arms and industrial robots?

  • What are the sensors used in self-driving cars?

  • What are the top open-source software systems for home automation?

  • Motion detectors or motion sensors?

  • What are the main types of proximity sensors?

  • What are the different types of fingerprint scanners?

Project Source Code

###

//Program to 
/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is confidential property of Nordic
 * Semiconductor ASA.Terms and conditions of usage are described in detail
 * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 * $LastChangedRevision: 133 $
 */
 
 
#include // standard I/O library
#include "nrf24le1.h" // I/O header file for NRF24LE1
#include "hal_uart.h" // library containing serial communication functions
#include "hal_clk.h" // library containing clock functions
#include // standard library
#include // library containing string functions
#include // library containing maths functions
#include "hal_delay.h"  // header file containing delay functions
 
sfr16 DPTR = 0X82; // functional register to hold value
 
 
// Repeated putchar to print a string
void putstring(char *s)
{
  while(*s != 0)
    putchar(*s++);
}
 
// function to convert integer into string array
void itoa(int num, char* str)
{
int i= 0, count = 0;
int temp = num;
if(num == 0)
{
str[i++] = '0';
str[i] = '';
return;
}
 
while(temp != 0)
{
int rem = temp % 10;
temp = temp/10;
count ++;
}
 
str[count --] = '';
while(num != 0)
{
int rem = num % 10;
str[count --] = (rem > 9) ? (rem - 10) + '1' : rem + '0';
num = num/10;
}
 
return;
}
 

###

 


Circuit Diagrams

Circuit-Diagram-NRF24LE1-Interfacing-Ultrasonic-Sensor

Project Video


Filed Under: Tutorials

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Resistor Selection for Amplifier Layout
  • Permittivity and Permealibility in CST
  • Testing 5kW Grid Tied inverter over 200-253VAC
  • Single ended measuring ports and balanced antenna
  • Thermal modelling of repetitive power pulse

RSS Electro-Tech-Online.com Discussions

  • Can I make two inputs from one??
  • Beats Solo 4
  • Behlke swich
  • Is AI making embedded software developers more productive?
  • Simple LED Analog Clock Idea

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe