Things used in this project

Hardware components:
Ard yun
Arduino Yun
×1
Parallax MEMSIC 2125 Dual-axis Accelerometer
×1
Amazon echo dot
Amazon Alexa Echo Dot
×1
Adafruit industries ada64 image 75px
Solderless Breadboard Half Size
I prefer red
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
11026 02
Jumper wires (generic)
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
09590 01
LED (generic)
Again, I prefer red
×1
Software apps and online services:
Ide web
Arduino IDE
Gawd2jnp51w1h1ccsulo
IFTTT Amazon Alexa service
Avs med 3 22
Amazon Alexa Alexa Voice Service
Cayenne logo hi
myDevices Cayenne

Schematics

Dryer Alert wiring
Hook up a MEMSIC 2125 accelerometer to Arduino Yun
dryeralert_iXYp1QGHwW.fz

Code

Dryer Alert Arduino CodeArduino
Work-in-progress; The code uses Cayenne to send SMS when the dryer shuts off. Need to convert that to an Echo notification (pending).
// Include statements:
#include <Bridge.h>

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneYun.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxxxxxxxxxxxx";

// Adjust these to meet your needs
const int buttonPin = 2;            // pin number of the pushbutton
const int xPin = 3;                 // pin number of the X output of the accelerometer
const int yPin = 4;                 // pin number of the Y output of the accelerometer
const int ledPin = 13;              // pin number of the LED
const int waitTime = .1;            // wait time in minutes
const float sensitivityX = 0.002;   // sensitivity of X axis in percent change
const float sensitivityY = 0.002;   // sensitivity of Y axis in percent change

// Variables:
boolean lastButtonState = LOW;
boolean currentButtonState = LOW;
boolean ledState = LOW;
int counter = 0;
float lastPulseX = 0;
float lastPulseY = 0;

// Variables to contain the resulting accelerations
  int accelerationX, accelerationY;

// Initial setup
void setup() {
  // Initialize serial communications:
  Serial.begin(9600);
  
  // Initiate Cayenne communications
  Cayenne.begin(token);
  
  // Initialize the pins:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  
  Bridge.begin();
}

// Debounce function for the pushbutton
boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if(last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}

// Main loop
void loop()
{
  Cayenne.run();
  delay (5);
     
  // Set the LED
  currentButtonState = debounce(lastButtonState);
  if(lastButtonState == LOW && currentButtonState == HIGH)
  {
    ledState = !ledState;
  }
  lastButtonState = currentButtonState;
  digitalWrite(ledPin, ledState);
  
  // If the led is on
  if (ledState == HIGH)
  { 
    // If the counter is less than the wait time.
    // I multiplied the waitTime by 3000 to account for timing.
    // You may need to adjust this value to get more accurate timing.
    // if (counter < (waitTime * 3000))
    if (counter < (10))  // For testing only
    {
     
      // Declare variables to read the pulse widths, change, and percentage change:
      float pulseX, pulseY, changeX, changeY, percentX, percentY;
    
      // Read pulse from x- and y-axes:
      pulseX = pulseIn(xPin,HIGH);  
      pulseY = pulseIn(yPin,HIGH);
      
      // Convert the pulse width into acceleration
      // accelerationX and accelerationY are in milli-g's:
      // Earth's gravity is 1000 milli-g's, or 1g.
      accelerationX = abs((pulseX / 10) - 500) * 8;
      accelerationY = abs((pulseY / 10) - 500) * 8;
      // print the acceleration
      Serial.print(accelerationX);
      // print a tab character:
      Serial.print("\t");
      Serial.print(accelerationY);
      Serial.println();    
          
      // Find the change in the pulse:
      changeX = lastPulseX - pulseX;
      changeY = lastPulseY - pulseY;
    
      // Calculate the percentage change using absolute values:
      percentX = abs(changeX / lastPulseX);
      percentY = abs(changeY / lastPulseY);
    
      // If the percentage change is less than the sensitivity (i.e. no movement detected)
      if (percentX < sensitivityX && percentY < sensitivityY)
      {      
        // Increase the counter
        counter++;
      }
      // Else if movement is detected
      else
      { 
        // Reset the counter
        counter = 0;
      }

      // Print the counter
      Serial.print(counter);
      Serial.println(); 
      delay(1000);
          
      // Set the last pulse equal to the current pulse
      lastPulseX = pulseX;
      lastPulseY = pulseY;
    }
    else
    {
      // Reset the counter
      // Comment out to end the loop
      counter = 0;
      ledState = LOW;
    }
    //  Serial.print("Life is good.");
    //  Serial.println(); 
    // Serial.end();
    //ledState = LOW;
  }
}

Credits

Rhino 8lcnifj5c2
tnunnster
2 projects • 4 followers
IT Project Manager by day, novice tinkerer by night. Very appreciative of the community and the open network of project ideas.
Contact
Thanks to MakerBee.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog