Thank you that's exactly what i am looking for!
Lucas van rossum
@Lucas van rossum
Best posts made by Lucas van rossum
-
RE: Problem with multiple relays and delays
Latest posts made by Lucas van rossum
-
RE: Problem with multiple relays and delays
@Poupoune1974 no problems, i will post my progress here...
-
RE: Problem with multiple relays and delays
Thank you that's exactly what i am looking for!
-
Problem with multiple relays and delays
Hi, I am building shutters controler.
My motorized shutters are very basics. There are 3 cables for each motors.
One hot for the ascend the second hot for descent and the neutral.To automate shutters I have an opening delay.
When I command the opening, the relay is operated until the opening delay is ended.This works well when I command one shutter. But in this room there are 3 shutters on the same sensors node.
When I use several shutters at the same time there is problems (it seems like delays were added together ).
Some relays are activated during too much time.Should i use some kind of threads for each shutter?
Cheers
/* =============================================================== Project: Store Test Author: Lucas van Rossum Created: 14/02/2016 Arduino IDE: 1.7.8 ================================================================== */ #include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #define RELAY_ON 0 #define RELAY_OFF 1 // relay shutter pin #define RELAY_UP1 2 #define RELAY_DWN1 3 #define RELAY_UP2 4 #define RELAY_DWN2 5 #define RELAY_UP3 6 #define RELAY_DWN3 7 //button pin #define BUTUP1 8 #define BUTDWN1 A5 #define BUTUP2 A4 #define BUTDWN2 A6 #define BUTUP3 A7 #define BUTDWN3 A0 //switch door pin #define DOORSWITCH1 A3 #define DOORSWITCH2 A2 // CHILD ID #define CHILD_ID_STORE1 1 #define CHILD_ID_STORE2 2 #define CHILD_ID_STORE3 3 #define CHILD_ID_WINDOWS1 4 #define CHILD_ID_WINDOWS2 5 //Secure delay int securedelay=0; //openclose delay int ouverturedelay=10000; // to store button value int ValBUTUP1=0; int ValBUTDWN1=0; int ValBUTUP2=0; int ValBUTDWN2=0; int ValBUTUP3=0; int ValBUTDWN3=0; //to store last shutter action int oldActionA=0; int oldActionB=0; int oldActionC=0; bool state; //// Construct MySensors library MySensor gw; MyMessage msgAUp(CHILD_ID_STORE1,V_UP); MyMessage msgADwn(CHILD_ID_STORE1,V_DOWN); MyMessage msgAStp(CHILD_ID_STORE1,V_STOP); MyMessage msgApor(CHILD_ID_STORE1,V_PERCENTAGE); MyMessage msgBUp(CHILD_ID_STORE2,V_UP); MyMessage msgBDwn(CHILD_ID_STORE2,V_DOWN); MyMessage msgBStp(CHILD_ID_STORE2,V_STOP); MyMessage msgBpor(CHILD_ID_STORE2,V_PERCENTAGE); MyMessage msgCUp(CHILD_ID_STORE3,V_UP); MyMessage msgCDwn(CHILD_ID_STORE3,V_DOWN); MyMessage msgCStp(CHILD_ID_STORE3,V_STOP); MyMessage msgCpor(CHILD_ID_STORE3,V_PERCENTAGE); //switch Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce(); int oldValDOORSWITCH1=-1; int oldValDOORSWITCH2=-1; MyMessage msgSWITCH1(CHILD_ID_WINDOWS1,V_TRIPPED); MyMessage msgSWITCH2(CHILD_ID_WINDOWS2,V_TRIPPED); void setup(){ // Initialize library and add callback for incoming messages gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Store_Salon ", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_STORE1, S_COVER); gw.present(CHILD_ID_STORE2, S_COVER); gw.present(CHILD_ID_STORE3, S_COVER); gw.present(CHILD_ID_WINDOWS1, S_BINARY); gw.present(CHILD_ID_WINDOWS2, S_BINARY); //Setup all the Arduino Pins //relay pinMode(RELAY_UP1, OUTPUT); pinMode(RELAY_DWN1, OUTPUT); pinMode(RELAY_UP2, OUTPUT); pinMode(RELAY_DWN2, OUTPUT); pinMode(RELAY_UP3, OUTPUT); pinMode(RELAY_DWN3, OUTPUT); //switch pinMode(DOORSWITCH1,INPUT); pinMode(DOORSWITCH2,INPUT); // pullup digitalWrite(DOORSWITCH1,HIGH); digitalWrite(DOORSWITCH2,HIGH); debouncer1.attach(DOORSWITCH1); debouncer2.attach(DOORSWITCH2); debouncer1.interval(5); debouncer2.interval(5); //Turn OFF any power to the Relay channels digitalWrite(RELAY_UP1,RELAY_OFF); digitalWrite(RELAY_DWN1,RELAY_OFF); digitalWrite(RELAY_UP2,RELAY_OFF); digitalWrite(RELAY_DWN2,RELAY_OFF); digitalWrite(RELAY_UP3,RELAY_OFF); digitalWrite(RELAY_DWN3,RELAY_OFF); pinMode(BUTUP1, INPUT); pinMode(BUTDWN1, INPUT); pinMode(BUTUP2, INPUT); pinMode(BUTDWN2, INPUT); pinMode(BUTUP3, INPUT); pinMode(BUTDWN3, INPUT); // pullup digitalWrite(BUTUP1,HIGH); digitalWrite(BUTDWN1,HIGH); digitalWrite(BUTUP2,HIGH); //digitalWrite(BUTDWN2,HIGH); only analog A6 //digitalWrite(BUTUP3,HIGH); only analog A7 digitalWrite(BUTDWN3,HIGH); } void loop(){ // Alway process incoming messages whenever possible gw.process(); //Get buton value ValBUTUP1 = digitalRead(BUTUP1); ValBUTDWN1 = digitalRead(BUTDWN1); ValBUTUP2 = digitalRead(BUTUP2); ValBUTDWN2 = analogRead(BUTDWN2) < 500 ? LOW : HIGH; ValBUTUP3 = analogRead(BUTUP3) < 500 ? LOW : HIGH; ValBUTDWN3 = digitalRead(BUTDWN3); //Get Magnetic Door Switch Sensor debouncer1.update(); // Get the update value int value1 = debouncer1.read(); if (value1 != oldValDOORSWITCH1) { // Send in the new value gw.send(msgSWITCH1.set(value1==HIGH ? 1 : 0)); oldValDOORSWITCH1 = value1; } debouncer2.update(); // Get the update value int value2 = debouncer2.read(); if (value2 != oldValDOORSWITCH2) { // Send in the new value gw.send(msgSWITCH2.set(value2==HIGH ? 1 : 0)); oldValDOORSWITCH2 = value2; } ////////// button //shutter1 //UP if (ValBUTUP1 == LOW && ValBUTDWN1 == HIGH ){ int action=1; //action: 1 up,2 down, 0 stop if (action!=oldActionA) { //if (oldAction==2){ digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", up relay1 "); digitalWrite(RELAY_UP1,RELAY_ON); digitalWrite(RELAY_DWN1,RELAY_OFF); gw.send(msgAUp.set(1), false);} // back to domoticz oldActionA=action;} //DOWN if (ValBUTDWN1 == LOW && ValBUTUP1 == HIGH ){ int action=2; //1 monté,2descente, 0stop if (action!=oldActionA) { //if (oldAction==1){ digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", down relay1 "); digitalWrite(RELAY_DWN1,RELAY_ON); digitalWrite(RELAY_UP1,RELAY_OFF); gw.send(msgADwn.set(1), false);} // back to domoticz oldActionA=action; } //OFF if (ValBUTDWN1 == HIGH && ValBUTUP1 == HIGH ){ int action=0; //action: 1 up,2 down, 0 stop if (action!=oldActionA){ Serial.print(", none "); digitalWrite(RELAY_UP1,RELAY_OFF); digitalWrite(RELAY_DWN1,RELAY_OFF); gw.send(msgAStp.set(1), false);} // back to domoticz oldActionA=action; } if (ValBUTDWN1 == LOW && ValBUTUP1 == LOW ){ int action=0; //action: 1 up,2 down, 0 stop if (action!=oldActionA){ Serial.print(", none "); digitalWrite(RELAY_UP1,RELAY_OFF); digitalWrite(RELAY_DWN1,RELAY_OFF); gw.send(msgAStp.set(1), false);} // back to domoticz oldActionA=action; } //shutter2 //UP if (ValBUTUP2 == LOW && ValBUTDWN2 == HIGH ){ int action=1; //action: 1 up,2 down, 0 stop if (action!=oldActionB) { //if (oldAction==2){ digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", up relay2 "); digitalWrite(RELAY_UP2,RELAY_ON); digitalWrite(RELAY_DWN2,RELAY_OFF); gw.send(msgBUp.set(1), false);} // back to domoticz oldActionB=action;} //DOWN if (ValBUTDWN2 == LOW && ValBUTUP2 == HIGH ){ int action=2; //action: 1 up,2 down, 0 stop if (action!=oldActionB) { //if (oldAction==1){ digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", down relay2 "); digitalWrite(RELAY_DWN2,RELAY_ON); digitalWrite(RELAY_UP2,RELAY_OFF); gw.send(msgBDwn.set(1), false);} // back to domoticz oldActionB=action; } //OFF if (ValBUTDWN2 == HIGH && ValBUTUP2 == HIGH ){ int action=0; //1 monté,2descente, 0stop if (action!=oldActionB){ Serial.print(", stop Stor2 2b "); digitalWrite(RELAY_UP2,RELAY_OFF); digitalWrite(RELAY_DWN2,RELAY_OFF); gw.send(msgBStp.set(1), false);} // back to domoticz oldActionB=action; } if (ValBUTDWN2 == LOW && ValBUTUP2 == LOW ){ int action=0; //action: 1 up,2 down, 0 stop if (action!=oldActionB){ Serial.print(", stop Stor2 0b "); digitalWrite(RELAY_UP2,RELAY_OFF); digitalWrite(RELAY_DWN2,RELAY_OFF); gw.send(msgBStp.set(1), false);} // back to domoticz oldActionB=action; } //shutter3 //UP if (ValBUTUP3 == LOW && ValBUTDWN3 == HIGH ){ int action=1; //action: 1 up,2 down, 0 stop if (action!=oldActionC) { //if (oldAction==2){ digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", up relay3 "); digitalWrite(RELAY_UP3,RELAY_ON); digitalWrite(RELAY_DWN3,RELAY_OFF); gw.send(msgCUp.set(1), false);} // back to domoticz oldActionC=action;} //DOWN if (ValBUTDWN3 == LOW && ValBUTUP3 == HIGH ){ int action=2; //action: 1 up,2 down, 0 stop if (action!=oldActionC) { //if (oldAction==1){ digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); gw.wait(securedelay);//} Serial.print(", down relay3 "); digitalWrite(RELAY_DWN3,RELAY_ON); digitalWrite(RELAY_UP3,RELAY_OFF); gw.send(msgCDwn.set(1), false);} // back to domoticz oldActionC=action; } //OFF if (ValBUTDWN3 == HIGH && ValBUTUP3 == HIGH ){ int action=0; //action: 1 up,2 down, 0 stop if (action!=oldActionC){ Serial.print(", none "); digitalWrite(RELAY_UP3,RELAY_OFF); digitalWrite(RELAY_DWN3,RELAY_OFF); gw.send(msgCStp.set(1), false);} //back to domoticz oldActionC=action; } if (ValBUTDWN3 == LOW && ValBUTUP3 == LOW ){ int action=0; //action: 1 up,2 down, 0 stop if (action!=oldActionC){ Serial.print(", none "); digitalWrite(RELAY_UP3,RELAY_OFF); digitalWrite(RELAY_DWN3,RELAY_OFF); gw.send(msgCStp.set(1), false);} //back to domoticz oldActionC=action; } } void incomingMessage(const MyMessage &message) { // Write some debug info Serial.println("[incomingMessage]"); Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print("messagetype"); Serial.print(message.type); Serial.print(", New status: "); Serial.println(message.getBool()); // shutter1 if (message.sensor ==1){ if (message.type == 29) { // open shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_UP1, RELAY_ON); digitalWrite(RELAY_DWN1, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); } } if (message.type == 30) { // close shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_DWN1, RELAY_ON); digitalWrite(RELAY_UP1, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); } } if (message.type == 31) { // stop shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN1, RELAY_OFF); digitalWrite(RELAY_UP1, RELAY_OFF); } } } // shutter2 if (message.sensor ==2){ if (message.type == 29) { // open shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_UP2, RELAY_ON); digitalWrite(RELAY_DWN2, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); } } if (message.type == 30) { // close shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_DWN2, RELAY_ON); digitalWrite(RELAY_UP2, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); } } if (message.type == 31) { // stop shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN2, RELAY_OFF); digitalWrite(RELAY_UP2, RELAY_OFF); } } } // shutter3 if (message.sensor ==3){ if (message.type == 29) { // open shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_UP3, RELAY_ON); digitalWrite(RELAY_DWN3, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); } } if (message.type == 30) { // close shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); gw.wait(securedelay); digitalWrite(RELAY_DWN3, RELAY_ON); digitalWrite(RELAY_UP3, RELAY_OFF); gw.wait(ouverturedelay); digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); } } if (message.type == 31) { // stop shutter state = message.getBool(); if(state == 0){ digitalWrite(RELAY_DWN3, RELAY_OFF); digitalWrite(RELAY_UP3, RELAY_OFF); } } } }
-
Reboot arduino after X connections fails
Hi
Some time after power loose, I have to reset my arduino because it can't find the gateway any more.
Is there a way to do this automaticaly?(like reboot arduino every 2 min if it don't find any gataway)
regards
Lucas -
No serial debug
OS: Windows 7 64bit
Arduino IDE: 1.7.8
MySensors: 1.5
Arduino: UNO
Radio: NRF24L01+Hi, i try a simple setup with a serial gateway and relay actuator with no succes.
So i unplug all and i upload the serial gateway code to my uno with no radio on it.
The serial monitor just print one random character every time i open it.
No other debug info...
Normaly it should print :
0;0;3;0;9;gateway started, id=0, parent=0, distance=0
0;0;3;0;14;Gateway startup complete.cheers