bangnaga

Kontrol Relay daribluetooth

May 8th, 2017
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // 2017
  3. // Kontrol Relay dari bluetooth
  4.  
  5. const int relayPin = 3; // Tentukan Pin Digital Relay
  6. int state;             // Status terakhir dari serial port
  7. int flag;              // flag o/off;)
  8.  
  9.  
  10. void setup()
  11. {
  12.   pinMode(relayPin, OUTPUT);  // Tentukan Pin Output
  13.     Serial.begin(9600);       // Set baud rate serial
  14. }
  15.  
  16. void loop()
  17. {
  18.     if(Serial.available() > 0){    
  19.       state = Serial.read();    // simpan data serial di variabel state
  20.     }
  21.  
  22.  if( state == '1' )               // jika ata 1 maka aktifkan relay /Charging
  23.   {
  24.     digitalWrite(relayPin, HIGH);    
  25.   }
  26.  
  27.   if( state == '0' )              // if 0 Nonaktifkan Relay/Stop Charging
  28.   {
  29.     digitalWrite(relayPin, LOW);  
  30.   }
  31. }
RAW Paste Data