Accelerometer Values

I have an accelerometer from sparkfun and an Arduino UNO. the accelerometer part number is this: SEN-00252
I have it connected to analog input pins and Vcc and GND correctly, and I have chosen to use the 1.5G so I have GS1 and Gs2 connected to ground.
Every time I re-upload the program the values printed on the serial screen are vastly different ranging from 20s to 300s. I need this value to stay constant as I need to run motors off certain values.
Can anyone help me with getting these values constant?

Thanks!

The catalog says that it's a 3.3v part. Are you hooking Vcc to the 3.3v source on the Arduino?

If i understand correctly you should expect values from 0 to about 450 depending on tilt. You can get more resolution by connecting 3.3v to the AREF pin and selecting analogReference(EXTERNAL).

You mean this one...

The MMA7260Q

It is discontinued -- but all the data sheets are there...

Why don't you post your code... And tell us what is hooked where. Which Arduino are you using? Does it have 3.3v -- if not did you create a source. Are you using AREF...

There will probably be about 10 points of swing about the "nominal" values.

...and if you looked through the forum you would see a thread about this exact device -- similar to ADXL335 --- except for G-Rating in terms of reading it.

...Plus the V022 compiler has several examples of reading sensors and averaging values etc.

hey I'm having similar problems, im using a 3.3V pro mini and Pololu - MMA7260QT 3-Axis Accelerometer ±1.5/2/4/6g

my ranges are running pretty wild and its the data isn't really consistant or showing the ranges very much.

this is the code im using

/*
 ADXL3xx
 
 Reads an Analog Devices ADXL3xx accelerometer and communicates the
 acceleration to the computer.  The pins used are designed to be easily
 compatible with the breakout boards from Sparkfun, available from:
 http://www.sparkfun.com/commerce/categories.php?c=80

 http://www.arduino.cc/en/Tutorial/ADXL3xx

 The circuit:
 analog 0: accelerometer self test
 analog 1: z-axis
 analog 2: y-axis
 analog 3: x-axis
 analog 4: ground
 analog 5: vcc
 
 created 2 Jul 2008
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe 
 
 This example code is in the public domain.

*/

// these constants describe the pins. They won't change:
const int groundpin = 2;             // analog input pin 4 -- ground
const int powerpin = 4;              // analog input pin 5 -- voltage
const int zpin = A2;                  // z-axis of the accelerometer
const int ypin = A1;                  // y-axis
const int xpin = A0;                  // x-axis (only on 3-axis models)

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
  
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.

}

void loop()
{
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(ypin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(zpin));
  Serial.println();
  // delay before next reading:
  delay(100);
}

List some of your data as well. The some of us who use them can comment.

I also suggest that you might want to hook directly to +V (3.3V) and Ground on the Arduino as appropriate to test.

Some reading below are from and Ethernet/UDP collection system I sue to place sensors and Arduino and Make controllers remotely. All the extra fluff in the readings is so that I can determine the "drop rate" of the packets, and whether or not data is out of order. If so I re-sort it. The Make does not allow me to attache a sequence number at the controller as I am using the built in OSC. The arduino lets me attache system time and the Millis() count.

Below is the output from a BMA180 on Sensors 0,1,2 ans MA7361L is on Sensors 3,4,5.

You are looking for the values that look like this -- the sensor no, and the data value. The BMA180 swings around the 0 point -- positive and negative, while the MA7361L swings about the 512 reading for X and Y and about 680 for the Z sensor (It's detecting 1G) ...and no the sensor is not exactly level.

Sensor: 0, Val: -34

Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 0, Val: -34 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 1, Val: -272 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 2, Val: 5946 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 3, Val: 499 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 4, Val: 529 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1348 Time: 10:48:29 PM Bytes( 64 ) Sensor: 5, Val: 685 Seconds: 82109.346000175 Tick... 25363 ArdTime... 1300484890 Remote ID: 2878
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 0, Val: -26 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 1, Val: -191 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 2, Val: 6014 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 3, Val: 499 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 4, Val: 528 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1349 Time: 10:48:29 PM Bytes( 64 ) Sensor: 5, Val: 682 Seconds: 82109.3619997613 Tick... 25376 ArdTime... 1300484890 Remote ID: 2880
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 0, Val: -71 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 1, Val: -289 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 2, Val: 6040 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 3, Val: 496 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 4, Val: 538 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882
Seq. No: 1350 Time: 10:48:29 PM Bytes( 64 ) Sensor: 5, Val: 678 Seconds: 82109.3769998057 Tick... 25391 ArdTime... 1300484890 Remote ID: 2882

Here is another set of readings from a sensor in position to collect data -- as opposed to sitting on the bench.

They are labeled as 24,25 and 26 since I just transform them up from 4,5,6 on a make controller. I analyze the data by sets.

Seq. No: 2024 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   506  : /analogin/4/value Seconds from Midnight... 46824.3469998473
Seq. No: 2025 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   519  : /analogin/5/value Seconds from Midnight... 46824.3469998473
Seq. No: 2026 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   653  : /analogin/6/value Seconds from Midnight... 46824.3469998473
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2027 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   506  : /analogin/4/value Seconds from Midnight... 46824.3619998917
Seq. No: 2028 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   517  : /analogin/5/value Seconds from Midnight... 46824.3619998917
Seq. No: 2029 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   649  : /analogin/6/value Seconds from Midnight... 46824.3619998917
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2030 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   503  : /analogin/4/value Seconds from Midnight... 46824.3780001067
Seq. No: 2031 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   520  : /analogin/5/value Seconds from Midnight... 46824.3780001067
Seq. No: 2032 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   653  : /analogin/6/value Seconds from Midnight... 46824.3780001067
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2033 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   508  : /analogin/4/value Seconds from Midnight... 46824.393999693
Seq. No: 2034 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   516  : /analogin/5/value Seconds from Midnight... 46824.393999693
Seq. No: 2035 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   650  : /analogin/6/value Seconds from Midnight... 46824.393999693
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2036 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   505  : /analogin/4/value Seconds from Midnight... 46824.4089997374
Seq. No: 2037 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   520  : /analogin/5/value Seconds from Midnight... 46824.4089997374
Seq. No: 2038 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   650  : /analogin/6/value Seconds from Midnight... 46824.4089997374
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2039 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   499  : /analogin/4/value Seconds from Midnight... 46824.4249999523
Seq. No: 2040 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   516  : /analogin/5/value Seconds from Midnight... 46824.4249999523
Seq. No: 2041 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   652  : /analogin/6/value Seconds from Midnight... 46824.4249999523
   ...Bundle Checked: #bundle  Length: 112, No in Bundle: 3
Seq. No: 2042 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 24   500  : /analogin/4/value Seconds from Midnight... 46824.4399999967
Seq. No: 2043 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 25   522  : /analogin/5/value Seconds from Midnight... 46824.4399999967
Seq. No: 2044 Time: 1:00:24 PM Received 28 Bytes:   Sensor :> 26   651  : /analogin/6/value Seconds from Midnight... 46824.4399999967

Hello,

I have tried both connecting +3.3V to the AREF... as well as using the 3.3 source itself.

I read the other topic using this accelerometer last night and it helped quite a bit.

I have now been able to continuously get values around 690 for X and Y. I am actually only using these two for this project. The values are changing a little bit by 1 or 2 but I assume this is due to the fact I have the accelerometer near my laptop.

I have the 3.3 from the Arduino Uno connected to the accelerometer. and nothing connected to the AREF pin. I am also using the 1.5G option for the accelerometer.

For a little background information on what I am trying to accomplish with this is get accelerometer values as well as using a gyroscope attached to a formula 1 car and according to certain values from the sensors linear actuators will either extend or retract moving the airfoil optimizing down force.

Now that I have the accelerometer working I was just wondering if I could compare the current accelerometer value to the last one. So if the value changed by say 20-50 send a signal to one actuator to move the airfoil.

Here is the code I have so far.

int pinI1=2; // define I1 port
int pinI2=3; //define I2 port
int EnableA=5; //define EA (PWN speed regulation) port

int pinI3=4; // define I1 port
int pinI4=7; //define I2 port
int EnableB=6; //define EA (PWN speed regulation) port


float x, y;
float Ax,Ay;
 

void setup()
{
  Serial.begin(9600); 
  pinMode(pinI1,OUTPUT); //define port as output
  pinMode(pinI2,OUTPUT);
  pinMode(EnableA,OUTPUT);
  pinMode(pinI3,OUTPUT); //define port as output
  pinMode(pinI4,OUTPUT);
  pinMode(EnableB,OUTPUT);
}

void loop()
{

  x = (analogRead(0));
      Serial.println(x);
      Serial.print("\t");
  y = (analogRead(1));
      Serial.println(y);
      delay(1500);

  if (x > 6)    //this is to test if the motor turns on correctly
      {
          analogWrite(EnableA,100);
          digitalWrite(pinI1,LOW); //DC motor rotates clockwise
          digitalWrite(pinI2,HIGH);
      }
}

These are the values I get after leaving the accelerometer still for quite a bit using the code I just posted

697.00
	699.00
695.00
	698.00
694.00
	696.00
694.00
	695.00
694.00
	695.00
693.00
	695.00
693.00
	694.00
693.00
	694.00
697.00
	694.00
697.00
	693.00
694.00
	693.00

May I suggest....

void loop()
{

  x = (analogRead(0));
      Serial.Print("X:  "); // label the axis
      Serial.print(x);       // print the value
      Serial.print("\t");    // now do a tab

  y = (analogRead(1));
      Serial.Print("Y:  ");
      Serial.print(y);
     Serial.println();       // now do a newline...

      delay(1000);

Just aesthetics....

You probably need to speed up the readings and do a moving average. The size of the sample for the moving average is a bit of an art. You need to know something about the response of the SYSTEM.

Too small a group for the moving average and the response will be jerky -- too many samples and the unit will lack responsiveness.

The Version 22 samples do have an example of that... the moving average

...otherwise -- you will have the unit thrashing about like crazy!

As you could see from my readings and yours -- you do get some noise. You must account for that. The noise tells you nothing. You are looking for a signal -- i.e. deviation from the noise level.

Welcome to the world of engineering where noise and error analysis matters!

Then you will understand SNR -- Signal to Noise Ratio.

I have no idea what is appropriate for your circumstance. You can do trial and error. Run your servos for example -- make one turn at a rate you need to calibrate -- then determine the amount of signal and the Slew Rate (how fast it changes and the slope -- or rate of change... same thing..) When you make the motor move the device that is...

But I do think you have the idea...

If the sensor is flat and level they should read about the same. If you stand it on edge it should vary by one G... as you rotate it it should flip to the other axis off by one G....

x = (analogRead(0));

Just aesthetics....

Just wasted parentheses...

AWOL:

x = (analogRead(0));

Just aesthetics....

Just wasted parentheses...

Aye. Thanks. :roll_eyes: