Advertisement
RuiViana

Relays_c_Delay

Feb 3rd, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. /*     http://labdegaragem.com/forum/topics/alguem-pra-me-ajudar-a-da-um-delay-500
  2.   Relay IN1 connected to PinOut 2 Arduino
  3.   Relay IN2 connected to PinOut 3 Arduino
  4.   Relay IN3 connected to PinOut 4 Arduino
  5.   Relay IN4 connected to PinOut 5 Arduino
  6.   --->you can connected to relay modul 4 channel
  7.  
  8.   Serial data sending from Arduino Bluetooth Relay 4CH.apk
  9.   data '1'-'4' to on is Ralay CH 1-4
  10.   data 'A'-'D' to off is Ralay CH 1-4
  11.   data '9' to on ALL CH 1-4
  12.   data 'I' to off ALL CH 1-4
  13. */
  14.  
  15. #include <SoftwareSerial.h>
  16. SoftwareSerial mySerial(10, 11); //Pin10 RX , Pin 11 TX connected to--> Bluetooth TX,RX
  17.  
  18. #define relay1 2
  19. #define relay2 3
  20. #define relay3 4
  21. #define relay4 5
  22.  
  23. unsigned long DRelay1;
  24. unsigned long DRelay2;
  25. unsigned long DRelay3;
  26. unsigned long DRelay4;
  27. unsigned int DelayTime =  500;
  28.  
  29. char val;
  30. //----------------------------
  31. void setup() {
  32.   pinMode(relay1, OUTPUT);
  33.   pinMode(relay2, OUTPUT);
  34.   pinMode(relay3, OUTPUT);
  35.   pinMode(relay4, OUTPUT);
  36.   digitalWrite(relay1, HIGH);
  37.   digitalWrite(relay2, HIGH);
  38.   digitalWrite(relay3, HIGH);
  39.   digitalWrite(relay4, HIGH);
  40.   mySerial.begin(9600);
  41.   Serial.begin(9600);
  42.   DRelay1 = millis();
  43.   DRelay2 = millis();
  44.   DRelay3 = millis();
  45.   DRelay4 = millis();
  46. }
  47. //----------------------------
  48. void loop()
  49. {
  50.   //cek data serial from bluetooth android App
  51.   if ( mySerial.available() > 0 )
  52.   {
  53.     val = mySerial.read();
  54.     Serial.println(val);
  55.   }
  56.   //Relay is on
  57.   if ( val == '1' )
  58.   {
  59.     digitalWrite(relay1, LOW);
  60.     DRelay1 = millis();                     // Recarrega contagem
  61.   }
  62.   if ( val == '2' )
  63.   {
  64.     digitalWrite(relay2, LOW);
  65.     DRelay2 = millis();
  66.   }
  67.   if ( val == '3' )
  68.   {
  69.     digitalWrite(relay3, LOW);
  70.     DRelay3 = millis();
  71.   }
  72.   if ( val == '4' )
  73.   {
  74.     digitalWrite(relay4, LOW);
  75.     DRelay4 = millis();
  76.   }
  77.   val = 0;
  78.  
  79.   if ((millis() - DRelay1) >= DelayTime)    // Se ultrapassou o tempo programado
  80.   {
  81.     digitalWrite(relay1, HIGH);             // Desliga rele
  82.   }
  83.   if ((millis() - DRelay2) >= DelayTime)
  84.   {
  85.     digitalWrite(relay2, HIGH);
  86.   }
  87.   if ((millis() - DRelay3) >= DelayTime)
  88.   {
  89.     digitalWrite(relay3, HIGH);
  90.   }
  91.   if ((millis() - DRelay4) >= DelayTime)
  92.   {
  93.     digitalWrite(relay4, HIGH);
  94.   }
  95. }
  96.  
  97. // http://labdegaragem.com/forum/topics/alguem-pra-me-ajudar-a-da-um-delay-500
  98. //Arduino project created by: pujar
  99. //www.mutekla.com
  100. //Apk Android remote controll suport this project, download on Playstore:
  101. //Arduino Bluetooth Relay 4CH.apk
  102. //https://play.google.com/store/apps/details?id=dev.merahkemarun.arduinobluetoothrelay4ch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement