loading

Step 6: Arduino code for laundry alarm


/*
laundry strobe alarm by Emile 'Butch' Alline
monitors turn off of either washer or dryer, then turns on strobe light and on board LED
Hardware is ardweeny ATmega 328, works with IDE 1.0 and earlier
*/
int loopDelay = 1000;       // loop delay between readings set by user
const int  LEDpin = 13;     // output pin for on board LED
const int  strobePin = 5;   // strobe trigger output pin
const int  dryerPin = 2;    // dryer hall switch pin
const int  washerPin = 3;   // washer hall switch pin
int dryerState = 0;         // current state of the dryer, set to zero=off
int washerState = 0;        // current state of the washer, set to zero=off
int lastDryerState = 0;     // previous state of the dryer, set to zero=off
int lastWasherState = 0;    // previous state of the washer, set to zero=off
int firstDryerRead = 0;     // first reading of dryer pin
int firstWasherRead = 0;    // first reading of washer pin
int secondDryerRead = 0;    // second reading of dryer pin
int secondWasherRead = 0;   // second reading of washer pin
int readDelay = 8320;       //the number of microseconds to delay between readings
// 8320 determined experimentally to yield best detection of 60 hz (~99.3% accurate)

void setup() {
  pinMode(LEDpin,OUTPUT);      // initialize LED pin as output for debug
  digitalWrite(LEDpin,LOW);    // set LED off
  pinMode(strobePin, OUTPUT);  // initialize the strobe pin as an output
  digitalWrite(strobePin,LOW); // set the strobe pin LOW (strobe off)
  pinMode(dryerPin, INPUT);    // initialize the dryer pin as an input from hall switch
  pinMode(washerPin, INPUT);   // initialize the washer pin as an input from hall switch
}
void loop()
{
  digitalWrite(LEDpin,HIGH); // flash LED to indicate loop is active
  delay(20); // value not critical
  digitalWrite(LEDpin,LOW);
 
  //first we see if there is 60 hz current on the dryer, if so then dryer state is on (=1)
  firstDryerRead = digitalRead(dryerPin);  //check status of dryer pin for hi part of 60 hz
  delayMicroseconds(readDelay);            // wait for possible next cycle
  secondDryerRead = digitalRead(dryerPin); //then check it again to avoid reading mains spikes

  if(firstDryerRead != secondDryerRead) {  //set the dryer state to on or off (!= means not equal)
    dryerState = 1; // readings are different so there must still be 60 hz on dryerPin
  }
  else {  // no 60 Hz so dryer must be off
    dryerState = 0; // steady state condition, no 60 hz current
  }
  if ((lastDryerState == 1) && (dryerState == 0)){ // 60 hz changed from on to off (&& means boolean AND)
    Serial.println(" dryer turned off ");          // notify user
    digitalWrite(strobePin,HIGH); // set strobe pin HIGH (strobe on),user will do reset to turn it off
    digitalWrite(LEDpin,HIGH);
    while (true)  // Job done, loop until a human arrives to reset
    {
    }
  }
  //end of dryer readings

  //check for 60 hz on washer, if so then washer state is on (=1)
  firstWasherRead = digitalRead(washerPin);  //check status of washer pin for hi part of 60 hz
  delayMicroseconds(readDelay);              // wait for possible next cycle
  secondWasherRead = digitalRead(washerPin); //then check it again to avoid reading mains spikes

  if(firstWasherRead!=secondWasherRead) {
    washerState = 1; // readings are different so there must be 60 hz on washerPin
  }
  else {   // no 60 Hz so dryer must be off
    washerState = 0; // steady state condition, no 60 hz
  }
  if ((lastWasherState == 1) && (washerState == 0)){ // 60 hz changed from on to off
    Serial.println(" washer turned off ");  // notify user
    digitalWrite(strobePin,HIGH); // set strobe pin HIGH (strobe on),user will do reset to turn it off
    digitalWrite(LEDpin,HIGH);
    while (true)  // Job done, just loop until a human arrives to reset
    {
    }
  }
  //end of washer readings
 
  lastDryerState = dryerState;   // save dryer state for comparison later
  lastWasherState = washerState; // save washer state for comparison later
  delay (loopDelay); // optional, not required
}
<p>Being very hearing impaired myself I am always looking for concepts that will assist, so appreciate your invention. That said, some day hopefully someone will come up with a hand held device (similar to a cell phone) that will translate audio into script as find even the best hearing aid devices don't necessarily deliver clarity when in certain environments which in turn can be frustrating for both parties involved in a conversation.</p>
Great job!!! <br> <br>A quick couple of questions... <br> <br> <br>What about people who have a 220v dryer? Instead of using a plug like you have, could we simply open the washer/dryer (at least the older units with the dial timers) and find 120vac on it, then attach a cord to it to bring it outside the case and attach your hall effect sensor? <br> <br>Thanks
110 V or 220V should not make any difference to the hall switch. It is the magnetic field that operates the switch.<br><br>I would strongly recommend that you have someone look over your plans before proceeding. I would also recommend that you keep all high voltages and the sensor within the appliance and only bring out the signal lines from the hall sensor.<br><br>Good luck on your build!
<p>I agree with yr safety advice. If the Hall sensor gives a 5V signal, one could consider feeding it to an optocoupler even, just to get a double isolation. Some of those wires in the AC box are rather close :-)</p>
I'm thinking I may stick with your design mostly except I'll use an or one rbbb for my washer and one for my dryer. <br> <br>I still don,t know about the hall effect. I may even think about attaching an led to the dial timer with a 5v adapter and using a photocell or one of these <br>http://shop.moderndevice.com/products/ambi-light-sensor <br> to detect when the led is on. <br>
<p>Great project, interesting, especially measuring the current<br>I was just wondering, in your situation wouldnt a cooking alarm set to the time the washer needs not have been a quicker and simpler solution? Obviously she would have to carry the alarm with her to feel the vibrations</p>
<p>Great project, interesting, especially measuring the current<br>I was just wondering, in your situation wouldnt a cooking alarm set to the time the washer needs not have been a quicker and simpler solution?</p>
can I modify this to light up to different light for each? <br> <br>you have do5 as the light trigger now. Could that be set for the washer and the do4 be set for the washer?
Yes, you can have the code control LEDs on various pins, just be sure that you use a current limiting resistor. <br> <br>If you send me your email address, I will send you my code. You do not have to use a separate MCU for the washer and dryer. I suggest you start with the dryer since dryers typically stay on from start to finish. Washers tend to have periods in their cycles (that vary in number and length) which can give a false &quot;off&quot; signal. These periods can be accounted for in software.
or could you help me strip the code to just look for one machine and I'll build one foe each.
&quot;Main&quot; photos added per your request. Please let me know if this is acceptable and if this instructable is entered in the Arduino Challenge

About This Instructable

6,423views

18favorites

License:

Bio: retired mechanical engineer
More by balline:DIY polarized multi-pin connectors Make a real (cheap) hexapod ! A laundry alarm for the hearing impaired and everyone else! 
Add instructable to: