AnsweredAssumed Answered

not able to detect linear motion of the device using adxl335 accelerometer

Question asked by softlab on Nov 29, 2011
Latest reply on Mar 15, 2012 by Kevin.G

Dear All,

 

I can able to read the ADXL accelerometer readings (X, Y and Z outputs) from PIC16LF1827 MCU and able to detect if the device is tilted or vibrated. But not able to detect if the device moved horizontally or verically. I have placed ADXL inside the device.

 

0.1uF ceramic capacitors used as decoupling and also on X, Y and Z outputs as filter capacitors. I have directly connected the ADXL (X, Y and Z axis) outputs to PIC MCU. No voltage-follower has been used between PIC and Sensor.

 

Steps:

 

1. Read the ADXL (X, Y and Z) outputs and store it in to variables initial_X, initial_Y and initial_Z using ADC, when device is activated.

2. wait for few seconds (say, for example, 5 seconds, it may be increased in future based on user requirements)

3. Read ADXL outputs and store the values in to variables Final_X, Final_Y and Final_Z  and compare with initial_X, initial_Y and initial_Z continuously

4. If desired difference found on ADXL output (Final_X - initial_X or Final_Y -  initial_Y or Final_Z -  initial_Z) lit the LED

 

The code is as follows:

 

IDE : MPLAB v8.63

Compiler : Hi-Tech C v9.83

 

// Declare variables to store ADXL outputs

unsigned int val_X_Initial; //ADC Value
unsigned int val_Y_Initial; //ADC Value
unsigned int val_Z_Initial; //ADC Value

 

unsigned int val_X_Final; //ADC Value
unsigned int val_Y_Final; //ADC Value
unsigned int val_Z_Final; //ADC Value

 

Step 1:

 

// READ ADC Initial values
val_X_Initial = read_ADC(0);   //Read Channel 0 (AN0/RA0)
val_Y_Initial = read_ADC(1);   //Read Channel 1 (AN1/RA1)
val_Z_Initial = read_ADC(2);   //Read Channel 2 (AN2/RA2)

 

Step 2:

 

// wait 5 seconds

__delay_ms(5000);

 

Step 3:

 

//Read ADXL outputs and store the values in to variables Final_X, Final_Y and Final_Z  and compare with initial_X, initial_Y and initial_Z continuously

 

while (1){

val_X_Final = read_ADC(0);   //Read Channel 0 (AN0/RA0)
val_Y_Final = read_ADC(1);   //Read Channel 1 (AN1/RA1)
val_Z_Final = read_ADC(2);   //Read Channel 2 (AN2/RA2)

 

Step 4:

 

//If desired difference found on ADXL output (Final_X - initial_X or Final_Y -  initial_Y or Final_Z -  initial_Z) lit the LED

 

if ((val_X_Final < (val_X_Initial - 15))|| (val_X_Final > (val_X_Initial + 15))){
       if (RB3 == 0){
           RB3 = 1;  // lit LED
       }
}
else if((val_Y_Final < (val_Y_Initial - 15))|| (val_Y_Final > (val_Y_Initial + 15))){
       if (RB3 == 0){
          RB3 = 1;   // lit LED
       }
}
else{
      if ((val_Z_Final < (val_Z_Initial - 15))|| (val_Z_Final > (val_Z_Initial + 15))){
             if (RB3 == 0){
                 RB3 = 1;  // lit LED
              }
      }
}

 

Note: Able to find Tilt and Vibrate of device but not moving the device (i.e. linear motion of the device)

 

Any help will be highly appreciated.

 

Thanks

Attachments

Outcomes