Go Down

Topic: 3 axis accelerometer to monitor. (Read 2932 times) previous topic - next topic


I want to use the best 3 axis accelerometer to monitor if A dryer or washer is on or off.  The data would be sent from the
accelerometer to an Arduino.  The Arduino would read the data minute from minute.  So if the Arduino read the data for 14 minute,  after the last minute the data was low the Arduino would turn on A led.

If the dryer is off the led would be off
If the dryer is on the led would be off
If the dryer is on and running for 10 minutes,  and after the last minute the dry turns off the led will turn on. 

Where is some Accelerometer I was looking at.

Memsic 2125 Dual-axis Accelerometer
ADXL335 - 5V ready triple-axis accelerometer
3 axis accelerometer - ADXL335


You don't need accurate acceleration measurement. So almost any accelerator would do.
I suggest a 3-axis accelerator.

An analog sensor is for example the MMA7361 or ADXL335. On Ebay the MMA7361 costs only 3 dollars and the ADXL335 only 4 dollars.
A sensor with I2C is more complicated. But if you already have used I2C, you might prefer that.

Most Arduino Board supply 3.3V. If you have a Arduino Uno or Arduino Leonardo, you can use 3.3V or 5V sensors.


So if I used the ADXL335 3-axis accelerator.  How do I make the code read the data of the x,y,and z. So the code, to run
the arduino,  would have to read the data from minute to minute.  The arduino code would have to read the accelerator data at rest (dryer off).  Then take the at rest data and compare to the moving data (dryer on),  from one minute to the next minute.  So the dryer would be running for 14 minute,  and if the dryer turns off in the last minute the led would turn on. 

Turn on Arduino,  read data x,y,and Z.
Next read data at rest.
One minute
Then compare data at rest to moving.
If at rest then turn on led.

Code: [Select]

//Analog read pins
const int xPin = 2;
const int yPin = 1;
const int zPin = 0;

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;

//to hold the caculated values
double x;
double y;
double z;

void setup(){

void loop(){

//read the analog values from the accelerometer
int xRead = analogRead(xPin);
int yRead = analogRead(yPin);
int zRead = analogRead(zPin);

//convert read values to degrees -90 to 90
int xAng = map(xRead, minVal, maxVal, -90, 90);
int yAng = map(yRead, minVal, maxVal, -90, 90);
int zAng = map(zRead, minVal, maxVal, -90, 90);

//Caculate 360deg values
x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);

//Output the caculations
Serial.print("x: ");
Serial.print(" | y: ");
Serial.print(" | z: ");

//just here to slow down the serial output - Easier to read


Here is what I am shooting for,  but with the Arduino.....

Here is the web...



Dec 01, 2012, 03:12 pm Last Edit: Dec 01, 2012, 03:36 pm by Krodal Reason: 1
What I would do is first to get the sensor connected, and print the analog values of the sensor.
Hold the sensor in different positions, and shake it to see what the values do.

You want to write a full program without having the sensor. That will be hard.

The way you want to read the angle doesn't seem right.
The shaking and vibration of the dryer causes higher values then the angle.
If the dryer is off, you are reading the angle.
There are many examples for an analog acceleration sensor and the Arduino.

My suggestion is to determine the shaking of the sensor. For example reading samples at 200 Hz (I think somewhere between 2 and 1000 Hz is good), and check only the difference with the previous values from the analog inputs. Convert the difference of the 3 axis to a single 'g'-force value.
Code: [Select]

// Just as an example, not tested.
static int old_x, old_y, old_z;
int new_x, new_y, new_z;
int delta_x, delta_y, delta_z;
double g;

new_x = analogRead(xPin);
new_y = analogRead(yPin);
new_z = analogRead(zPin);

delta_x = new_x - old_x;
delta_y = new_y - old_y;
delta_z = new_z - old_z;

g = sqrt ( sq(delta_x) + sq(delta_y) + sq(delta_x) );
g /= SENSITIVITY_VALUE;         // convert to real 'g' according to sensor sensitivity;

old_x = new_x;     // remember the value for the next sample
old_y = new_y;
old_z = new_z;

That value should be near zero if the dryer is off. If the dryer is on, you might get perhaps 0.5 to 3 'g' (just a guess).

Once you have that, you can use the average 'g'-force during 10 seconds or during 1 minute.

An other part is the delay and sequence. This can easily be programmed in the Arduino. You could add a button to simulate the washing machine, and test the delay.
The normal delay ( http://www.arduino.cc/en/Reference/delay ) is in milliseconds. So you could wait 1 minute like this:
Code: [Select]
delay (60L * 1000L);   // wait 1 minute
The 'L' is to indicate that it is a long integer.

Go Up