Go Down

Topic: ADXL 335 Defect? (Read 494 times) previous topic - next topic

Soulfly

Heyho guys,

I got problems with 2 adxl 335s I ordered. One of them like a moonth ago i started interfacing it with this simple code:

const int xpin = A8; // x-axis of the accelerometer
const int ypin = A9; // y-axis
const int zpin = A10; // z-axis
 
void setup()
{
Serial.begin(9600);
}
 
void loop()
{
int x = analogRead(xpin)-195; //read from xpin   // these values were the ones which i measured when the sensor was even laying on the desk.

int y = analogRead(ypin)-359; //read from ypin

int z = analogRead(zpin)-413; //read from zpin

Serial.print(x); //print x value on serial monitor
Serial.print("\t");
Serial.print(y); //print y value on serial monitor
Serial.print("\t");
Serial.print(z); //print z value on serial monitor
Serial.print("\n");
delay(1000); //wait for 1 second
}


So the problem here was that everytime i connected it again to the arduino it was giving out totaly different values .... so i wasn't sure if it was working correctly and ordered a new one

tried out the same code but the only time its changing values is when i change the supply voltage form 3.3 to 5 (which the board should handle -> GY61) even tilting and shaking the sensor didnt alter the values.

Are both of the adxls defect? What am I doing wrong...?

Thanks in advance

wildbill

Which Arduino are you using? How is it wired to the Accelerometer?

Soulfly

Arduino Mega 2560
VCC of Sensor to 3.3V
X,Y,Z to Analog Inputs (each)
gnd to 0V
ADXL 335 (GY-61 Board)

MarkT

Those calibrations seem way off - when you measured them was the z-axis vertical?  If so the x calibration value is totally wrong. Y calibration seems plausible.

Where did you get those modules?  Could they be counterfeit?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Soulfly

both from amazon from a certified retailer idk if theyre counterfeit atleast the first one is responding in a semi-plausible way...


As said the sensor was measured when laying even on the desk no shaking or movement done to it :/

jremington

#5
Apr 26, 2019, 05:28 pm Last Edit: Apr 26, 2019, 05:29 pm by jremington
Please use code tags when posting code.

Take out the (wrong) subtractive constants in the code below, print out and post the measured ADC values for several fixed orientations of the accelerometer (Z up and down, X up and down, etc.)

Code: [Select]
int x = analogRead(xpin)-195; //read from xpin   // these values were the ones which i measured when the sensor was even laying on the desk.

int y = analogRead(ypin)-359; //read from ypin

int z = analogRead(zpin)-413; //read from zpin



I suggest to study this guide to learn how to calibrate an accelerometer.

Soulfly

Code: [Select]
20:20:03.051 -> X, Y, Z  :: 37, 507, 487 :: -3G, -0G, -0G
20:20:03.258 -> X, Y, Z  :: 37, 507, 487 :: -3G, -0G, -0G
20:20:03.466 -> X, Y, Z  :: 37, 511, 490 :: -3G, -0G, -0G
20:20:03.673 -> X, Y, Z  :: 37, 496, 490 :: -3G, -0G, -0G
20:20:03.914 -> X, Y, Z  :: 37, 489, 495 :: -3G, -0G, -0G
20:20:04.089 -> X, Y, Z  :: 37, 495, 494 :: -3G, -0G, -0G
20:20:04.296 -> X, Y, Z  :: 37, 496, 492 :: -3G, -0G, -0G
20:20:04.538 -> X, Y, Z  :: 37, 507, 488 :: -3G, -0G, -0G
20:20:04.746 -> X, Y, Z  :: 38, 507, 489 :: -3G, -0G, -0G
20:20:04.953 -> X, Y, Z  :: 38, 508, 488 :: -3G, -0G, -0G
20:20:05.159 -> X, Y, Z  :: 38, 512, 487 :: -3G, 0G, -0G
20:20:05.366 -> X, Y, Z  :: 38, 482, 485 :: -3G, -0G, -0G
20:20:05.574 -> X, Y, Z  :: 38, 433, 479 :: -3G, -0G, -0G
20:20:05.781 -> X, Y, Z  :: 38, 411, 476 :: -3G, -1G, -0G
20:20:05.989 -> X, Y, Z  :: 38, 400, 480 :: -3G, -1G, -0G
20:20:06.197 -> X, Y, Z  :: 38, 403, 480 :: -3G, -1G, -0G
20:20:06.404 -> X, Y, Z  :: 38, 403, 480 :: -3G, -1G, -0G
20:20:06.611 -> X, Y, Z  :: 39, 404, 479 :: -3G, -1G, -0G
20:20:06.819 -> X, Y, Z  :: 39, 408, 477 :: -3G, -1G, -0G
20:20:07.028 -> X, Y, Z  :: 39, 401, 478 :: -3G, -1G, -0G
20:20:07.236 -> X, Y, Z  :: 39, 404, 479 :: -3G, -1G, -0G
20:20:07.442 -> X, Y, Z  :: 39, 404, 477 :: -3G, -1G, -0G
20:20:07.648 -> X, Y, Z  :: 39, 404, 478 :: -3G, -1G, -0G
20:20:07.855 -> X, Y, Z  :: 39, 405, 479 :: -3G, -1G, -0G
20:20:08.063 -> X, Y, Z  :: 39, 404, 479 :: -3G, -1G, -0G
20:20:08.269 -> X, Y, Z  :: 39, 402, 479 :: -3G, -1G, -0G
20:20:08.474 -> X, Y, Z  :: 40, 403, 480 :: -3G, -1G, -0G
20:20:08.679 -> X, Y, Z  :: 39, 403, 479 :: -3G, -1G, -0G
20:20:08.886 -> X, Y, Z  :: 40, 403, 479 :: -3G, -1G, -0G
20:20:09.089 -> X, Y, Z  :: 40, 406, 477 :: -3G, -1G, -0G
20:20:09.296 -> X, Y, Z  :: 40, 404, 478 :: -3G, -1G, -0G
20:20:09.502 -> X, Y, Z  :: 40, 403, 479 :: -3G, -1G, -0G
20:20:09.711 -> X, Y, Z  :: 40, 405, 478 :: -3G, -1G, -0G
20:20:09.953 -> X, Y, Z  :: 40, 402, 478 :: -3G, -1G, -0G
20:20:10.126 -> X, Y, Z  :: 40, 403, 480 :: -3G, -1G, -0G
20:20:10.333 -> X, Y, Z  :: 40, 403, 480 :: -3G, -1G, -0G
20:20:10.572 -> X, Y, Z  :: 40, 404, 477 :: -3G, -1G, -0G
20:20:10.779 -> X, Y, Z  :: 40, 404, 479 :: -3G, -1G, -0G
20:20:10.986 -> X, Y, Z  :: 41, 404, 478 :: -3G, -1G, -0G
20:20:11.190 -> X, Y, Z  :: 41, 403, 478 :: -3G, -1G, -0G
20:20:11.396 -> X, Y, Z  :: 41, 400, 478 :: -3G, -1G, -0G
20:20:11.604 -> X, Y, Z  :: 41, 404, 480 :: -3G, -1G, -0G
20:20:11.810 -> X, Y, Z  :: 41, 400, 480 :: -3G, -1G, -0G
20:20:12.018 -> X, Y, Z  :: 41, 402, 478 :: -3G, -1G, -0G
20:20:12.224 -> X, Y, Z  :: 41, 402, 480 :: -3G, -1G, -0G
20:20:12.431 -> X, Y, Z  :: 41, 399, 483 :: -3G, -1G, -0G
20:20:12.640 -> X, Y, Z  :: 41, 402, 484 :: -3G, -1G, -0G
20:20:12.847 -> X, Y, Z  :: 41, 407, 482 :: -3G, -1G, -0G
20:20:13.054 -> X, Y, Z  :: 41, 406, 483 :: -3G, -1G, -0G
20:20:13.259 -> X, Y, Z  :: 41, 406, 481 :: -3G, -1G, -0G
20:20:13.466 -> X, Y, Z  :: 42, 402, 474 :: -3G, -1G, -0G
20:20:13.675 -> X, Y, Z  :: 42, 418, 439 :: -3G, -1G, -0G
20:20:13.882 -> X, Y, Z  :: 42, 476, 401 :: -3G, -0G, -1G
20:20:14.084 -> X, Y, Z  :: 42, 489, 387 :: -3G, -0G, -1G
20:20:14.292 -> X, Y, Z  :: 42, 500, 386 :: -3G, -0G, -1G
20:20:14.500 -> X, Y, Z  :: 42, 500, 388 :: -3G, -0G, -1G
20:20:14.737 -> X, Y, Z  :: 42, 500, 389 :: -3G, -0G, -1G
20:20:14.945 -> X, Y, Z  :: 43, 500, 388 :: -3G, -0G, -1G
20:20:15.153 -> X, Y, Z  :: 42, 496, 387 :: -3G, -0G, -1G
20:20:15.360 -> X, Y, Z  :: 43, 499, 387 :: -3G, -0G, -1G
20:20:15.569 -> X, Y, Z  :: 42, 506, 387 :: -3G, -0G, -1G
20:20:15.777 -> X, Y, Z  :: 43, 501, 385 :: -3G, -0G, -1G
20:20:15.986 -> X, Y, Z  :: 43, 499, 389 :: -3G, -0G, -1G
20:20:16.194 -> X, Y, Z  :: 43, 530, 396 :: -3G, 0G, -1G
20:20:16.402 -> X, Y, Z  :: 43, 559, 409 :: -3G, 0G, -1G
20:20:16.610 -> X, Y, Z  :: 43, 593, 421 :: -3G, 0G, -1G
20:20:16.819 -> X, Y, Z  :: 43, 571, 442 :: -3G, 0G, -0G
20:20:17.028 -> X, Y, Z  :: 43, 584, 459 :: -3G, 0G, -0G
20:20:17.202 -> X, Y, Z  :: 43, 592, 505 :: -3G, 0G, -0G
20:20:17.442 -> X, Y, Z  :: 43, 588, 550 :: -3G, 0G, 0G
20:20:17.651 -> X, Y, Z  :: 43, 556, 552 :: -3G, 0G, 0G
20:20:17.858 -> X, Y, Z  :: 44, 561, 559 :: -3G, 0G, 0G
20:20:18.066 -> X, Y, Z  :: 43, 551, 566 :: -3G, 0G, 0G
20:20:18.274 -> X, Y, Z  :: 44, 545, 574 :: -3G, 0G, 0G
20:20:18.481 -> X, Y, Z  :: 44, 533, 570 :: -3G, 0G, 0G
20:20:18.690 -> X, Y, Z  :: 44, 538, 583 :: -3G, 0G, 0G
20:20:18.898 -> X, Y, Z  :: 44, 537, 568 :: -3G, 0G, 0G
20:20:19.105 -> X, Y, Z  :: 44, 503, 541 :: -3G, -0G, 0G
20:20:19.310 -> X, Y, Z  :: 44, 552, 545 :: -3G, 0G, 0G
20:20:19.519 -> X, Y, Z  :: 44, 560, 570 :: -3G, 0G, 0G
20:20:19.728 -> X, Y, Z  :: 44, 567, 571 :: -3G, 0G, 0G
20:20:19.935 -> X, Y, Z  :: 45, 548, 565 :: -3G, 0G, 0G
20:20:20.145 -> X, Y, Z  :: 45, 539, 576 :: -3G, 0G, 0G
20:20:20.353 -> X, Y, Z  :: 45, 528, 572 :: -3G, 0G, 0G
20:20:20.562 -> X, Y, Z  :: 45, 520, 580 :: -3G, 0G, 0G
20:20:20.769 -> X, Y, Z  :: 45, 505, 581 :: -3G, -0G, 0G
20:20:20.976 -> X, Y, Z  :: 45, 496, 580 :: -3G, -0G, 0G
20:20:21.184 -> X, Y, Z  :: 45, 494, 577 :: -3G, -0G, 0G
20:20:21.391 -> X, Y, Z  :: 45, 497, 578 :: -3G, -0G, 0G
20:20:21.601 -> X, Y, Z  :: 45, 497, 580 :: -3G, -0G, 0G
20:20:21.807 -> X, Y, Z  :: 46, 496, 580 :: -3G, -0G, 0G
20:20:22.017 -> X, Y, Z  :: 46, 497, 577 :: -3G, -0G, 0G
20:20:22.223 -> X, Y, Z  :: 46, 495, 579 :: -3G, -0G, 0G
20:20:22.431 -> X, Y, Z  :: 46, 496, 579 :: -3G, -0G, 0G
20:20:22.637 -> X, Y, Z  :: 46, 499, 578 :: -3G, -0G, 0G
20:20:22.846 -> X, Y, Z  :: 46, 502, 578 :: -3G, -0G, 0G
20:20:23.051 -> X, Y, Z  :: 46, 502, 579 :: -3G, -0G, 0G
20:20:23.259 -> X, Y, Z  :: 46, 530, 591 :: -3G, 0G, 0G
20:20:23.467 -> X, Y, Z  :: 46, 573, 558 :: -3G, 0G, 0G
20:20:23.674 -> X, Y, Z  :: 46, 599, 499 :: -3G, 1G, -0G
20:20:23.880 -> X, Y, Z  :: 47, 585, 436 :: -3G, 0G, -0G
20:20:24.088 -> X, Y, Z  :: 47, 537, 395 :: -3G, 0G, -1G
20:20:24.296 -> X, Y, Z  :: 47, 491, 403 :: -3G, -0G, -1G
20:20:24.502 -> X, Y, Z  :: 47, 385, 465 :: -3G, -1G, -0G
20:20:24.711 -> X, Y, Z  :: 47, 392, 510 :: -3G, -1G, -0G
20:20:24.916 -> X, Y, Z  :: 47, 425, 492 :: -3G, -1G, -0G
20:20:25.122 -> X, Y, Z  :: 47, 391, 529 :: -3G, -1G, 0G
20:20:25.329 -> X, Y, Z  :: 47, 433, 477 :: -3G, -0G, -0G
20:20:25.537 -> X, Y, Z  :: 47, 461, 408 :: -3G, -0G, -1G
20:20:25.745 -> X, Y, Z  :: 48, 512, 370 :: -3G, 0G, -1G
20:20:25.951 -> X, Y, Z  :: 48, 504, 392 :: -3G, -0G, -1G
20:20:26.158 -> X, Y, Z  :: 48, 521, 390 :: -3G, 0G, -1G
20:20:26.365 -> X, Y, Z  :: 48, 519, 388 :: -3G, 0G, -1G
20:20:26.573 -> X, Y, Z  :: 48, 516, 389 :: -3G, 0G, -1G
20:20:26.782 -> X, Y, Z  :: 48, 521, 388 :: -3G, 0G, -1G
20:20:26.987 -> X, Y, Z  :: 48, 516, 386 :: -3G, 0G, -1G
20:20:27.230 -> X, Y, Z  :: 48, 521, 387 :: -3G, 0G, -1G
20:20:27.436 -> X, Y, Z  :: 48, 503, 388 :: -3G, -0G, -1G
20:20:27.643 -> X, Y, Z  :: 48, 512, 379 :: -3G, 0G, -1G
20:20:27.852 -> X, Y, Z  :: 48, 481, 388 :: -3G, -0G, -1G
20:20:28.058 -> X, Y, Z  :: 48, 504, 391 :: -3G, -0G, -1G
20:20:28.263 -> X, Y, Z  :: 48, 481, 397 :: -3G, -0G, -1G
20:20:28.471 -> X, Y, Z  :: 48, 449, 425 :: -3G, -0G, -1G
20:20:28.678 -> X, Y, Z  :: 49, 422, 460 :: -3G, -1G, -0G
20:20:28.882 -> X, Y, Z  :: 49, 406, 480 :: -3G, -1G, -0G
20:20:29.088 -> X, Y, Z  :: 49, 416, 477 :: -3G, -1G, -0G
20:20:29.295 -> X, Y, Z  :: 49, 394, 486 :: -3G, -1G, -0G
20:20:29.502 -> X, Y, Z  :: 49, 435, 456 :: -3G, -0G, -0G
20:20:29.709 -> X, Y, Z  :: 49, 395, 452 :: -3G, -1G, -0G
20:20:29.917 -> X, Y, Z  :: 49, 423, 477 :: -3G, -1G, -0G
20:20:30.125 -> X, Y, Z  :: 49, 407, 476 :: -3G, -1G, -0G
20:20:30.332 -> X, Y, Z  :: 49, 401, 488 :: -3G, -1G, -0G
20:20:30.540 -> X, Y, Z  :: 49, 429, 476 :: -3G, -0G, -0G
20:20:30.747 -> X, Y, Z  :: 50, 413, 481 :: -3G, -1G, -0G
20:20:30.954 -> X, Y, Z  :: 50, 406, 477 :: -3G, -1G, -0G
20:20:31.161 -> X, Y, Z  :: 50, 410, 481 :: -3G, -1G, -0G
20:20:31.369 -> X, Y, Z  :: 50, 400, 480 :: -3G, -1G, -0G
20:20:31.579 -> X, Y, Z  :: 50, 415, 484 :: -3G, -1G, -0G
20:20:31.787 -> X, Y, Z  :: 50, 410, 486 :: -3G, -1G, -0G
20:20:31.993 -> X, Y, Z  :: 50, 400, 486 :: -3G, -1G, -0G
20:20:32.201 -> X, Y, Z  :: 50, 419, 483 :: -3G, -1G, -0G
 


https://lastminuteengineers.com/adxl335-accelerometer-arduino-tutorial/

so i've sat down with the older adxl, and tested the code from the link with it an it seems to work on y and z axis.... x axis seems teribbly broken ... somehow it ccontinues to go up over the whole runthrough and doesn't react to tilting, meanwhile the y and z working perfect.... any idea what could cause my problem?

jremington

#7
Apr 27, 2019, 05:46 am Last Edit: Apr 28, 2019, 05:13 am by jremington
Quote
any idea what could cause my problem?
Did you fix the errors in the code mentioned in reply #5?

Did you study the guide linked in reply #5?

If so, post the revised code, using code tags, and the output it produces for Z up and down, X up and down, Y up and down.

Go Up