ADXL335 Accelerometer to MATLAB through Arduino

7 visualizzazioni (ultimi 30 giorni)
I am working on a project of connecting an ADXL335 Accelerometer to an Arduino UNO then reading the data in Matlab. So far whenever a reading is done movement shows at about the same height on every axis. So if I move the accelerometer only in the y-axis where the same movement is seen on the z and x-axis. I am not sure what is wrong please help!! See code below
It is connected as follows: Analog Pin 1: Z Analog Pin 2: Y Analog Pin 3: X Analog Pin 4: Ground Analog Pin 5: Vin
This code is used along with the Arduino Package for Matlab: a = arduino('COM4')
a.pinMode(15,'input'); a.pinMode(16,'input'); a.pinMode(17,'input'); %%%% a.pinMode(18,'output'); a.pinMode(19,'output'); a.digitalWrite(18,0); a.digitalWrite(19,1); %%%%
xval = zeros(); yval = zeros(); zval = zeros();
for i = 1:500 zval(i) = a.analogRead(1); yval(i) = a.analogRead(2); xval(i) = a.analogRead(3);
subplot(3,1,1) plot(xval, 'b'); title('x');
subplot(3,1,2) plot(yval, 'r'); title('y');
subplot(3,1,3) plot(zval, 'g'); title('z'); pause(0.01); end

Risposte (1)

Dariusz Szalejko
Dariusz Szalejko il 5 Feb 2019
3D USB ACCELEROMETER ? https://bit.ly/2I35Vn4 ? ?easure ?cceleration ? in your PC / Raspberry Pi / Linux / Windows !! Use in ✔MATLAB ✔ Python or any other programming language!

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by