ADXL335 measurements in G's


I am working on Arduino mega 2560 (Mega ADK) for my project... and am trying to interface it by ADXL335.
I am getting reading i guess they are in mV...i really want to understand how can i convert them into G's.

For the time being i used the sample code which exists in the arduino software itself...and am going to develop it later to use it in my system.

Thank you in advance for you assistance....and any further information regarding this accelerometer, difficulties you guys faced and things i should take into consideration when am dealing with it....

I would really appreciate if anyone of you provide me with any further information regarding ADXL335

Thank you again

I am getting reading i guess they are in mV…

Why guess?
Your code should tell you (it doesn’t tell us anything, because we can’t see it)

Somewhere in the accelerometer’s datasheet will be a sensitivity figure, giving the number of counts or mV per g.
That will tell you how to convert mV to ms-2

Thank you for your reply :slight_smile:

This is the sample code i got from the library, just reading the analog port and display them...

const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis 

void setup()

void loop()
  // print the sensor values:



I got the clue of how to convert the readings... i will post the reading as soon as i modify the code
Thank you

OK, so the readings are not in mV, they’re raw readings.
If you want mV, they you need to multiply the raw readings by 5.0 / 1023.0.
Once you’ve got that fixed, then you need to plug in the sensitivity value from the datasheet.
There’ll also be an offset to be applied, because the accelerations will be +/-, but the accelerometer will only give positive voltages.

Regarding the sensitivity values which one should i use (max=330 , min=270 , typical=300) ?
Providing that am using 3.3v to power the accelerometer and the arduino board is powered by I2C cable.

and the offset will be solved by subtracting the zero bias voltage from the voltage i will get in mV , am i right ?

Regarding the sensitivity values which one should i use (max=330 , min=270 , typical=300) ?

Use the Z axis to calibrate it.
With the accelerometer on a level stable surface, the Z axis should read exactly 1g (or -1g depending on orientation)

the arduino board is powered by I2C cable

USB, surely?

And yes, the offset is usually half the supply voltage.

unfortunately am getting random numbers for all axises (ranging from 197 till 479 )

yes am using USB :slight_smile:

I really appreciate your help

unfortunately am getting random numbers for all axises (ranging from 197 till 479 )

Double check your connections (do your pins match the pins you're reading?) and ensure you've got a solid ground connection between your Arduino and your accelerometer.
Any strong sources of interference nearby?

Maybe concentrate on a single axis.

connections are correct...yes you are right the accelerometer is not exactly fixed to a solid ground...i will find solution for that now

if i add capacitors for noise blocking, is that going to affect my readings positively ?


i am getting some steady readings for raw values...and am trying to get the values in G's, but all what i can read are "zeros"

can you please figure out what is the problem:
this programe turn on led if adxl readings in G exceeds 2

const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
int ledpin = 2; 
const float power_supply = 5.0;
const float sensor_power_supply = 3.3;
const float zero_bias = sensor_power_supply / 2;

const int threshold_x = 2;
const int threshold_y = 2;
const int threshold_z = 2;

void setup() {
  Serial.begin   (9600);
  pinMode(ledpin, OUTPUT);
  Serial.print ("x axis \t\t");
  Serial.print ("y axis \t\t");
  Serial.print ("z axis \t\t");
void loop() {
  Serial.print ("\t\t");
  Serial.print ("\t\t");
  float voltage_x = (analogRead(xpin)) * power_supply / 1023.0;
  float x = (voltage_x - zero_bias) / 320;
  Serial.print ("\t\t");
  float voltage_y = (analogRead(ypin)) * power_supply / 1023.0;
  float y = (voltage_y - zero_bias) / 320;
  Serial.print ("\t\t");
  float voltage_z = (analogRead(zpin)) * power_supply / 1023.0;
  float z = (voltage_z - zero_bias) / 320;

if ( ( x > threshold_x) ||(y > threshold_y) || (z > threshold_z))
  digitalWrite(ledpin, HIGH);
  digitalWrite(ledpin, LOW);


Are you saying the raw voltages are zero, or the calculated g values are zero?

am getting zeros for G values