Hi Guys,
I am trying to develop a way to verify the amplitude/frequency that the Lilypad Vibe Board is vibrating at using a ADXL335 accelerometer on the Lilypad accelerometer.
So far this is what my code cooks like:
// these constants describe the pins. They won't change:
const int xpin = A1; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis (only on 3-axis models)
int vibe = 8; //motor connected to PWM 8
int sampleDelay = 500; //number of milliseconds between readings
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
pinMode(vibe, OUTPUT); //sets the digital pin as output
//Make sure the analog-to-digital converter takes its reference voltage from
// the AREF pin
analogReference(EXTERNAL);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void loop()
{
analogWrite(vibe,0); //set value of motor PWM from 0-255
int x = analogRead(xpin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int y = analogRead(ypin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int z = analogRead(zpin);
//zero_G is the reading we expect from the sensor when it detects
//no acceleration. Subtract this value from the sensor reading to
//get a shifted sensor reading.
float zero_G = 512.0;
//scale is the number of units we expect the sensor reading to
//change when the acceleration along an axis changes by 1G.
//Divide the shifted sensor reading by scale to get acceleration in Gs.
float scale = 102.3;
Serial.print("x val: ");
Serial.print(((float)x - zero_G)/scale);
Serial.print("\t");
Serial.print("y val: ");
Serial.print(((float)y - zero_G)/scale);
Serial.print("\t");
Serial.print("z val: ");
Serial.print((((float)z - zero_G)/scale)-1);
Serial.print("\n");
// delay before next reading:
delay(sampleDelay);
}
My question is I know that the vibe board's motor specs gives a normalized vibration amplitude of 1.4G, so whats a feasible method for measuring this using the accelerometer itself? When I placed it flat on top of the motor, I noticed slight changes in the Y and Z axis but didn't see anything close to the spec sheets.
Your help is deeply appreciated!!!