21 Aralık 2017 Perşembe

Blueutooth üzerinden LED yakma


Bu uygulama ile cep telefonu üzerinden 4 lÜ LED kontrolü yapılmıştır. Arduino Bluetooth Control Device programını Google Play Store dan indirip uygulamayı çalıştırınız. Programda Connect butonuna tıklayıp bluetooth araması yapıp HC-05 bluetooth adresini seçiniz.


Not: Programı yüklerken Bluetooth bağlantısını kesiniz.
  





/*  Bluetooth üzerinden röle kontrolü
 *  
 *  LED Bağlantıları: 2,3,4,5. pinler
 *  HC06 Bluetooth Bağlantısı: Vcc=5V ,GND=GND,Tx= Arduino Rx, Rx= Arduino Tx
 *  
*/

#define LED_PIN1  2
#define LED_PIN2  3
#define LED_PIN3  4
#define LED_PIN4  5
  
int inByte = 0;       
boolean status_unlock;
boolean status_bluetooth;

long interval = 1000;           
long previousMillis = 0;        
int minite,sec;

void setup()
{
  Serial.begin(9600);
  
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
  pinMode(LED_PIN4, OUTPUT);

  
  digitalWrite(LED_PIN1, LOW);  
  digitalWrite(LED_PIN2, LOW);  
  digitalWrite(LED_PIN3, LOW);  
  digitalWrite(LED_PIN4, LOW);  
    
  
  status_bluetooth = true;
  status_unlock = false;
  sec = 0;
}

void loop()
{
  if (Serial.available() > 0) {   
       
    inByte = Serial.read();           

    if(inByte == 'A'){    
      Serial.print('A');         
      digitalWrite(LED_PIN1, HIGH);       
      status_unlock = false;
      inByte = 0;     
    }
    
    if(inByte == 'a'){    
      digitalWrite(LED_PIN1, LOW);        
      Serial.print('a');           
      status_unlock = true;
      sec = 0;
      inByte = 0;     
    }
    
    if(inByte == 'B'){    
      digitalWrite(LED_PIN2, HIGH);        
      Serial.print('B');         
      inByte = 0;     
    }
    
    if(inByte == 'b'){    
      digitalWrite(LED_PIN2, LOW);       
      Serial.print('b');        
      inByte = 0;     
    }
    
    if(inByte == 'C'){    
      digitalWrite(LED_PIN3, HIGH);       
      Serial.print('C');         
      inByte = 0;     
    }
    
    if(inByte == 'c'){    
      digitalWrite(LED_PIN3, LOW);        
      Serial.print('c');        
      inByte = 0;     
    }
    
    if(inByte == 'D'){    
      digitalWrite(LED_PIN4, HIGH);       
      Serial.print('D');        
      inByte = 0;     
    }
    
    if(inByte == 'd'){    
      digitalWrite(LED_PIN4, LOW);      
      Serial.print('d');         
      inByte = 0;     
    }
    if(inByte == 'S'){    
      
      Serial.print('S');       
      status_bluetooth = true;
      sec = 0;
          
    }    
  } 
}
  

Hiç yorum yok:

Yorum Gönder