Interfacing Accelerometer with NRF24LE1
In this series we have learnt the basic functionalities and features of NRF24LE1. Now it’s time to use them for achieving higher tasks. In future, we will combine various functionalities of the NRF with outer world. Today, we will interface an accelerometer sensor with NRF24LE1 using ADC (Analog to digital converter). We will also output the acceleration reading to our PC using Serial communication.
Fig. 1: Prototype of NRF24LE1 Interfacing with Accelerometer
Please refer to our previous articles on ADC and Serial Communication.
We all have studied the definition of acceleration which says that it is the rate of change of velocity. Earlier, we used to calculate the acceleration manually by using formulas but this is an era of digital world; now sensors are available to replace the manual task. These sensors have a wide range of applications whether it is a robotic arm or a rocket. The accelerometer sensor that we will be using is ADXL335.
Some basic features of ADXL335:
·       3 axis sensing
·       Low power – 350 uA(typical)
·       1.8V – 3.6 V operation
·       Small Size
·       -3g to +3g sensing range
Functioning:
This module has 3 analog output pins for acceleration in X, Y and Z direction. The output voltage in these pins varies from 0 – 3.3V.
Fig. 2:Â PCB Layout of NRF24LE1 Interfacing with Accelerometer
 3.3V corresponds to +3g where g is the gravitational acceleration.
We will use the inbuilt ADC of NRF to convert the analog voltage sensed from the module and the reference voltage for ADC will be 3.3V. The X analog pin will connect to Pin0.0, Y to Pin0.1 and Z to Pin0.2. The module for ADXL335 already has an inbuilt 3.3V regulator IC. So we will supply 5V to this module.
After getting the converted digital value for different directions we have to subtract 0g value from them. 0g means no acceleration but the accelerometer sensor still outputs some analog voltage for it. So we have to reduce this value from the sensed digital value.
The 0g output value can be found in the datasheet of the sensor. The 0g value which we are using is 1.33V for X, 1.6V for Y and 0.84V for Z direction. The corresponding digital values are 103, 124 and 65.
After subtracting the 0g values we will divide the result with sensitivity of the sensor. Sensitivity is measured in mV/g. It can be found in the datasheet. We are using nearly 300mv/g value for Sensitivity. The corresponding digital value is around 23. After dividing, the result will be in terms of g.
So, the formula for calculating acceleration is:
Acceleration in X= (x – 103.0)/23.0;
Acceleration in Y = (y – 124.0)/23.0;
Acceleration in Z = (z – 65.0)/21.0;
Where x, y and z are the analog values sensed from the module.
We will transmit the acceleration calculated to PC using serial communication. The pin for serial transmission is P0.3. We have also mentioned the code for a clearer understanding.
You may also like:
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// standard library #include "nrf24le1.h" // NRF24LE1 library#include "hal_adc.h"  // ADC function libraryÂ#include "hal_uart.h"  // UART functions library#include "hal_clk.h"Â#include // String functions library #include // Maths functions library #include "hal_delay.h"  // delay functions libraryÂÂ//////////////////////////// function to convert integer to 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;}// Repeated putchar to print a stringvoid putstring(char *s){ while(*s != 0)   hal_uart_putchar(*s++);}###
Â
Circuit Diagrams
Project Video
Filed Under: Tutorials
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!!
You must be logged in to post a comment.