Pages: [1]   Go Down
Author Topic: 3 axis accelerometer to monitor dryer.  (Read 1194 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,  I want to know the best way to,  make code to run ONE  
Arduino,  ONE 3 AXIS ACCELERATION SENSOR MMA7660 module, and ONE LED.  

What I want the code to do is.  I want to put the
 3 axis mma7660 module on the clothes dryer in my home.  

The 3 axis mma7660 module will work with the Arduino.  

The Arduino will read the 3 axis mma7660 module
(shake or not shake).

Arduino would read the state of the 3 axis mma 7660 module from minute to minute.  Read state of 3 axis mma 7660 module,
then one minute would go by,  then read the state of the
3 axis mma 7660 module, and so on.  


If the dryer is running and shaking,  the led would be off.

If the dryer isn't running the led would be on.  

Is there some easy code that would do this.  



Code:
#include <Arduino.h>
#include <I2C.h>
#include <MMA7660.h>

MMA7660::MMA7660()
{
I2c.begin();
}

void MMA7660::init(){
//set mode to standy to set sample rate
write(MODE_REG, 0x00);
write(INTSU_REG, 0x00);
write(SR_REG, 0x00);  //120 samples and auto-sleep
write(MODE_REG, 0x01); //set mode to active
}

void MMA7660::setPowerMode(int mode){

}

void MMA7660::setSamples(int samples){

}

void MMA7660::enableTap(){
write(MODE_REG, 0x00);
write(INTSU_REG, 0x04); //turn on tap interrupt
write(SR_REG, 0x00);
write(PDET_REG, 0x86); //enable Z-AXIS tap and set threshold to 6 taps
write(PD_REG, 0x14); //set debounce filter to 21 measurements
write(MODE_REG, 0xC1);
//read(TILT_REG);
}

void MMA7660::enableShake(uint8_t axis){
write(MODE_REG, 0x00);
write(INTSU_REG, axis);
write(MODE_REG, 0xC1);
}

uint8_t MMA7660::readTilt(){
return read(TILT_REG);
}

int MMA7660::readAxis(uint8_t axis){
uint8_t data = 0x40;

//check if the alert bit is set, if so re-read
while(data & 0x40){
data = read(axis);
}

//if it's a negative value convert the two's complement
if(data & 0x20){
data += 0xC0; //the register returns a 6 bit number, fix for uint8_t
data = ~data;
data++;
return (int)data * -1;
}
return (int)data;
}

void MMA7660::write(uint8_t REG_ADDRESS, uint8_t DATA){
I2c.write((uint8_t)MMA7660_CTRL_ID,(uint8_t)REG_ADDRESS,(uint8_t)DATA);
}

uint8_t MMA7660::read(uint8_t REG_ADDRESS){
I2c.read((uint8_t)MMA7660_CTRL_ID, (uint8_t)REG_ADDRESS,(uint8_t) 0x01);
return I2c.receive();
}
 


Code:
#ifndef MMA7660_h
#define MMA7660_h

#include <Arduino.h>

#define MMA7660_CTRL_ID 0x4C
#define XOUT_REG 0x00
#define YOUT_REG 0x01
#define ZOUT_REG 0x02
#define TILT_REG 0x03
#define SRST_REG 0x04  //Sampling rate status
#define SPCNT_REG 0x05 //Sleep count
#define INTSU_REG 0x06 //Interrupt setup
#define MODE_REG 0x07
#define SR_REG 0x08    //Auto-wake/sleep and portrait/landscape filter
#define PDET_REG 0x09  //Tap detection
#define PD_REG 0x0A    //Tap debounce count
#define X_AXIS 0x00
#define Y_AXIS 0x01
#define Z_AXIS 0x02
#define X_SHAKE 0x80
#define Y_SHAKE 0x40
#define Z_SHAKE 0x20

// library interface description
class MMA7660
{
  // user-accessible "public" interface
public:
MMA7660();
void init();
void setPowerMode(int mode);
void setSamples(int samples);
void enableTap();
void enableShake(uint8_t axis);
uint8_t readTilt();
int readAxis(uint8_t axis);
uint8_t read(uint8_t REG_ADDRESS);

private:
void write(uint8_t REG_ADDRESS, uint8_t DATA);
};

#endif




Here is what I am shooting for


http://diy.viktak.com/2012/07/washing-machine-monitor.html?m=1

But with (ONE ARDUINO) (ONE 3 AXIS MM7660 MODULE) (ONE LED).                          
« Last Edit: January 10, 2013, 06:06:14 pm by Tricky12 » Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

this could b the structure of the code:

Code:
void setup() {
// setup sensor
// setup LED
}

void loop() {
// wait
// read sensor
// if there was movement --> turn the LED off
// if there was no movement --> turn the LED on
}

or what was ur question? smiley
Logged

-Arne

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



Hi

What I don't know how to do is,  program the code, that
will read the mma7660 module.  What I mean by that is.
How will the 3 axis sensor know when the dryer is
shaking or moving?   Because all I know how to do is make
the 3 axis read in degrees on x y and z.  (-/+). 
Is there A way to read the output of the 3 axis module.
If the module is sitting still,  there would be (0).  If the 3 axis was
moving,  there would be (100).   

if x y z > 10 led would be high
if x y z < 10 led would be low

This is the code I need help with.     
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

did u look at the readings when u shake it?
maybe u can c a characteristic pattern?
Logged

-Arne

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there A way to take the two programs and put them as one. 

The first code is the one that give's me data on the mma7660 3 axis accelerometer.  What I don't know how to
do is get more sensitivity out of the (mma7660 3 axis accelerometer).  Angles and Degree's can't read the dryer when it is
on and running.  I need to read the shaking, little movement and sensitivity of the dryer.  This is what the
(mma7660 3 axis accelerometer) should read as data.


Code:
#include <Wire.h>
#include <MMA7660.h>

void setup()
{
  Serial.begin(9600);
  MMA7660.init();
}

void loop()
{
  int x,y,z;
  delay(100); // There will be new values every 100ms
  MMA7660.getValues(&x,&y,&z);
  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" y: ");
  Serial.print(y);
  Serial.print(" z: ");
  Serial.println(z);



Code:
}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;

delay (60L * 1000L);   // wait 1 minute
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3643
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should be able to simplify this somewhat. Use your first program and compare the data when the drier is off and when it is running. Which axis shows the most difference? Keep a moving average of that axis and use it to tell you whether the LED is on or off. Alternatively, just use a current sensor to tell you how much power the device is pulling.
Logged

Pages: [1]   Go Up
Jump to: