Variant on old Washing Machine project using LIS2DH12 Accelerometer on impExplorer Dev kit

I recently received an impExplorer Developer kit. It looks really good and I’ve started getting to know all the attached sensors.

For my first device-led project, I wanted to test out the LIS2DH12 Accelerometer and what better way to do this than to find a suitable smart home test application.

So, as I recall the washing machine project (old forum link here), which also used an accelerometer (although a different one), I came up with a variant on this project.

I am now trying to get my head around the LIS3DH imp library and work out the best-practice approach for this application (i.e. detect washing machine spin cycle / washing cycle - if possible).

I’m also considering other sensors (water, door, etc.) as well as the included environment sensor (temp, humidity, pressure), so my first thought was to use a wakeup timer to periodically wake up (say every 3 seconds) measure sensor readings (such as accelerometer, water, door), record data and then back to sleep. If an event is detected, then send an alert to agent etc. Environment sensors can be much less frequent. So, not sure if putting imp into a deep sleep is best here as this is a power down of imp and I already have control of sensor power via power gate (pin 1).

So, any advice appreciated here. As in, can wakeup timer approach be used here (with some low power option) without draining the battery? If this approach is taken what are the best settings for the accelerometer (e.g. sampling rate)? Was not sure about fifo’s… did not think applicable here, but maybe I’m wrong.

The alternative approach was to come up with some form of interrupt for accelerometer (in particular). Not sure what can be down with water door as have no connection with pin 1.

If Interrupt method, how do I go about setting this up with the accelerometer? Then, if pin 1 is used as the power Gate, what then? I was considering a hybrid approach (when power gate not needed use as interrupt option, then disable interrupt and switch to output mode to power sensors) but maybe this is overkill.

Anyhow, any feedback will be greatly appreciated.

Thanks.

There are a couple options depending on how much power you need to conserve. You can disconnect from WiFi or you can go into a sleep mode.

Here is some documentation on running an imp offline - https://electricimp.com/docs/resources/offline/

Also here are some sample applications - skip to the intermediate and advanced examples for power efficient and interrupt usage - https://github.com/electricimp/examples/tree/master/Intro%20to%20Squirrel%20Applications

Thanks @betsy. I’ll read through the documentation.

As my washing machine sits in the utility room together with home gas boiler, I thought a nice addition would be to attach a carbon monoxide sensor. Currently have lux sensor to tell me if light left on (a common occurrence on my part).

Anyone have suggestions for good I2C CO sensor that will work well off batteries & 3.3V.

Otherwise prototype almost ready. The only real challenge so far is finding suitable white duct tape for the sensors. Moisture + surface causing tape to loosen.

Google Photos

Thanks

ImpExplorer Dev Kit accelerometer is working well… Chart shows rate of change in (3-axis) movement during wash cycle.

Google Photos

1 Like

That all looks like a fun project. Tough to do a door close sensor unless you open up the machine and utilize the door switch they already have. I assume you don’t want to take apart your machine.

The CO thing … the ones you buy in a store probably turn-over rather quickly, so the sensors in them are usually fresh. They also have a test button, which is supposed to test the sensor? Any CO breakout board you buy online will have sat on a shelf for who knows how long? CO sensors deteriorate over time. You will have to buy a CO gas test bottle to periodically check it. Sort of expensive, but I assume it will last a long time, and it would be a valid CO test for your breakout board.

@mlseim Thanks for pointing out the CO calibration and testing issues. And, thanks for the link. Didn’t know you could purchase CO gas test bottles. Very useful as with, all things, testing and validation are key.

Yes, the aim is for retrofit without taking apart the machine. Door sensor acts as the “nagging” trigger once wash is complete. You need to open a washing machine door in order to remove the washing.

I’m making use of the Dark Sky web services library to provide me with a weather update once the washing is completed. Quite happy with the result…

Google Photos

Looking good Gerrikoio! Which platform/software are you using to display the Accelerometer data?

Would you consider sharing your project source code?

Cheers!

I’m not using any platform to display data as was not the aim of this project. The chart was created manually using the agent datalogs where I turn off all server.log messages except for accel data (an RMS value pushed to server every 3 seconds). I then simply cut n paste logged data into excel and parse out the data for charting (scatter chart). This was a quick and dirty hack which allowed me to start understanding what’s going on. From there my code as evolved where I merged the 3 axis readings into 1 aggregated value and then created a moving average using absolute values as all I want is to track the cycle, nothing more. Beyond this, I will use the high-value thresholds to act as triggers for the device.

If I were to send the detailed data to a platform then I would probably consider the following, as used these web services before:
plot.ly, as provides ready-made charts, or
keen.io, as provides some good data query/analysis options but for charting you need to do your own thing using own library such as chartjs, for example, or
firebase, as provides handy options for creating real-time web and mobile apps, although similarly need to use own charting libraries,

There are plenty of other options which would work too, from AWS and IBM BlueMix through to Dweet.io, UbiDots and Conctr.

Regarding code. Not much to show as used eImp library for device, where I set data rate at 100Hz (no science behind that setting) and then took readings using the function found in the eImp library examples

accelSensor.getAccel(function(result) { … });

For the weather report, I used the DarkSky library. Works great.

For emails, I use Mailgun and for notifications I use Slack.

Hi There

Thank you for the detailed explanation and links to various services.

I’ve got much learning to do yet but have not been able to get data out of the Accelerometer (yet). It’s the bit of your code I was most interested in seeing… I’m likely missing something obvious and was looking for an example to compare to.

I’ll take another stab at it.

Cheers Mate :slight_smile:

Ok, I’ve extracted out the accel code from my Imp device. Hopefully got it all:

#require "LIS3DH.device.lib.nut:2.0.0"
const LIS2DH12_ADDR = 0x32;
const WSH_WAKEUP_TIME = 3;
accelSensor <- null;
pwrGATE <- hardware.pin1;

function takeAccelReading() {
accelSensor.setDataRate(100);
accelSensor.enable(true);
accelSensor.getAccel(function(result) {
if (“err” in result) {
// Check for error
server.log("accel error: " + result.err);
}
else {
// add timestamp to result table
result.ts <- time();
result.x *= 100.0;
result.y *= 100.0;
result.z *= 100.0;
}
});
imp.wakeup(WSH_WAKEUP_TIME, takeWashMachineReading);
}
// Configure I2C bus for sensors
// ---------------------------------------------------------------------

local i2c = hardware.i2c89;

i2c.configure(CLOCK_SPEED_400_KHZ);
accelSensor <- LIS3DH(i2c, LIS2DH12_ADDR);
accelSensor.reset();
accelSensor.setMode(LIS3DH_MODE_NORMAL);
accelSensor.setRange(2);
server.log(format(“Device ID: 0x%02X”, accelSensor.getDeviceId()));

// POWER gate for the Grove IO pins
pwrGATE.configure(DIGITAL_OUT, 1);

// Start taking sensor readings
takeAccelReading();

The library examples also suggest using this when imp device goes idle:
// Set the imp to sleep when idle, ie. program complete
imp.onidle(function() {
accelSensor.setDataRate(0);
accelSensor.enable(false);
// server.sleepfor(ENV_SLEEP_TIME); <---- NOTE if using this then you do not need to use imp.wakeup in the takeAccelReading() function
server.log(“Going offline”);
server.disconnect();
});