Interface do Acelerômetro com NRF24LE1 (Parte 12/14)

Accelerometer Interface with NRF24LE1 (Part 12/14)

Interface accelerometer with NRF24LE1

In this series, we learn the basic functionalities and features of the NRF24LE1 . Now it's time to use them to perform higher tasks. In the future, we will combine various features of the NRF with the outside world. Today, we will interface an accelerometer sensor with NRF24LE1 using ADC (analog to digital converter). We will also send the acceleration reading to our PC using serial communication.

Protótipo de interface NRF24LE1 com acelerômetro

Fig. 1: NRF24LE1 interface prototype with accelerometer

See our previous articles on ADC and serial communication .

We have all studied the definition of acceleration, which says that it is the rate of change of speed. Previously, we used to calculate acceleration manually using formulas, but this is an era of digital world; sensors are now available to replace the manual task. These sensors have a wide range of applications, be it a robotic arm or a rocket. The accelerometer sensor we will use is the ADXL335.

Some basic features of ADXL335:

· 3-axis detection

· Low power – 350 uA (typical)

· 1.8V – 3.6V operation

· Small size

Detection range from -3g to +3g

Operation:

This module has 3 analog output pins for acceleration in the X, Y and Z directions. The output voltage on these pins ranges from 0 – 3.3V.

Layout de PCB de interface NRF24LE1 com acelerômetro

Fig. 2: PCB layout of NRF24LE1 interface with accelerometer

3.3V corresponds to +3g where g is the gravitational acceleration.

We will use NRF's built-in ADC to convert the analog voltage detected in the module and the reference voltage for ADC will be 3.3V. Analog pin X will be connected to Pin0.0, Y to Pin0.1 and Z to Pin0.2. The module for ADXL335 already has a built-in 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 the 0g value from them. 0g means there is no acceleration, but the accelerometer sensor still outputs some analog voltage to it. So we have to reduce this value from the detected digital value.

The 0g output value can be found in the sensor datasheet. The 0g value we are using is 1.33 V for X, 1.6 V for Y, and 0.84 V for Z direction. The corresponding digital values ​​are 103, 124, and 65.

After subtracting the 0g values, we will divide the result by the sensitivity of the sensor. Sensitivity is measured in mV/g. It can be found in the technical sheet. We are using a value of almost 300mv/g for Sensitivity. The corresponding digital value is around 23. After division, the result will be in terms of g.

Therefore, 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 ​​detected in the module.

We will transmit the calculated acceleration to the PC via serial communication. The pin for serial transmission is P0.3. We have also mentioned the code for clearer understanding.

Project source code

###

 //Program to

/* Copyright (c) 2009 Nordic Semiconductor. All rights reserved.

*
*The information contained herein is the confidential property of Nordic
* ASA Semiconductor. Terms and conditions of use are described in detail * in the NORDIC SEMICONDUCTORS STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free and non-transferable use of the information. NO * WARRANTY OF ANY KIND is provided. This title should NOT be removed from the * the file. * *$LastRevisionAmended: 133$ */ #include //standard I/O library #include //standard library #include "nrf24le1.h" // library NRF24LE1 #include "hal_adc.h" // ADC function library #include "hal_uart.h" // UART function library #include "hal_clk.h" #include //String function library #include //Mathematical functions library #include "hal_delay.h" // delay function library /////////////////////////// function to convert integer to string array empty itoa(int num, char* str) { int i= 0, count = 0; internal temperature = num; if(num == 0) { str(i++) = '0'; str(i) = ''; turn back; } while (temperature!=0) { int rem = temp% 10; temperature = temperature/10; count++; } str(count --) = ''; while(num!= 0) { int rem = num% 10; str(count --) = (rem > 9) ? (rem - 10) + '1' : rem + '0'; num = num/10; } turn back; } // Putchar repeated to print a string void putstring(char *s) { while(*s != 0) hal_uart_putchar(*s++); }

###

Circuit diagrams

Circuit Diagram-NRF24LE1-Accelerometer Interface

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.