Instructables

A laundry alarm for the hearing impaired and everyone else!

Featured

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
}
 
Remove these adsRemove these ads by Signing Up