Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Ultrasonic sensor with NRF24LE1 (Part 11/14)

By Amanpreet Singh

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.

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

 

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.

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!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What is a loop calibrator? 
  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Measure AC current accurateley (100mA to 10A)
  • 74HC595 creating Fake output
  • What was before microcontrollers ?
  • NEED HELP FOR OP-AMP IN BGR
  • Check undesired substrate mode...

RSS Electro-Tech-Online.com Discussions

  • Sla ir li ion
  • Need a ducted soldering fan for solder smoke extraction
  • Question about ultrasonic mist maker
  • Best way to reduce voltage in higher wattage system?
  • Two 300nH inductor in series, can get higher current?
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 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 | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering