Calculating G Force.

Hello,

I have a arduino connected to a MMA7260Q accelerometer. I need to calculate the current g force acting on the accelerometer at any time. I have found that at 1g the accelerometer gives a output on 2 volts and at 0g it gives a out out of 1.7volts. I know this is correct because I have the accelerometer set to 300mv/g.

But when I try to map the value i cannot get the correct g force output.

Does anyone know a way of doing this?

Thanks for any help!

Telly

I can't see your code.

// include the library code:
#include <LiquidCrystal.h>
#define pinx 0
#define piny 1
#define pinz 2

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float valx;
float valy;
float valz;

void setup() {
  
  lcd.begin(20, 4);                   //Set up the LCD's number of columns and rows
  Serial.begin(9600);                 //Begin sending serial data back to the connected PC
  
}

void loop() {  

  // Z Axis
  lcd.setCursor(8,2);
  lcd.print("Z=");
  valz = analogRead(pinz);
  Serial.print(map(valz), 0, 1023, 0, 255),DEC);
  lcd.print(map(valz), 0, 1023, 0, 255),DEC);

  delay (100);                        //Loop every 1/10th second
  lcd.clear();                        //Clear LCD before next write
  
}

Just testing on the Z at the moment.

But when I try to map the value i cannot get the correct g force output

Does that code even compile?

Sorry my bad I made a change and did not test it!

// include the library code:
#include <LiquidCrystal.h>

#define pinz 2

float valz;

void setup() {
  
Serial.begin(9600);                 //Begin sending serial data back to the connected PC
  
}

void loop() {  

  // Z Axis
  valz = analogRead(pinz);
  Serial.print(map (valz, 0, 1023, 0, 255),DEC);

  delay (100);                        //Loop every 1/10th second
  
}

All that does is divide the input range by 4.
You need to make the output range signed, and offset it.