Note (Feb. 24, 2018) - The device has been update to include an Alexa Skill for Dryer Status response to "Are my clothes dry?". See Version 2.0 instructions below.
The laundry room in my townhouse is on the lower floor, and my hearing isn't what it used to be. So, I can't always hear the dryer alarm go off to announce the clothes are dry. Since I also don't like wrinkled clothes, I need to know the moment the dryer stops so I can hang things up.
So, I paired a Arduino Yun with an accelerometer and coded the Arduino to post status to a ThingSpeak channel. I added an Alexa Skill and Lambda function to enable "Alexa: Are my clothes dry?" inquiries that check the ThingSpeak channel dryer status and provide a voice response via Echo.
Lastly, the Arduino code includes integration with Cayenne myDevices to send an SMS alert when the dryer stops vibrating. (This will be updated to also use Alexa voice notifications when that feature becomes available to developers.) The device includes a button for the user to start the monitor (trigger an "on" notification) and an LED to visually indicate when the monitor is actively sensing vibration.
(See below for Version 2.0 addition of ThingSpeak and Alexa Skill.)
Step 1.1: Wiring the Accelerometer, Button, and LED
The Memsic 2125 accelerometer has 6 pins:
- X-axis Out; wired to Yun pin 3
- Y-axis Out; wired to Yun pin 4
- Ground for X-axis; wired to Yun GND
- Ground for Y-Axis; wire to Yun GND
- +5V; wired to Yun 5V
- T Out (temperature reading for measurement compensating; not used for this project)
The momentary button and 10K ohm resistor are connected to GND, 5V and Yun pin 2, as shown below.
The indicator LED is inserted directly into Yun pins 13 (anode, the long leg) and GND (cathode). (Note: A 220 ohm resistor can also be added in series with the LED anode to limit wear and tear on the LED.)
Power is supplied to the Yun via USB.
That's it!
Step 1.2: Cayenne myDevices Account
Visit the Cayenne myDevices site to create a free account and obtain an authentication token for the Arduino code.
After creating an account, select Add New... > Device/Widget and select the Arduino microcontroller option...
... and then select the Arduino Yun sketch...
... to obtain a code snippet that includes your authentication token and the correct Cayenne library for Yun:
//#define CAYENNE_DEBUG // Un-comment 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[] = "<your token>";
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}
void loop()
{
Cayenne.run();
}
Save this snippet to cut/paste into the Arduino sketch later.
Step 1.3: Arduino IDE prep
Launch the Arduino IDE (instructions to download the IDE are available in Arduino.cc Software section) and select Sketch > Include Library > Manage Libraries... .
Search for "Cayenne" libraries and install Cayenne by myDevices
Step 1.4: Arduino Yun code
The Arduino code has several main components:
a) The Bridge Library needed for Yun
#include <Bridge.h>
b) The Cayenne authentication snippet from Step 2
c) Specify the accelerometer pins and variables
// 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;
The parameters for waitTime, sensitivityX and sensitivityY can be adjusted in the field to account for variation in the vibration intensity of different equipment.
d) Initialize Yun and Cayenne
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();
}
e) Monitor accelerometer output
While the monitor is active, the program will continuously check the accelerometer reading to see if there are changes from previous readings. If no changes are detected, the monitor knows that vibration has stopped.
// 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)
Step 1.5: Configure the Cayenne Device Dashboard Widget
Back at the Cayenne dashboard, select Add New... > Device/Widget and then select Sensors > Generic > Digital Input. Give your widget a name and select the Yun device from Step 2 above. Choose "Digital" for connectivity, pin D13 and "2 State" (on/off) for the widget.
The dashboard widget will indicate the state of the Dryer: green = "on" (sensing vibration) or no-color = "off".
Step 1.6: Configure the Cayenne Device Trigger(s)
Still at the Cayenne dashboard, select Add New... > Trigger. Give your new trigger a name and select the Yun device. Configure as shown below and specify your mobile phone number for the text message. (Alternately, you can specify an email address, or both.)
Tip: If you share the dryer with other people in the household, you can set up an additional trigger to alert everyone when the dryer starts, so they know it's currently in use.
Other Resources:
- Arduino.cc has a good tutorial on setting up the Yun and connecting to wifi.
- Cayenne has detailed documentation about configuring the platform for Arduino devices.
{Note (02/24/2018): Cayenne has recently change the Arduino API to require MQTT. The code for this project will need to be updated to use the CayenneMQTT library.}
Version 2.0 - Add Dryer Status check via Alexa Skill + ThingSpeakStep 2.1: Set up the ThingSpeak Channel
In the Arduino IDE, add the ThingSpeak library via Library Manager:
Next, create a ThingSpeak account (if you don't already have one) and follow the simple instructions for creating a public channel:
After completing the channel set up, make note of your Channel ID and your Write API Key. In your Arduino code, add the following lines and replace the placeholder with your Channel ID and Write API Key.
// ThingSpeak - Version: Latest
#include <ThingSpeak.h>
// ThingSpeak example
#include "YunClient.h"
YunClient client;
unsigned long myChannelNumber = #######;
const char * myWriteAPIKey = "XXXXXXXXXXXXXXXXXXX";
In the initial setup section, add the following:
void setup() {
// ThingSpeak
ThingSpeak.begin(client);
}
And in the main loop add:
ThingSpeak.setField(1, ledState);
ThingSpeak.setField(2, percentX);
ThingSpeak.setField(3, percentY);
// Write the fields all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
When the device is activated, the ThingSpeak channel will now show dryer status information in the visualization area.
Step 2.2: Set up the Dryer Alert Alexa Skill
The Dryer Alert requires configuration of the Alexa Skill along with coding of the AWS Lambda function. We'll start with the Alexa Skill.
If you don't already have an Amazon developer account, go to the Alexa Skills Kit (ASK) site and register. There are also some great tutorials available on the site for the basics of creating an Alexa Skill. For the Dryer Alert Skill, you'll need a few basic intents:
{
"intents": [
{
"intent": "DryerStatusIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.StopIntent"
}
]
}
You'll also need to specify a few utterances to trigger the AWS Lambda service:
DryerStatusIntent are my clothes dry
DryerStatusIntent check the dryer status
DryerStatusIntent what's the dryer status
DryerStatusIntent what is the dryer status
DryerStatusIntent is the dryer on
DryerStatusIntent is the dryer busy
Follow the ASK tutorials to complete the skill configuration. Make note of the Application ID; you'll need this for the AWS Lambda function setup.
Step 3: Configure the AWS Lambda Function for Dryer Status
Once the Skill configuration is complete, go to the AWS Management Console (create a free account, if needed) and proceed to the Lambda Management Console. Select Create Function:
(If you're new to Lambda, first check out the getting-started tutorial.)
In the Add Triggers section of the Designer, select the Alexa Skills Kit option and use the Application ID from the previous step to connect the Lambda function with the Skill.
The Lambda function Python code is provided in the Code section below. You just need to cut/paste this code into your lambda_function.py. The only thing you'll need to change for this project is to specify your own public ThingSpeak channel and corresponding field you're monitoring.
# Change these elements to point to your data
channel = 177778
field = 1
#
You can also change the voice responses to meet your own needs.
Once the Lambda configuration is complete, make note of the ARN number in the upper right-hand corner and go back to the Skill Configuration page and enter the ARN in the Default end point field. This completes the integration.
If you don't have an Alexa device, you can use the simulation service Echosim.io to give it a whirl.
Future Enhancements:
1) Version 2.1 - When Alexa announces developer support for notifications, add notification for Alexa to alert when the dryer stops: Alexa, "Your clothes are dry".
Comments