Hello, I bought an Adafruit 5V ADXL335 that I am using with an Arduino Nano EVERY.
Current wiring order:
ADXL335 -> Arduino Nano EVERY
Xout -> A2
Yout -> A1
Zout -> A0
GND -> GND
3V -> AREF
Vin -> 5V
Current Code (credit to https://lastminuteengineers.com/adxl335-accelerometer-arduino-tutorial/):
const int xInput = A2;
const int yInput = A1;
const int zInput = A0;
// 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,0);
Serial.print("G, ");
Serial.print(yAccel,0);
Serial.print("G, ");
Serial.print(zAccel,0);
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;
}
The current issue is, for all 3 axis, only 1023 is printed constantly. Moving the accelerometer doesn't change anything. If I remove the AREF wire and get rid of analogReference(EXTERNAL), it returns a stream of random data that does not respond to tilt, i.e, it the data floats.
Any help is appreciated!