Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Washing machine state sensor

Washing machine state sensor

Scheduled Pinned Locked Moved My Project
32 Posts 10 Posters 21.3k Views 7 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mvdarend
    wrote on last edited by
    #1

    Hi all, I've been lurking a while here and finally made my first Gateway and Sensors last weekend. I couldn't beleive how easy it was to create and setup :thumbsup:

    Because my washing machine is up in the attic in a sound insulated room, I can't hear it, so I've created a sensor to detect the washing machine state.

    Basically it works as follows:
    The washing machine has an LED with three states:

    • On - Washing machine is Running
    • Flashing - Washing machine has finished the cycle and is Idle
    • Off - Washing machine is Off

    I have a simple light sensor stuck over the LED on the washing machine and have the following code:

    #include <MySensor.h>
    #include <SPI.h>
    
    #define ID 0
    
    enum WashingMachineState {
    	Off,
    	Running,
    	Idle
    };
    
    // these constants won't change:
    const int sensorPin = 7;    // the pin that the Light Sensor is attached to
    const int interval = 200;
    const int threshold = 300;
    
    const int triggerOnOffCount = 80;
    const int triggerIdleCount = 10;
    
    // Variables will change:
    int FlashValue = 0;
    int flashCounter = 0;   // counter for the number of flashes
    int offCounter = 0;
    int onCounter = 0;
    int lightState = 0;         // current state of the light
    int lastlightState = 0;     // previous state of the light
    
    WashingMachineState machineState;
    WashingMachineState lastMachineState;
    
    MySensor gw;
    MyMessage msg(ID, V_VAR1);
    
    void setup() {
    	gw.begin();
    	gw.present(ID, S_CUSTOM);
    
    	// initialize the button pin as a input:
    	pinMode(sensorPin, INPUT);
    
    	// Set default state
    	machineState = Off;
    	lastMachineState = Off;
    }
    
    
    void loop() {
    	delay(interval);
    
    	readLightStatus();
    
    	if (machineState == Idle && machineState != lastMachineState) {
    		lastMachineState = machineState;
    		// send notification
    		gw.send(msg.set("Idle"));
    	}
    
    	if (machineState == Off && machineState != lastMachineState) {
    		lastMachineState = machineState;
    		// send notification
    		gw.send(msg.set("Off"));
    	}
    
    	if (machineState == Running && machineState != lastMachineState) {
    		lastMachineState = machineState;
    		// send notification
    		gw.send(msg.set("Running"));
    	}
    }
    
    void readLightStatus() {
    	// read the Light sensor input pin:
    	FlashValue = analogRead(sensorPin);
    
    	if (FlashValue > threshold)
    	{
    		// light On
    		lightState = 1;
    	}
    	else
    	{
    		// light off
    		lightState = 0;
    	}
    
    	incrementCounters();
    
    	// save the current state as the last state, 
    	lastlightState = lightState;
    }
    
    void incrementCounters(){
    	if (lightState == 1)
    	{
    		// light On
    		onCounter += 1;
    		offCounter = 0;
                    if (onCounter > triggerOnOffCount) { onCounter = triggerOnOffCount; }
    	}
    	else
    	{
    		// light off
    		offCounter += 1;
    		onCounter = 0;
                    if (offCounter > triggerOnOffCount) { offCounter = triggerOnOffCount; }
    	}
    
    	// compare the lightState to its previous state
    	if (lightState != lastlightState && lightState == 1) {
    		// if the state has changed to On, increment the flash counter
    		flashCounter++;
                    if (flashCounter > triggerIdleCount) { flashCounter = triggerIdleCount; }
    	}
    
    	// 10 Flashes counted, machine is now idle
    	if (flashCounter >= triggerIdleCount && machineState != Idle) {
    		machineState = Idle;
    		offCounter = 0;
    		onCounter = 0;
    	}
    
    	if (onCounter >= triggerOnOffCount && machineState != Running)
    	{
    		machineState = Running;
    		offCounter = 0;
    		flashCounter = 0;
    	}
    
    	if (offCounter >= triggerOnOffCount && machineState != Off)
    	{
    		machineState = Off;
    		onCounter = 0;
    		flashCounter = 0;
    		offCounter = triggerOnOffCount; // don't let the number increment any further
    	}
    
    	//Serial.println("flashCounter: " + String(flashCounter));
    	//Serial.println("onCounter:    " + String(onCounter));
    	//Serial.println("offCounter:   " + String(offCounter));
    
    }
    

    It actually works great, but I've very little experience with Arduino programming (and even less with MySensors) and I'm sure that the code could be much better. Any pointers or tips would be very welcome.

    1 Reply Last reply
    0
    • Moshe LivneM Offline
      Moshe LivneM Offline
      Moshe Livne
      Hero Member
      wrote on last edited by
      #2

      It's an omen! I was just thinking about it (not in general, this very minute) then i refreshed the browser and your post came in. I was thinking to try and listen for the annoying beeps its making when it finished. what controller are you using? what sensor type in the controller?

      I am no expert myself but would say to use gw.sleep instead of delay, although in your case it makes little difference because its wall powered sensor.
      also would make one

      if (machineState != lastMachineState) {
               lastMachineState = machineState;
               gw.send(msg.set(state_array[machineState]));
      }
      
      

      just to make it prettier (you should define state_array accordingly)

      all and all its a really neat code.

      RJ_MakeR 1 Reply Last reply
      0
      • M Offline
        M Offline
        mvdarend
        wrote on last edited by
        #3

        Thanks for the feedback and code improvement Moshe.

        I'm using a Nano with a simple photocell resistor. I'll post some pictures this evening if you like, it's still a bit ugly though :)

        The controller I'm using is HomeGenie.

        Moshe LivneM 1 Reply Last reply
        0
        • M mvdarend

          Thanks for the feedback and code improvement Moshe.

          I'm using a Nano with a simple photocell resistor. I'll post some pictures this evening if you like, it's still a bit ugly though :)

          The controller I'm using is HomeGenie.

          Moshe LivneM Offline
          Moshe LivneM Offline
          Moshe Livne
          Hero Member
          wrote on last edited by
          #4

          @mvdarend I wonder if domoticz has the S_CUSTOM sensor. will check.

          1 Reply Last reply
          0
          • Moshe LivneM Moshe Livne

            It's an omen! I was just thinking about it (not in general, this very minute) then i refreshed the browser and your post came in. I was thinking to try and listen for the annoying beeps its making when it finished. what controller are you using? what sensor type in the controller?

            I am no expert myself but would say to use gw.sleep instead of delay, although in your case it makes little difference because its wall powered sensor.
            also would make one

            if (machineState != lastMachineState) {
                     lastMachineState = machineState;
                     gw.send(msg.set(state_array[machineState]));
            }
            
            

            just to make it prettier (you should define state_array accordingly)

            all and all its a really neat code.

            RJ_MakeR Offline
            RJ_MakeR Offline
            RJ_Make
            Hero Member
            wrote on last edited by
            #5

            @Moshe-Livne Not very pretty or efficient, but works perfectly. :stuck_out_tongue_closed_eyes:

            http://forum.mysensors.org/topic/1530/mysensoring-a-ge-washer

            http://forum.mysensors.org/topic/1529/mysensoring-a-ge-electric-clothes-dryer

            RJ_Make

            Moshe LivneM 1 Reply Last reply
            0
            • RJ_MakeR RJ_Make

              @Moshe-Livne Not very pretty or efficient, but works perfectly. :stuck_out_tongue_closed_eyes:

              http://forum.mysensors.org/topic/1530/mysensoring-a-ge-washer

              http://forum.mysensors.org/topic/1529/mysensoring-a-ge-electric-clothes-dryer

              Moshe LivneM Offline
              Moshe LivneM Offline
              Moshe Livne
              Hero Member
              wrote on last edited by
              #6

              @ServiceXp looking for non intrusive. I have encountered problems last night with detecting the beeps as the cheap sound detector modules are, surprise surprise, not very good. I have ordered some better ones. Another option would be to monitor current (heaps of examples so it should be easy)

              RJ_MakeR 1 Reply Last reply
              0
              • Moshe LivneM Moshe Livne

                @ServiceXp looking for non intrusive. I have encountered problems last night with detecting the beeps as the cheap sound detector modules are, surprise surprise, not very good. I have ordered some better ones. Another option would be to monitor current (heaps of examples so it should be easy)

                RJ_MakeR Offline
                RJ_MakeR Offline
                RJ_Make
                Hero Member
                wrote on last edited by
                #7

                @Moshe-Livne I tried a bunch of "wattage watching solutions" and non of them worked very well, but that was also using Vera as my controller (now using HomeSeer). We use 4 different cycles which may have caused some of those problems we encountered also.

                RJ_Make

                Moshe LivneM 1 Reply Last reply
                0
                • RJ_MakeR RJ_Make

                  @Moshe-Livne I tried a bunch of "wattage watching solutions" and non of them worked very well, but that was also using Vera as my controller (now using HomeSeer). We use 4 different cycles which may have caused some of those problems we encountered also.

                  Moshe LivneM Offline
                  Moshe LivneM Offline
                  Moshe Livne
                  Hero Member
                  wrote on last edited by
                  #8

                  @ServiceXp I was thinking of having the logic in the arduino. should be simple, no? current drawn - in cycle. no current for 5 min - cycle ended. what am i missing?

                  greglG RJ_MakeR 2 Replies Last reply
                  0
                  • Moshe LivneM Moshe Livne

                    @ServiceXp I was thinking of having the logic in the arduino. should be simple, no? current drawn - in cycle. no current for 5 min - cycle ended. what am i missing?

                    greglG Offline
                    greglG Offline
                    gregl
                    Hero Member
                    wrote on last edited by
                    #9

                    @Moshe-Livne With a current sensor you might even be able to profile each cycle.

                    eg: current ~5amps for 3mins = rinse
                    current ~8amps for 8mins = wash
                    current ~10amps for spin

                    No, not really necessary, but A+++ for cool factor!

                    Moshe LivneM 1 Reply Last reply
                    0
                    • greglG gregl

                      @Moshe-Livne With a current sensor you might even be able to profile each cycle.

                      eg: current ~5amps for 3mins = rinse
                      current ~8amps for 8mins = wash
                      current ~10amps for spin

                      No, not really necessary, but A+++ for cool factor!

                      Moshe LivneM Offline
                      Moshe LivneM Offline
                      Moshe Livne
                      Hero Member
                      wrote on last edited by
                      #10

                      @gregl Oh super useful! predictive finishing! can calculate when the cycle will finish and by triangulating my position and using google maps calculate how long it will take me to arrive and let me know i am late for taking out the washing!
                      Or it can do a prep talk to the dryer, getting it all worked out for the upcoming laundry :-)

                      1 Reply Last reply
                      0
                      • Moshe LivneM Moshe Livne

                        @ServiceXp I was thinking of having the logic in the arduino. should be simple, no? current drawn - in cycle. no current for 5 min - cycle ended. what am i missing?

                        RJ_MakeR Offline
                        RJ_MakeR Offline
                        RJ_Make
                        Hero Member
                        wrote on last edited by
                        #11

                        @Moshe-Livne said:

                        @ServiceXp I was thinking of having the logic in the arduino. should be simple, no? current drawn - in cycle. no current for 5 min - cycle ended. what am i missing?

                        I think it depends on your washers efficiency and the cycles you use. My washer is one of those HE machines that using adaptive cycle routines with-in the select load type. Creates a wattage watching nightmare. Couple that with Vera's instability, I just gave up and took a more direct approach.

                        RJ_Make

                        BulldogLowellB 1 Reply Last reply
                        0
                        • RJ_MakeR RJ_Make

                          @Moshe-Livne said:

                          @ServiceXp I was thinking of having the logic in the arduino. should be simple, no? current drawn - in cycle. no current for 5 min - cycle ended. what am i missing?

                          I think it depends on your washers efficiency and the cycles you use. My washer is one of those HE machines that using adaptive cycle routines with-in the select load type. Creates a wattage watching nightmare. Couple that with Vera's instability, I just gave up and took a more direct approach.

                          BulldogLowellB Offline
                          BulldogLowellB Offline
                          BulldogLowell
                          Contest Winner
                          wrote on last edited by
                          #12

                          @ServiceXp

                          I like this project, but since my washer and dryer have LEDs which indicate that cycle is complete too, I was thinking to optically sense that cycle was complete if I cannot get to the electronics easily (and maybe even void my warrantee). I'm going to try to find a very small sensor, perhaps.

                          My real issue is how to get my wife excited about increasing our laundry efficiency ;)

                          Moshe LivneM 1 Reply Last reply
                          0
                          • hekH Offline
                            hekH Offline
                            hek
                            Admin
                            wrote on last edited by
                            #13

                            Tried the washer thing a year back...

                            But it quickly got down-voted by my wife after some innocent "bugs" in the watt-algorithm. I was forced to stop the Sonos speakers to announce "Tvätten är klar" ( <-- Swedish) several times during the wash cycle.

                            Hope to build enough confident to give it another try. But I suspect we got one of these eco-washers...

                            1 Reply Last reply
                            0
                            • DidiD Offline
                              DidiD Offline
                              Didi
                              wrote on last edited by
                              #14

                              @hek said:

                              Hope to build enough confident to give it another try. But I suspect we got one of these eco-washers...

                              I bought one this year and my wife is really happy with it ;-)

                              if (knowledge == 0) { use BRAIN; use GOOGLE;use SEARCH; } else {make POST;}

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kalle
                                wrote on last edited by
                                #15

                                Maybe a vibration sensor do the trick ;-)

                                like this one or similar: http://www.dfrobot.com/index.php?route=product/product&product_id=79#.VYM0i6O0N8E

                                1 Reply Last reply
                                0
                                • BulldogLowellB BulldogLowell

                                  @ServiceXp

                                  I like this project, but since my washer and dryer have LEDs which indicate that cycle is complete too, I was thinking to optically sense that cycle was complete if I cannot get to the electronics easily (and maybe even void my warrantee). I'm going to try to find a very small sensor, perhaps.

                                  My real issue is how to get my wife excited about increasing our laundry efficiency ;)

                                  Moshe LivneM Offline
                                  Moshe LivneM Offline
                                  Moshe Livne
                                  Hero Member
                                  wrote on last edited by
                                  #16

                                  @BulldogLowell @ServiceXp Bosch in their infinite wisdom made the LED integral part of the start/stop button, putting a bit of a damper on optically sensing it. So far the 2 sound sensors I have are so bad that unless you do something really drastic like nuclear explosion they are very stoic about environmental beeps. they are ok for sensing knocks. now, I am not trying to sense Watt or try to profile the current use, as this is hopeless (my washing machine is also too smart for her own good). I am just going to watch for current draw above the "zero" over 5 min period. I think it would be safe enough but will not know until I get the sensors.....
                                  @kalle - got the vibration sensor in the mail yesterday! great minds, etc. but it is more complicated as while doing hot wash there are lengthy waits for the water to heat up.
                                  my plan is to use one of these powerboard things (http://www.mitre10.co.nz/shop/electrical_hardware/cords_powerboards/hpm_surge_protector_powerboard_6_way_106033/) and block the last two and use the space for the arduino and sensor to measure current on the last socket. I have excellent RCDs installed :-)
                                  @hek - I use discreet notification using google hangouts....

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mvdarend
                                    wrote on last edited by
                                    #17

                                    @kalle, I actually tried the vibration sensor (based on this design) but I could only get it to perform properly by pressing a button to tell the Arduino that the cycle had started, which made it useless for when I wanted the machine to delay the start.
                                    I tried checking for vibrations as a trigger for 'Machine start' but it would trigger when loading the machine, and again when unloading... basically that was useless.

                                    @Moshe-Livne, I wanted to try sensing electricity usage, but when profiling the machine I found that when 'off' it was still consuming almost 5 watts, which is not a major problem if you define that as a threshold, but our machine sometimes just sits there doing nothing as far as I can see during the cycle. I was worried it would be a bit of a 'hit and miss' affair as @hek experienced.

                                    @ServiceXp, I looked at your solution also when browsing the forums and almost went that way. But I didn;t want to open my machine, I know that my wife would not be happy about that. And with three small kids I can't afford to take my time about it, we need the machine every day :)

                                    Prateek GuptaP Moshe LivneM 2 Replies Last reply
                                    0
                                    • M mvdarend

                                      @kalle, I actually tried the vibration sensor (based on this design) but I could only get it to perform properly by pressing a button to tell the Arduino that the cycle had started, which made it useless for when I wanted the machine to delay the start.
                                      I tried checking for vibrations as a trigger for 'Machine start' but it would trigger when loading the machine, and again when unloading... basically that was useless.

                                      @Moshe-Livne, I wanted to try sensing electricity usage, but when profiling the machine I found that when 'off' it was still consuming almost 5 watts, which is not a major problem if you define that as a threshold, but our machine sometimes just sits there doing nothing as far as I can see during the cycle. I was worried it would be a bit of a 'hit and miss' affair as @hek experienced.

                                      @ServiceXp, I looked at your solution also when browsing the forums and almost went that way. But I didn;t want to open my machine, I know that my wife would not be happy about that. And with three small kids I can't afford to take my time about it, we need the machine every day :)

                                      Prateek GuptaP Offline
                                      Prateek GuptaP Offline
                                      Prateek Gupta
                                      wrote on last edited by
                                      #18

                                      @mvdarend hey I just stumbled across this post. I would like to draw your attention to something called as Power signature analysis.
                                      There are some automation systems using it, such as neurio.io
                                      I am still intrigued by it. Any electrical engineers here?

                                      1 Reply Last reply
                                      0
                                      • M mvdarend

                                        @kalle, I actually tried the vibration sensor (based on this design) but I could only get it to perform properly by pressing a button to tell the Arduino that the cycle had started, which made it useless for when I wanted the machine to delay the start.
                                        I tried checking for vibrations as a trigger for 'Machine start' but it would trigger when loading the machine, and again when unloading... basically that was useless.

                                        @Moshe-Livne, I wanted to try sensing electricity usage, but when profiling the machine I found that when 'off' it was still consuming almost 5 watts, which is not a major problem if you define that as a threshold, but our machine sometimes just sits there doing nothing as far as I can see during the cycle. I was worried it would be a bit of a 'hit and miss' affair as @hek experienced.

                                        @ServiceXp, I looked at your solution also when browsing the forums and almost went that way. But I didn;t want to open my machine, I know that my wife would not be happy about that. And with three small kids I can't afford to take my time about it, we need the machine every day :)

                                        Moshe LivneM Offline
                                        Moshe LivneM Offline
                                        Moshe Livne
                                        Hero Member
                                        wrote on last edited by
                                        #19

                                        @mvdarend you are a ray of sunshine, aren't you? I think power profiling is the way to go. although the washing machine will sit around doing nothing for a while (especially during pre-wash) I think it is still safe to say that there will be spikes of usage when heating, spinning, etc
                                        I am not too fussy about catching the machine the minute it finished so even 30 min with nothing over the threshold will be fine for me. I tend to leave the washing for DAYS in the machine :disappointed:
                                        I now have 3 different vibration sensors. They do work for an extent but as you said - the number of false positives is a pain.
                                        @Prateek-Gupta I think that is a bit of over solving a washing machine problem :-)

                                        Prateek GuptaP 1 Reply Last reply
                                        0
                                        • Moshe LivneM Moshe Livne

                                          @mvdarend you are a ray of sunshine, aren't you? I think power profiling is the way to go. although the washing machine will sit around doing nothing for a while (especially during pre-wash) I think it is still safe to say that there will be spikes of usage when heating, spinning, etc
                                          I am not too fussy about catching the machine the minute it finished so even 30 min with nothing over the threshold will be fine for me. I tend to leave the washing for DAYS in the machine :disappointed:
                                          I now have 3 different vibration sensors. They do work for an extent but as you said - the number of false positives is a pain.
                                          @Prateek-Gupta I think that is a bit of over solving a washing machine problem :-)

                                          Prateek GuptaP Offline
                                          Prateek GuptaP Offline
                                          Prateek Gupta
                                          wrote on last edited by
                                          #20

                                          @Moshe-Livne Yes, I agree. But then this could be applied to a numerous electrical appliances across your home. Almost, all the devices have a unique power signature down to different operating modes.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          21

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular