/* "Laundrino" by joergeli http://arduino.joergeli.de "Laundry is ready"-, respectively "washing machine has finished"-sketch Sketch compiled with Arduino-IDE 1.6.8 Sketch is listening to vibrations of washer with MPU6050 accelerometer and if there is no motion anymore (set by variable "offTime"), flash WaschOff-LED, turn on a relais, trigger a wireless remote doorbell, or whatever ... In my case, I trigger a remote doorbell sender "Grundig QH831-A" (433MHz) via WaschOff-output and the remote doorbell receiver "Grundig QH-822AC" sounds every "repat"-seconds until circuit is powered off. */ #include "I2Cdev.h" #include "MPU6050.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif MPU6050 accelgyro; int16_t ax, ay, az; // not used here, only for the sake of completeness int16_t gx, gy, gz; #define OUTPUT_READABLE_ACCELGYRO //________________ These variables are depending on your washer, just try and adjust them! _________________________ long offTime = 70000; // when there is no motion detected since offTime (here 70 seconds) -> trigger output long repeat = 20000; // repeat-time of flashing WaschOff-LED / trigger doorbell-sound (in ms) int gx_thres = 170; // threshold of x movement int gy_thres = 180; // threshold of y movement int gz_thres = 170; // threshold of z movement //______________________________________________________________________________________________________________ int LED_motionDetected=9; // LED lights up, when either LEDx, LEDy, or LEDz is on int LEDx=10; int LEDy=11; int LEDz=12; int WaschOff=4; // Output-LED, respectively trigger output-signal String sensor_x; String sensor_y; String sensor_z; long startTime; long duration = 0; void setup(){ pinMode(LED_motionDetected, OUTPUT); pinMode(LEDx, OUTPUT); pinMode(LEDy, OUTPUT); pinMode(LEDz, OUTPUT); pinMode(WaschOff, OUTPUT); digitalWrite(LED_motionDetected, LOW); digitalWrite(LEDx, LOW); digitalWrite(LEDy, LOW); digitalWrite(LEDz, LOW); digitalWrite(WaschOff, HIGH); // high, because my doorbell sender triggers on a falling edge from 3V to GND #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif Serial.begin(115200); Serial.println("Initializing I2C devices..."); accelgyro.initialize(); Serial.println("Testing device connections..."); Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // Normaly MPU6050 is factory calibrated, but I use my own (more precise?) calibration of the MPU6050 // You can use the sketch "MPU6050-Calibration.ino" to get the 6 calibration values, that I've added at my homepage for calibration accelgyro.setXAccelOffset(-4741); accelgyro.setYAccelOffset(-273); accelgyro.setZAccelOffset(581); accelgyro.setXGyroOffset(159); accelgyro.setYGyroOffset(-56); accelgyro.setZGyroOffset(99); delay(1000); Serial.println(F("running ...")); } void loop(){ if(duration < offTime){ // read raw accel/gyro measurements from device accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // turn on correspondigly LEDs, if motion detected // the threshold-values are depending on the vibration of your washer, just watch the x,y,z-LEDs if( gx > gx_thres || gx < -gx_thres){ digitalWrite(LEDx, HIGH); sensor_x = "x"; } if( gy > gy_thres || gy < -gy_thres){ digitalWrite(LEDy, HIGH); sensor_y = "y"; } if( gz > gz_thres || gz < -gz_thres){ digitalWrite(LEDz, HIGH); sensor_z = "z"; } // compare if any of the three sensors (gx,gy,gz) has movement detected if (digitalRead(LEDx) == HIGH || digitalRead(LEDy) == HIGH || digitalRead(LEDz) == HIGH) { digitalWrite(LED_motionDetected, HIGH); // turn on LED_motionDetected } if (digitalRead(LED_motionDetected) == HIGH){ Serial.print("Motion detected from sensor: "); Serial.print(sensor_x); Serial.print(" "); Serial.print(sensor_y); Serial.print(" "); Serial.println(sensor_z); startTime = millis(); // reset timer } duration = millis() - startTime; delay(20); // turn off all LEDs and reset sensor-variables digitalWrite(LEDx, LOW); digitalWrite(LEDy, LOW); digitalWrite(LEDz, LOW); digitalWrite(LED_motionDetected, LOW); sensor_x = ""; sensor_y = ""; sensor_z = ""; } // end of "if duration < offTime" // if washer has finished: flash WaschOff-LED, respectively trigger output-signal if(duration >= offTime){ Serial.println("Laundry is ready!"); digitalWrite(WaschOff, LOW); delay(300); digitalWrite(WaschOff, HIGH); delay(repeat); } } // end of loop