ADXL335 BREAKOUT-v2

Hi everybody!
I have bought an accelerometer ADXL335 BBoard-v2. I have found some of the online sources that did not work. I completely followed the orders and wired. But it is continuously 1023 for both axises.

The wiring order is that;
ADXL335-- Arduino Uno
Xout------ A1
Yout------ A2
Zout------ A3
GND------ GND
3V-------- AREF
Vin------- 5V

The code I am using is that;

void setup() {
pinMode(A1, INPUT); // Accelerometer for X axis
pinMode(13, OUTPUT);
analogReference(EXTERNAL);
Serial.begin(9600);
}

void loop() {
int accelVoltage;

Serial.print("Starting to read.. Volts are: ");
accelVoltage = analogRead(A1);
digitalWrite(13, HIGH); //LED
Serial.println(accelVoltage);

delay(2000);
digitalWrite(13, LOW);
delay(500);
}

So, the code above always reads 1023 even though I rotate the breadboard. It is only for x-axis but I also tried the other axises, the result was the same. When I do not include analog reference(external) line then it reads some arbitrary values not depending on the position of the breadboard, it just floats.

If anyone helps me with this issue, it will really be appreciated.

Thanks in advance :slight_smile:

Here is my sketch for doing this:

const int xInput = A5;
const int yInput = A4;
const int zInput = A3;

// initialize minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;

// Take multiple samples to reduce noise
const int sampleSize = 10;

void setup() {
analogReference(EXTERNAL);
Serial.begin(9600);
}

void loop() {
//Read raw values
int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);

// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);

// re-scale to fractional Gs
float xAccel = xScaled / 1000.0;
float yAccel = yScaled / 1000.0;
float zAccel = zScaled / 1000.0;

Serial.print("X, Y, Z :: “);
Serial.print(xRaw);
Serial.print(”, “);
Serial.print(yRaw);
Serial.print(”, “);
Serial.print(zRaw);
Serial.print(” :: ");
Serial.print(xAccel,2);
Serial.print("G, ");
Serial.print(yAccel,2);
Serial.print("G, ");
Serial.print(zAccel,2);
Serial.println(“G”);

delay(200);
}

// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}