need whole code to determine the position of adxl337+arduino uno

Hey there!

I need some help to implement adxl337 accelerometer+arduino uno to get the position by double integrate the acceleration data.

so can i get help with the whole code please!

so can i get help with the whole code please!

It is more normal here for posters to post the code that they want advice with. Have you got any ? What is your experience with Arduino and C++ ?

Is this an assignment or a real project. Details please.

Make sure that you read the 2 posts by Nick Gammon at the top of this forum giving advice on how to pose a programming question.

Hey!

Honestly, It's the first time with Arduino and C++..but I have gotten the code for acceleration data but i dont know really if this is correct or not! :(

Here is the code:

// Make sure these two variables are correct for your setup int scale = 3; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377 boolean micro_is_5V = true; // Set to true if using a 5V microcontroller such as the Arduino Uno, false if using a 3.3V microcontroller, this affects the interpretation of the sensor data

void setup() { // Initialize serial communication at 115200 baud Serial.begin(115200); }

// Read, scale, and print accelerometer data void loop() { // Get raw accelerometer data for each axis int rawX = analogRead(A0); int rawY = analogRead(A1); int rawZ = analogRead(A2);

// Scale accelerometer ADC readings into common units // Scale map depends on if using a 5V or 3.3V microcontroller float scaledX, scaledY, scaledZ; // Scaled values for each axis if (micro_is_5V) // Microcontroller runs off 5V { scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675 scaledY = mapf(rawY, 0, 675, -scale, scale); scaledZ = mapf(rawZ, 0, 675, -scale, scale); } else // Microcontroller runs off 3.3V { scaledX = mapf(rawX, 0, 1023, -scale, scale); scaledY = mapf(rawY, 0, 1023, -scale, scale); scaledZ = mapf(rawZ, 0, 1023, -scale, scale); }

// Print out raw X,Y,Z accelerometer readings Serial.print("X: "); Serial.println(rawX); Serial.print("Y: "); Serial.println(rawY); Serial.print("Z: "); Serial.println(rawZ); Serial.println();

// Print out scaled X,Y,Z accelerometer readings Serial.print("X: "); Serial.print(scaledX); Serial.println(" g"); Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g"); Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g"); Serial.println();

delay(2000); // Minimum delay of 2 milliseconds between sensor reads (500 Hz) }

// Same functionality as Arduino's standard map function, except using floats float mapf(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }

it's a Project. so I need the correct code to determine the position please, its important

best wishes

please anyone help me!

i forget to attach the result that i got when i used the code which is mentioned above.
now is attached

Hey there!

I need some help to implement adxl337 accelerometer+arduino uno to get the position by double integrate the acceleration data.
so can i get help with the whole code please!

Honestly, It’s the first time with Arduino and C++…but I have gotten the code for acceleration data but i dont know really if this is correct or not! :frowning:

Here is the code:

// Make sure these two variables are correct for your setup
int scale = 3; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
boolean micro_is_5V = true; // Set to true if using a 5V microcontroller such as the Arduino Uno, false if using a 3.3V microcontroller, this affects the interpretation of the sensor data

void setup()
{
  // Initialize serial communication at 115200 baud
  Serial.begin(115200);
}

// Read, scale, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  int rawX = analogRead(A0);
  int rawY = analogRead(A1);
  int rawZ = analogRead(A2);
  
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledX, scaledY, scaledZ; // Scaled values for each axis
  if (micro_is_5V) // Microcontroller runs off 5V
  {
    scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
    scaledY = mapf(rawY, 0, 675, -scale, scale);
    scaledZ = mapf(rawZ, 0, 675, -scale, scale);
  }
  else // Microcontroller runs off 3.3V
  {
    scaledX = mapf(rawX, 0, 1023, -scale, scale);
    scaledY = mapf(rawY, 0, 1023, -scale, scale);
    scaledZ = mapf(rawZ, 0, 1023, -scale, scale);
  }
  
  // Print out raw X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.println(rawX);
  Serial.print("Y: "); Serial.println(rawY);
  Serial.print("Z: "); Serial.println(rawZ);
  Serial.println();
  
  // Print out scaled X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
  Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g");
  Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g");
  Serial.println();
  
  delay(2000); // Minimum delay of 2 milliseconds between sensor reads (500 Hz)
}

// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

the result of this code is attached!

please anyone help me!

Best wishes

Hi, [ON SOAPBOX] Sorry..

yeah, it's a real Project, i have a master thesis in Lund univeristy..so I need the correct code to determine the position please, its important

What subject? By this stage you should have programming in C++ mastered. And how to do numeric integration in C++.

If you are at University, USE IT, the resources have to be available to you there. Especially mathematical resources to show you how to do integration.

Showing your tutors/lecturers that you are asking questions about your project, ON CAMPUS, rather than suddenly turn up with a sketch that does the job, will look Sooooo much better.. [OFF SOAPBOX] Tom..... :) PS Be a pain in the rear (could have used another word here :o ) to your lecturers/tutors and ask questions.

ok, thanks for the advice but i have done this already and i showed the code and the result to my tutor and he said that i need to get/determine the position..

Honestly i'm not proffesional in programming. And especially in Arduino and C++. I need only the sentences for the double integration i just want to see the way. So if you have it or not i will say thank u in both case.

best wishes ;)

The output voltages of the ADXL337 when there is no acceleration are roughly 1.5V. The sensitivity is roughly 300mV/g (these figures are for 3.0V supply voltage).

See the datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL337.pdf

You will need to calibrate each axis of your accelerometer for zero 'g' bias level and sensitivity.

Crosspost - see here

Please do not post in more than one thread. It can waste the time of forum members.

See: http://forum.arduino.cc/index.php?topic=357347.0

For several reasons it is not possible to estimate position from consumer grade accelerometer measurements, for more than a brief period of time. See this explanation for the details.

thank you guys for all your helps :)

But have anyone a code to this accelerometer to determine the position i just want to see how it does activate with the motion.

Best Wishes

It would be easier for you to just watch this video.

@cecilia90, please do not cross-post. Threads merged.