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. Troubleshooting
  3. I am not able to stop the blinds motor once the first command is sent.

I am not able to stop the blinds motor once the first command is sent.

Scheduled Pinned Locked Moved Troubleshooting
12 Posts 3 Posters 4.8k Views 3 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.
  • Suresh MaliS Offline
    Suresh MaliS Offline
    Suresh Mali
    wrote on last edited by
    #3

    Appreciate your response. Will try gw.process in while loop. I am yet to add the code for endpoint of curtain. I will be using reed switch to detect end and start.

    1 Reply Last reply
    0
    • mfalkviddM mfalkvidd

      I think you need to call gw.process inside your while loops. Otherwise no messages will be received so saveState will not be called, causing the code to loop endlessly.

      Looking at the debug output should reveal the problem.

      Also, when do you expect the motors to stop? I can't see where you detect that the cover has reached the endpoint.

      Adding a few comments would make it easier to follow what the code is supposed to do.

      Suresh MaliS Offline
      Suresh MaliS Offline
      Suresh Mali
      wrote on last edited by
      #4

      @mfalkvidd Thanks for your suggestion. It works great.

      1 Reply Last reply
      1
      • mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by
        #5

        Great! Thanks for reporting back.

        1 Reply Last reply
        0
        • Suresh MaliS Offline
          Suresh MaliS Offline
          Suresh Mali
          wrote on last edited by Suresh Mali
          #6

          Here is the sketch for Curtain Node.
          WindowCurtainShield.ino

          I have managed to solve a lot of problems, but some still exist.
          Works great with Domoticz..manual Buttons are still WIP.
          Some pictures for my first version of Node.
          I have left EEPROM and ATSHA204 unpopulated. Will learn more about it and then add.
          I will be using Dual Optiboot to support OTA.

          0_1456723308133_IMG_20160229_103922.jpg
          0_1456723353041_IMG_20160229_103930.jpg
          0_1456723391691_IMG_20160229_104552.jpg

          oscarcO 1 Reply Last reply
          0
          • Suresh MaliS Suresh Mali

            Here is the sketch for Curtain Node.
            WindowCurtainShield.ino

            I have managed to solve a lot of problems, but some still exist.
            Works great with Domoticz..manual Buttons are still WIP.
            Some pictures for my first version of Node.
            I have left EEPROM and ATSHA204 unpopulated. Will learn more about it and then add.
            I will be using Dual Optiboot to support OTA.

            0_1456723308133_IMG_20160229_103922.jpg
            0_1456723353041_IMG_20160229_103930.jpg
            0_1456723391691_IMG_20160229_104552.jpg

            oscarcO Offline
            oscarcO Offline
            oscarc
            wrote on last edited by
            #7

            @Suresh-Mali
            I tried your sketch but i'm having problems with reed switch bouncing (stop sensors) ,do you have any suggestions how to avoid this ? I'm using an arduino mini pro ,with magnetic reed switches .

            Suresh MaliS 1 Reply Last reply
            0
            • oscarcO oscarc

              @Suresh-Mali
              I tried your sketch but i'm having problems with reed switch bouncing (stop sensors) ,do you have any suggestions how to avoid this ? I'm using an arduino mini pro ,with magnetic reed switches .

              Suresh MaliS Offline
              Suresh MaliS Offline
              Suresh Mali
              wrote on last edited by
              #8

              @oscarc You can add debouncer.

                debouncer.attach(BUTTON_PIN);
                debouncer.interval(5);
              

              Refer the binary switch sensor sketch here http://www.mysensors.org/build/binary

              oscarcO 1 Reply Last reply
              0
              • Suresh MaliS Suresh Mali

                @oscarc You can add debouncer.

                  debouncer.attach(BUTTON_PIN);
                  debouncer.interval(5);
                

                Refer the binary switch sensor sketch here http://www.mysensors.org/build/binary

                oscarcO Offline
                oscarcO Offline
                oscarc
                wrote on last edited by
                #9

                @Suresh-Mali
                I already tried but it just jumps from forward to backward without stooping ,without the stops it works fine ,I push up and it moves ,I push the stop and stops but I really want to use the stops to prevent damage, I'm using an arduino mini pro with an external motor driver.

                #include <SPI.h>
                #include <MySensor.h>
                #include <Bounce2.h>
                
                int motor_forward = 5;
                int motor_reverse = 6;
                
                
                #define stopSwLeft 2
                #define stopSwRight  3
                
                
                int CHILD_CURTAIN_ID =1;
                int lastState;
                MySensor gw;
                MyMessage msg_S_COVER_U(CHILD_CURTAIN_ID, V_UP);
                MyMessage msg_S_COVER_D(CHILD_CURTAIN_ID, V_DOWN);
                MyMessage msg_S_COVER_S(CHILD_CURTAIN_ID, V_STOP);
                Bounce debouncer = Bounce(); 
                Bounce debouncer1 = Bounce();  
                void setup()
                {
                  Serial.begin(115200);
                  // initialize the digital pin as an output for L239D.
                  pinMode(motor_forward, OUTPUT);
                  pinMode(motor_reverse, OUTPUT);
                  
                  // initialize the digital pin as an output for Stop Switches.
                  pinMode(stopSwLeft, INPUT);
                  pinMode(stopSwRight, INPUT);
                digitalWrite(stopSwLeft,HIGH);
                digitalWrite(stopSwRight,HIGH);
                 debouncer.attach(stopSwLeft);
                  debouncer.interval(50);
                  debouncer1.attach(stopSwRight);
                  debouncer1.interval(50);
                
                  
                  gw.begin(incomingMessage, AUTO, true);
                  // Send the sketch version information to the gateway and Controller
                  gw.sendSketchInfo("Window_Curtain", "1.0");
                  gw.present(CHILD_CURTAIN_ID, S_COVER);
                  
                }
                
                void loop(){
                  
                  gw.process();
                  
                  
                 
                  }
                void cover(int coverVal){
                
                  //int coverVal = gw.loadState(CHILD_CURTAIN_ID);
                
                  Serial.print("Cover is : ");
                  lastState = coverVal;
                  switch (coverVal) {
                  case 0:
                    Serial.println("Opening");
                      while (lastState == coverVal)
                      {
                        m_left();
                        gw.process();
                        checkHWInnputs();
                        coverVal = gw.loadState(CHILD_CURTAIN_ID);
                      }
                      gw.send(msg_S_COVER_U.set(V_UP));
                    break;
                  case 1:
                    Serial.println("Closing");
                      while (lastState == coverVal)
                      {
                        m_right();
                        gw.process();
                        checkHWInnputs();
                        coverVal = gw.loadState(CHILD_CURTAIN_ID);
                      }
                      gw.send(msg_S_COVER_D.set(V_DOWN));
                    break;
                  case 2:
                    Serial.println("Idle");
                      while (lastState == coverVal)
                        {
                          m_stop();
                          gw.process();
                          //checkHWInnputs();
                          coverVal = gw.loadState(CHILD_CURTAIN_ID);
                        }
                      gw.send(msg_S_COVER_S.set(V_STOP));
                      break;
                  }
                  return;
                
                }
                void incomingMessage(const MyMessage &message) {
                  // We only expect one type of message from controller. But we better check anyway.
                  Serial.println("recieved incomming message");
                  switch (message.type) {
                  case V_UP:
                    gw.saveState(CHILD_CURTAIN_ID, 0);
                    Serial.print("Incoming change for ID_S_COVER:");
                    Serial.print(message.sensor);
                    Serial.print(", New status: ");
                    Serial.println("V_UP");
                    cover(gw.loadState(CHILD_CURTAIN_ID));
                    Serial.print("Done cover procedure");
                  
                    break;
                
                  case V_DOWN:
                    gw.saveState(CHILD_CURTAIN_ID, 1);
                    Serial.print("Incoming change for ID_S_COVER:");
                    Serial.print("message.sensor");
                    Serial.print(", New status: ");
                    Serial.println("V_DOWN");
                    cover(gw.loadState(CHILD_CURTAIN_ID));
                    Serial.print("Done cover procedure");
                   
                    break;
                
                  case V_STOP:
                    gw.saveState(CHILD_CURTAIN_ID, 2);
                    Serial.print("Incoming change for ID_S_COVER:");
                    Serial.print("message.sensor");
                    Serial.print(", New status: ");
                    Serial.println("V_STOP");
                    cover(gw.loadState(CHILD_CURTAIN_ID));
                    Serial.print("Done cover procedure");
                  
                    break;
                  }
                  Serial.print("exiting incoming message");
                  return;
                  
                }
                //the loop routine runs over and over again forever:
                void m_right() {
                  digitalWrite(motor_forward, HIGH); //terminal D1 will be HIGH
                  digitalWrite(motor_reverse, LOW); //terminal D2 will be LOW
                
                }
                
                void m_left() {
                  digitalWrite(motor_forward, LOW); //terminal D1 will be LOW
                  digitalWrite(motor_reverse, HIGH); //terminal D2 will be HIGH
                
                }
                
                void m_stop() {
                  digitalWrite(motor_forward, LOW); //terminal D1 will be LOW
                  digitalWrite(motor_reverse, LOW ); //terminal D2 will be HIGH
                
                }
                
                void checkHWInnputs()
                  {
                 debouncer.update();
                   debouncer1.update();
                  int value = debouncer.read();
                 int value1 = debouncer1.read();
                 
                  
                   if (value == LOW) {
                
                 Serial.println("Detected stop button push. Stopping");
                     cover(1);
                
                  }
                 
                
                   {
                   if (value1 == LOW)
                  Serial.println("Detected stop button push. Stopping");
                      cover(0);
                    
                    }
                  }
                
                Suresh MaliS 1 Reply Last reply
                0
                • oscarcO oscarc

                  @Suresh-Mali
                  I already tried but it just jumps from forward to backward without stooping ,without the stops it works fine ,I push up and it moves ,I push the stop and stops but I really want to use the stops to prevent damage, I'm using an arduino mini pro with an external motor driver.

                  #include <SPI.h>
                  #include <MySensor.h>
                  #include <Bounce2.h>
                  
                  int motor_forward = 5;
                  int motor_reverse = 6;
                  
                  
                  #define stopSwLeft 2
                  #define stopSwRight  3
                  
                  
                  int CHILD_CURTAIN_ID =1;
                  int lastState;
                  MySensor gw;
                  MyMessage msg_S_COVER_U(CHILD_CURTAIN_ID, V_UP);
                  MyMessage msg_S_COVER_D(CHILD_CURTAIN_ID, V_DOWN);
                  MyMessage msg_S_COVER_S(CHILD_CURTAIN_ID, V_STOP);
                  Bounce debouncer = Bounce(); 
                  Bounce debouncer1 = Bounce();  
                  void setup()
                  {
                    Serial.begin(115200);
                    // initialize the digital pin as an output for L239D.
                    pinMode(motor_forward, OUTPUT);
                    pinMode(motor_reverse, OUTPUT);
                    
                    // initialize the digital pin as an output for Stop Switches.
                    pinMode(stopSwLeft, INPUT);
                    pinMode(stopSwRight, INPUT);
                  digitalWrite(stopSwLeft,HIGH);
                  digitalWrite(stopSwRight,HIGH);
                   debouncer.attach(stopSwLeft);
                    debouncer.interval(50);
                    debouncer1.attach(stopSwRight);
                    debouncer1.interval(50);
                  
                    
                    gw.begin(incomingMessage, AUTO, true);
                    // Send the sketch version information to the gateway and Controller
                    gw.sendSketchInfo("Window_Curtain", "1.0");
                    gw.present(CHILD_CURTAIN_ID, S_COVER);
                    
                  }
                  
                  void loop(){
                    
                    gw.process();
                    
                    
                   
                    }
                  void cover(int coverVal){
                  
                    //int coverVal = gw.loadState(CHILD_CURTAIN_ID);
                  
                    Serial.print("Cover is : ");
                    lastState = coverVal;
                    switch (coverVal) {
                    case 0:
                      Serial.println("Opening");
                        while (lastState == coverVal)
                        {
                          m_left();
                          gw.process();
                          checkHWInnputs();
                          coverVal = gw.loadState(CHILD_CURTAIN_ID);
                        }
                        gw.send(msg_S_COVER_U.set(V_UP));
                      break;
                    case 1:
                      Serial.println("Closing");
                        while (lastState == coverVal)
                        {
                          m_right();
                          gw.process();
                          checkHWInnputs();
                          coverVal = gw.loadState(CHILD_CURTAIN_ID);
                        }
                        gw.send(msg_S_COVER_D.set(V_DOWN));
                      break;
                    case 2:
                      Serial.println("Idle");
                        while (lastState == coverVal)
                          {
                            m_stop();
                            gw.process();
                            //checkHWInnputs();
                            coverVal = gw.loadState(CHILD_CURTAIN_ID);
                          }
                        gw.send(msg_S_COVER_S.set(V_STOP));
                        break;
                    }
                    return;
                  
                  }
                  void incomingMessage(const MyMessage &message) {
                    // We only expect one type of message from controller. But we better check anyway.
                    Serial.println("recieved incomming message");
                    switch (message.type) {
                    case V_UP:
                      gw.saveState(CHILD_CURTAIN_ID, 0);
                      Serial.print("Incoming change for ID_S_COVER:");
                      Serial.print(message.sensor);
                      Serial.print(", New status: ");
                      Serial.println("V_UP");
                      cover(gw.loadState(CHILD_CURTAIN_ID));
                      Serial.print("Done cover procedure");
                    
                      break;
                  
                    case V_DOWN:
                      gw.saveState(CHILD_CURTAIN_ID, 1);
                      Serial.print("Incoming change for ID_S_COVER:");
                      Serial.print("message.sensor");
                      Serial.print(", New status: ");
                      Serial.println("V_DOWN");
                      cover(gw.loadState(CHILD_CURTAIN_ID));
                      Serial.print("Done cover procedure");
                     
                      break;
                  
                    case V_STOP:
                      gw.saveState(CHILD_CURTAIN_ID, 2);
                      Serial.print("Incoming change for ID_S_COVER:");
                      Serial.print("message.sensor");
                      Serial.print(", New status: ");
                      Serial.println("V_STOP");
                      cover(gw.loadState(CHILD_CURTAIN_ID));
                      Serial.print("Done cover procedure");
                    
                      break;
                    }
                    Serial.print("exiting incoming message");
                    return;
                    
                  }
                  //the loop routine runs over and over again forever:
                  void m_right() {
                    digitalWrite(motor_forward, HIGH); //terminal D1 will be HIGH
                    digitalWrite(motor_reverse, LOW); //terminal D2 will be LOW
                  
                  }
                  
                  void m_left() {
                    digitalWrite(motor_forward, LOW); //terminal D1 will be LOW
                    digitalWrite(motor_reverse, HIGH); //terminal D2 will be HIGH
                  
                  }
                  
                  void m_stop() {
                    digitalWrite(motor_forward, LOW); //terminal D1 will be LOW
                    digitalWrite(motor_reverse, LOW ); //terminal D2 will be HIGH
                  
                  }
                  
                  void checkHWInnputs()
                    {
                   debouncer.update();
                     debouncer1.update();
                    int value = debouncer.read();
                   int value1 = debouncer1.read();
                   
                    
                     if (value == LOW) {
                  
                   Serial.println("Detected stop button push. Stopping");
                       cover(1);
                  
                    }
                   
                  
                     {
                     if (value1 == LOW)
                    Serial.println("Detected stop button push. Stopping");
                        cover(0);
                      
                      }
                    }
                  
                  Suresh MaliS Offline
                  Suresh MaliS Offline
                  Suresh Mali
                  wrote on last edited by
                  #10

                  @oscarc The routine below i see some problem.

                  void checkHWInnputs()
                    {
                   debouncer.update();
                     debouncer1.update();
                    int value = debouncer.read();
                   int value1 = debouncer1.read();
                   
                    
                     if (value == LOW) {
                  
                   Serial.println("Detected stop button push. Stopping");
                       cover(1);
                    }
                  
                     {
                     if (value1 == LOW)
                    Serial.println("Detected stop button push. Stopping");
                        cover(0);
                      
                      }
                  

                  Once you detect the button state, you are calling

                  cover(0);
                  

                  If you look at the cover routine, the parameters are used in case statement.
                  0=Open
                  1=Close
                  2=Idle.
                  My suggestion would be to change cover(0)/cover(1) to cover(2) which would stop the motor.

                  mfalkviddM oscarcO 2 Replies Last reply
                  0
                  • Suresh MaliS Suresh Mali

                    @oscarc The routine below i see some problem.

                    void checkHWInnputs()
                      {
                     debouncer.update();
                       debouncer1.update();
                      int value = debouncer.read();
                     int value1 = debouncer1.read();
                     
                      
                       if (value == LOW) {
                    
                     Serial.println("Detected stop button push. Stopping");
                         cover(1);
                      }
                    
                       {
                       if (value1 == LOW)
                      Serial.println("Detected stop button push. Stopping");
                          cover(0);
                        
                        }
                    

                    Once you detect the button state, you are calling

                    cover(0);
                    

                    If you look at the cover routine, the parameters are used in case statement.
                    0=Open
                    1=Close
                    2=Idle.
                    My suggestion would be to change cover(0)/cover(1) to cover(2) which would stop the motor.

                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by mfalkvidd
                    #11

                    In addition to Suresh-Mali's suggestion, you could add

                    #define OPEN 0
                    #define CLOSE 1
                    #define IDLE 2
                    

                    and use cover(OPEN) / cover(CLOSE) / cover(IDLE) instead. That would make it easier to understand the intention of the code and easier to spot small mistakes.

                    1 Reply Last reply
                    2
                    • Suresh MaliS Suresh Mali

                      @oscarc The routine below i see some problem.

                      void checkHWInnputs()
                        {
                       debouncer.update();
                         debouncer1.update();
                        int value = debouncer.read();
                       int value1 = debouncer1.read();
                       
                        
                         if (value == LOW) {
                      
                       Serial.println("Detected stop button push. Stopping");
                           cover(1);
                        }
                      
                         {
                         if (value1 == LOW)
                        Serial.println("Detected stop button push. Stopping");
                            cover(0);
                          
                          }
                      

                      Once you detect the button state, you are calling

                      cover(0);
                      

                      If you look at the cover routine, the parameters are used in case statement.
                      0=Open
                      1=Close
                      2=Idle.
                      My suggestion would be to change cover(0)/cover(1) to cover(2) which would stop the motor.

                      oscarcO Offline
                      oscarcO Offline
                      oscarc
                      wrote on last edited by
                      #12

                      @Suresh-Mali
                      @mfalkvidd
                      Thank you for your help ,I'll be trying it tonight and I let you know
                      Thanks

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


                      24

                      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