Hi, I have seen a couple of the Accelerometer tuts, and more or less this is what I am using as my based to get going.
I have only modified it to suit my accelerometer and add output for serial monitoring the values.
I have my accelerometer mounted on a ‘tube’ on PVC… to mimic its final ‘mounting’ orientation and use.
with some wire/cable going to my Arduino Duemilanove per the circuit outline in the sketch comments:
/*
Accelerometer: DE-ACCM3D [Buffered 3D Accelerometer]
http://www.dimensionengineering.com/DE-ACCM3D.htm
Original code:
http://www.arduino.cc/en/Tutorial/ADXL3xx
Created: 07.02.08
(by David A. Mellis)
Modified 06.13.10
(by Jerry Dugan)
The circuit:
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
This example code is in the public domain.
*/
// these constants describe the pins. They won't change:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = 3; // x-axis of the accelerometer
const int ypin = 2; // y-axis
const int zpin = 1; // z-axis (only on 3-axis models)
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// play tone when ready
tone(8, 350, 250);
// 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.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
// print the sensor values:
Serial.print("X: ");
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print("Y: ");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print("Z: ");
Serial.print(analogRead(zpin));
// print a axis value totals:
Serial.print("\t");
Serial.print(analogRead(xpin) + analogRead(ypin) + analogRead(zpin));
unsigned int total = (analogRead(xpin) + analogRead(ypin) + analogRead(zpin));
Serial.print("------>");
Serial.print(total);
if (total < 1000){
tone(8, 550, 250);
}
Serial.println();
// delay before next reading:
delay(100);
}
Im a little unsure as to the what the original author meant by this section/comments:
// 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.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
I have:
Accelerometer PWR to Analog pin5
Accelerometer GND to Analog pin4
Accelerometer X axis to Analog pin3
Accelerometer Y axis to Analog pin2
Accelerometer Z axis to Analog pin1
my GOAL is two-fold… I want to be able to ‘track’ whenever the ‘sword’ (accelerometer) is being swung at a relatively decent speed, and then of course execute an event/function… (later I might add multi swing/force checking, but for now 1 ‘threshold’ is enough to get going)
secondly… I’d like to learn/figure out how to detect an abrupt stop like you swung and hit something
I hope I havent lost anyone… just trying to give a decent background for communication purposes.
onto my ‘results’ and the best way to handle this.
the values of any given axis is around 340-360 (when output to the serial monitor in the Arduino IDE) and of course one value/axis of the 3 will be around 470-490… which 'higher valued ‘axis’ depends on the orientation/mounting of the board.
more or less after just a plain totaling of the axis values… anything under ‘around’ 1000 verified as a swing/movement…swinging harder gave me lower a total…
I however do not feel this is the most accurate way of doing it since the orientation will not be known (think swordplay/fighting…etc)
and the orientation and way it might be held…etc… but swing in any direction needs to trigger event/function…and then Id like to take it one step closer to detecting an abrupt stop or ‘hit’ event.
Id imaging Id need to write some sort of ‘timer’ watchdog to check an sudden increase/decrease in force in ‘under’ a certain ms time frame?
ie:
value of swing is 900 something… if it that value reaches say 100 in under a certain milisecond threshold consider it a hit/abrupt stop event?
Anyone with some input chime in… all comments (positive) are appreciated.
Thanks