I am not able to stop the blinds motor once the first command is sent.
-
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.
-
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.
-
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.
@mfalkvidd Thanks for your suggestion. It works great.
-
Here is the sketch for Curtain Node.
WindowCurtainShield.inoI 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.


-
Here is the sketch for Curtain Node.
WindowCurtainShield.inoI 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.


@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-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 .@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
-
@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
@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-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); } }@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. -
@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.In addition to Suresh-Mali's suggestion, you could add
#define OPEN 0 #define CLOSE 1 #define IDLE 2and 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.
-
@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.@Suresh-Mali
@mfalkvidd
Thank you for your help ,I'll be trying it tonight and I let you know
Thanks