"Washing machine ended" sensor


  • Hero Member

    2015-07-04.jpg

    Simple sensor using http://www.aliexpress.com/item/1pc-lot-SW-420-Normally-Closed-Alarm-Vibration-Sensor-Module-Vibration-Switch-30512/32259757483.html. the sensor is attached to the top of the machine with one of those sticky dots. I found out it achieves the best and most accurate readings this way. (http://www.aliexpress.com/item/100pcs-lot-Balloon-attachment-glue-dot-attach-balloons-to-ceiling-or-wall-Globo-paste/2029756655.html)

    The sketch is a bit messy and probably could use a little love and constants but it works for me.
    The basic logic is:

    1. check for vibrations every 100ms
    2. if vibrations were detected, mark the period as "vibration" (a period is 5 minutes)
    3. if there was a vibration period after long period of quiet report "start of cycle"
      4 if there was a longish period of quite after a vibration period, report "end of cycle"
    4. in domoticz the change of state trigger a hangouts message to me.

    the sketch was tested on almost all cycles in my machine. It might fail if i load the machine late at night for early morning start as the opening and closing of the door might be detected as false positive. i might add a big red reset button to clear the state if it bothers me too much.

    here is the sketch:

    // Sensor to detect washing machine end of cycle
    // Connect vibration sensor to digital pin 3 
    
    
    #include <MySensor.h>
    #include <SPI.h>
    
    
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for vibration sensor
    #define SAMPLING_PERIOD 300000 // 5 minutes period. YMMV
    MySensor gw;
    int oldValue=-1;
    unsigned long period_start = millis();
    int state = -1;
    
    
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    
    void setup()  
    {  
      gw.begin();
    
     // Setup the button
      pinMode(BUTTON_PIN,INPUT);  
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      
      gw.present(CHILD_ID, S_DOOR);  
    }
    
    void report_state(int state)
    {
    	  	Serial.print("reporting state: ");
    		Serial.println(state); 
    	    gw.send(msg.set(state));
    	
    }
    
    int prev_state = -1;
    int prev_state_length = 0;
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      // Get the update value
      int value = digitalRead(BUTTON_PIN);
    
      if (value != 0 && state != 1) { // vibration detected for the first time during the period
      	state = 1; 
      }
    
      if (millis() - period_start > SAMPLING_PERIOD) {
      	period_start = millis();
      	Serial.println(state);
        if (state != prev_state) {
      		if (state == 1 && prev_state_length > 4) { //a vibration period after long period of quiet means a cycle started
      	    	report_state(state);
    	    	prev_state_length = 1;
      		
      		} 
      	} else if (state == 0 && prev_state_length > 2) { // a long period of quiet means cycle ended
      		if (prev_state_length == 3)
      			report_state(state); // report only once 
      	}
      	
      	if (state != prev_state)
      		prev_state_length = 1;
      	else
      		prev_state_length++;
    	prev_state = state;
        state = 0;
      	
      }
      
     
      delay(100);
    } 
    
    

  • Hero Member

    Just wanted to say that so far not even a single miss....


  • Hero Member

    Nice work!

    For version 2, get it to fold and put the clothes back in wardrobes! 😉


  • Hero Member

    @gregl this kind of machinery usually involves a ceremony and a ring and is very expensive to run.... 🙂



  • To detect a start of the machine properly you could check if the vibration at least is present for some seconds to prevent the misreading on the evening.

    Edit:

    What kind of Arduino "shield" are you using. Looks like an Arduino Nano on an adapter shield.



  • Nice work and maybe you can power up your arduino with one of the pin from inside the Washing machine (LED panel) to the Nano raw pin. Normaly it is really easy to disamble the plate one the top of the machine to gain access 😉


  • Hero Member

    @gloob true and it was on my todo list. However, loading the machine did not trigger the sensor yet. If it ain't broken....
    Yes it is a funduino "shield". Very handy for prototyping although really not needed here. It just have lots of vcc and gnd...


  • Hero Member

    @kalle i thought to use the vibrations to power it! Like one of these nifty self powering rocker switchs



  • How is the sensor configured in domoticz? is it added as a switch or motion sensor ?



  • gw.present(CHILD_ID, S_DOOR); = added as a door lock 😛



  • I am having some real problems with my Sw-420 vibration sensor. I fastened it directly to the outside of the drum (inside the over) so It vibrates alot when it is running. But the damn sensor wont play. I have to set the sensitivity almost to min to have it not light up when it is still. And when it is running it flickers from time to time, but I would guess it should stay on because it vibrates the whole time.

    If I turn up the sensitivity then it wont turn off, sometimes I need to tap it when there is no movement to have the light go off. I tried placing it in several different directions but can't get anything to work well. I have tried three different sensors and they all behave the same. Any tips?


  • Hero Member

    @Cliff-Karlsson sorry for the delayed reply.
    It needs to be set just on the verge.... So, turn it slowly until it is 0,give it slight turn back. These sensors do not have good signal amplification (its ok for the price i guess) so they work in a vwry narrow ranfe



  • @Moshe-Livne Thanks for posting this. I definitely plan on trying this for my washer but am curious if you think that it would work for the dryer as well. Is the SW-420 sensitive enough to be able to detect the more subtle movement of the dryer?


  • Hero Member

    @chuckconnors I seriously doubt that. the washing machine has much move violent movements. For the dryer I think I would go with current as it is continuously drawing current (lots of current!) while working. In retrospect I would do the same with the washing machine if it was not under warranty. get a small junction box, expose about 3cm of the cable and use non invasive current sensor, all inside the box. Problem is, as always, power for the arduino.
    another option that I considered is taking a good quality power strip, with lots of space in it and putting the sensor and the arduino inside it or only the current sensor (as the wires are exposed usually inside the strip) and the arduino device and charger on the outside. many modern strips have good quality USB sockets so no need for charger.
    just my 2c... not saying you should touch mains, etc bla bla bla....



  • my machine has an "end" led...so I attached a light sensor (LDR) on top of this led...

    just an idea 😉



  • Great Idea. Ill sure make one of these soon. But I think that I will add two start buttons (one for me and one for my girlfriend) and if one of the buttons is pressed as soon as washing machine is finished domoticz will send pushbullet notification to me or my girlfriend.


  • Hardware Contributor

    Hello, that's a very interesting way of solving the problem, I was planning to "upgrade" the wall plug with an in-wall switch including an ACS 712 sensor, this way it could detect 3 levels no current / low current (= on but not washing) / high current (washing). But this is so much simpler that I have to give it a try !

    I don't see why using a sensor board for this though ? It's just a basic switch so it could be connected to interrupt pin directly without a board, and then it's possible to do battery-powered sensor. I'll try that and give a feedback.



  • @Moshe-Livne are you still using this setup? I tried it but sumtimes I get false readings. Like a notification, while the machine wasn't even on...

    @Nca78 Did you ever do a project with the ACS 712? I was wondering about this sensor en it's safety.


  • Hero Member

    @JahFyahh yes, still using it. I never get false readings although lately I started getting the notifications half way through the cycle. Need to check the glue.



  • @Moshe-Livne how did you setup the sensitivity on the senser. I tried your advice, turning it to 0 (all the way to the left) then one stripe back. I pasted it with double sided tape to the top of the machine. Any other tips? I'm thinking of pasting it to the back of the machine.


  • Hero Member

    @JahFyahh it was mostly trial and error. I was lucky and my initial setup was good but these sensors have very sensitive adjustment (all cheap sensors do, i think) and sometimes a fraction of a turn is enough to change things. I think I wrote a simple "read in a loop" sketch and shaked it a bit (like a washing machine, small shakes) to see if i have a read. Hope that helps. I think top of the machine vibrates a bit more than back. if you put on the back, maybe try to mount it high as the upper part moves more than the lower part.


Log in to reply
 

Suggested Topics

49
Online

11.4k
Users

11.1k
Topics

112.6k
Posts