Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* http://labdegaragem.com/forum/topics/alguem-pra-me-ajudar-a-da-um-delay-500
- Relay IN1 connected to PinOut 2 Arduino
- Relay IN2 connected to PinOut 3 Arduino
- Relay IN3 connected to PinOut 4 Arduino
- Relay IN4 connected to PinOut 5 Arduino
- --->you can connected to relay modul 4 channel
- Serial data sending from Arduino Bluetooth Relay 4CH.apk
- data '1'-'4' to on is Ralay CH 1-4
- data 'A'-'D' to off is Ralay CH 1-4
- data '9' to on ALL CH 1-4
- data 'I' to off ALL CH 1-4
- */
- #include <SoftwareSerial.h>
- SoftwareSerial mySerial(10, 11); //Pin10 RX , Pin 11 TX connected to--> Bluetooth TX,RX
- #define relay1 2
- #define relay2 3
- #define relay3 4
- #define relay4 5
- unsigned long DRelay1;
- unsigned long DRelay2;
- unsigned long DRelay3;
- unsigned long DRelay4;
- unsigned int DelayTime = 500;
- char val;
- //----------------------------
- void setup() {
- pinMode(relay1, OUTPUT);
- pinMode(relay2, OUTPUT);
- pinMode(relay3, OUTPUT);
- pinMode(relay4, OUTPUT);
- digitalWrite(relay1, HIGH);
- digitalWrite(relay2, HIGH);
- digitalWrite(relay3, HIGH);
- digitalWrite(relay4, HIGH);
- mySerial.begin(9600);
- Serial.begin(9600);
- DRelay1 = millis();
- DRelay2 = millis();
- DRelay3 = millis();
- DRelay4 = millis();
- }
- //----------------------------
- void loop()
- {
- //cek data serial from bluetooth android App
- if ( mySerial.available() > 0 )
- {
- val = mySerial.read();
- Serial.println(val);
- }
- //Relay is on
- if ( val == '1' )
- {
- digitalWrite(relay1, LOW);
- DRelay1 = millis(); // Recarrega contagem
- }
- if ( val == '2' )
- {
- digitalWrite(relay2, LOW);
- DRelay2 = millis();
- }
- if ( val == '3' )
- {
- digitalWrite(relay3, LOW);
- DRelay3 = millis();
- }
- if ( val == '4' )
- {
- digitalWrite(relay4, LOW);
- DRelay4 = millis();
- }
- val = 0;
- if ((millis() - DRelay1) >= DelayTime) // Se ultrapassou o tempo programado
- {
- digitalWrite(relay1, HIGH); // Desliga rele
- }
- if ((millis() - DRelay2) >= DelayTime)
- {
- digitalWrite(relay2, HIGH);
- }
- if ((millis() - DRelay3) >= DelayTime)
- {
- digitalWrite(relay3, HIGH);
- }
- if ((millis() - DRelay4) >= DelayTime)
- {
- digitalWrite(relay4, HIGH);
- }
- }
- // http://labdegaragem.com/forum/topics/alguem-pra-me-ajudar-a-da-um-delay-500
- //Arduino project created by: pujar
- //www.mutekla.com
- //Apk Android remote controll suport this project, download on Playstore:
- //Arduino Bluetooth Relay 4CH.apk
- //https://play.google.com/store/apps/details?id=dev.merahkemarun.arduinobluetoothrelay4ch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement