Brendan Attempts to Make Some Things

MAS.863/4.140

Final Project: Laundry Time

Going into my final project I knew I wanted to accomplish a few things. I'm very interested in the Internet of Things, and really wanted to see if I could make something that was wi-fi enabled. I also wanted to try my hand at different forms of networking between boards. Finally, I wanted something that was cheap, simple, and relied on good software to make up for limited hardware. Thus enter, Laundry Time.

  • Technologies: Roland Mill, 3D Printer, Arduino IDE, Python, Arduino Huzzah, Networking and Communications, Friendship
  • Final: Project

The Arduino Huzzah

Originally, I was planning on using bluetooth in order to communicate between two boards, one that would be hosting a web server and one that would have the detecting device. Though Bluetooth is easy to implement, you cannot pair multiple decives with bluetooth, so that was out the window. Dan Chen showed me the Arduino Huzzah, and I was really excited to get to work with it. Once I did, I found the board to be incredible (probably too much so, because it took up all my time). The fact that it had a 32 bit chip, WiFi, only cost $7 in large quantities (7!) blew my mind. Getting set up with WiFi at Harvard proved to be a struggle though. There are no open WiFi networks at Harvard, and the Arduino prevented me from joining computer to computer networks. Eventually, the only workaround I could find was connecting a computer to Ethernet, which is something that my laptop lacked, and creating a wireless, internet connected network from there. Eventually, this strategy stopped working, as well.

Arduino Huzzah, in All Its Glory

After figuring out how to get on the internet, creating a web server was simple. However, this whole process would have been much easier if I were at MIT the entire time. From here, it was time to decide what type of item to use to detect whether a laundry machine was on or off. I had previously designed an accelerometer board for inputs week that I had been able to stuff, and with only one 2-axis accelerometer left in stock, I figured that a reasonable place to start was seeing if I could get an ATTiny45 to successfully communicate with the Huzzah.

The Accelerometer

Board 1

There are many ways to communicate between boards, and I spent many hours seeing if there was some way I could modify Professor Gershenfeld's code to be able to tell whether or not the board was on a working washing machine without another board having to do the communication (I couldn't at the very least). It did make me have tremendous respect for that software serial implementation. It took a very long time to get the two boards communicating, but eventually, by modifying the python script into C, it all worked out

So here's where things get interesting. I have a microcontroller that is both a web server and is performing a large amount of high speed calculations on input data, that does not support concurrency at all. There are many ways to go about dealing with this, but I chose one that was rather unorthodox, randomness.

		
		/* DHTServer - ESP8266 Webserver with a DHT sensor as an input

   Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)

   Version 1.0  5/3/2014  Version 1.0   Mike Barela for Adafruit Industries
*/
#include 
#include 
#include 
#include 

const char* ssid     = "MIT GUEST";
const char* password = "";

ESP8266WebServer server(80); 

// Initialize DHT sensor
// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
// you need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// This is for the ESP8266 processor on ESP-01

//float humidity, temp_f;  // Values read from sensor
String webString = "";   // String to display
// Generally, you should use "unsigned long" for variables that hold time
boolean is_on = true;
int xoffl;
int xoffh;
int xonl ;
int xonh;
int yoffl ;
int yoffh;
int yonl;
int yonh;
int xon;
int xoff;
int yon;
int yoff;
int mins;
float xvalue;
float yvalue;
float old_xvalue;
float old_yvalue;
float dev;
int counter = 0;
bool should_read;
void setup(void)
{
  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(9600);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.print("\n\r \n\rWorking to connect");

  // Wait for connection
  int counter = 0;
  while (WiFi.status() != WL_CONNECTED and counter < 40) {
    delay(500);
    Serial.print(".");
    counter ++;
  }
  Serial.println("");
  Serial.println("Washing Machine Sensor");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.gatewayIP());


  server.on("/", handle_root);

  server.on("/temp", []() { // if you add this subdirectory to your webserver call, you get text below :)
    //  gettemperature();       // read sensor
    webString = "Temperature: F"; // Arduino has a hard time with float to string
    server.send(200, "text/plain", webString);            // send to someones browser when asked
    Serial.println(webString);
  });

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void)
{
   if (random(10) < 9){
    server.handleClient();
   }
   should_read = false;
      if (Serial.read() == 1){
    if (Serial.read() == 2){
      if (Serial.read() == 3) {
        if (Serial.read() == 4)
          should_read = true;
        }
      }
      }
   if (should_read){
      if (counter % 100  == 0){
        if (dev > 5){
          is_on = true;
        }
        else{
          is_on = false;
        }
        Serial.println(dev);
        dev = 0;
        old_xvalue = xvalue;
        old_yvalue = yvalue;
      }
    xoffl = Serial.read();
   xoffh= Serial.read();
   xonl = Serial.read();
   xonh= Serial.read();
   yoffl = Serial.read();
   yoffh= Serial.read();
   yonl = Serial.read();
   yonh= Serial.read();
      xoff = 256*xoffh+ xoffl;
      xon = 256*xonh+ xonl;
      xvalue = xoff/float(xon+xoff);
      xoff = 256*xoffh+ xoffl;
      xon = 256*xonh+ xonl;
      xvalue = xoff/float(xon+xoff);
      yoff = 256*yoffh+ yoffl;
      yon = 256*yonh+ yonl;
      yvalue = yoff/float(yon+yoff);
      //Serial.println(yvalue, DEC);
      //Serial.println(xvalue);
      dev += abs(xvalue - old_xvalue) + abs(yvalue - old_yvalue);
      counter ++;
      old_xvalue = xvalue;
      old_yvalue = yvalue;
    }
    else{
      delay(random(200));
    }
   }

void handle_root() {

  if (is_on) {
    server.send(200, "text/html","  Laundry Time                

Laundry Time

Never Be Unsure Again

Wait A Minute!

Taken Now

"); } else { server.send(200, "text/html"," Laundry Time

Laundry Time

Never Be Unsure Again

Come on Up!

All Free

"); } delay(100); // server.send(200, "text/plain", "Hello from the weather esp8266, read from /temp or /humidity"); // delay(100); }

Roughly 9/10 of the time, it tries to keep the server up and running, but every once in a while, it will read the serial input as well. Since these chips are so fast, this is not a very long process at all (though both the ATTiny45 and the Arduino were running on a baudrate of 9600). These seemed to work very well!

Now as for the actual detection part, it was not flawless, but I believe with large number of samples and strong priors it can be. Below are some videos of test on the washing machine.

The Board

You might notice the blue ball that the board was sitting on, that was a way that I thought of to increase the variance of the accelerometer. I assumed that an object that could roll around easily would be easily swinged by momentum. I wasn't entirely right

Overall I made a very simple solution to a problem that has plagued me throughout college, and was excited by the results. I wish I had more time to continue to iterate, though, and am looking forward to continuing out on my own.