Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <SoftwareSerial.h>
  2.  
  3. const int motor = 5;
  4. const int rxpin = 0;  //set pin 1 as data receiver (it will be linked to BT module's TXD pin)
  5. const int txpin = 1;  //set pin 0 as data transmitter (it will be linked to BT module's RXD pin)
  6. int c=0;
  7. SoftwareSerial bluetooth(rxpin, txpin);  //to write an easier code I gave "bluetooth" name to transmission and reception pins
  8.  
  9. void setup(){
  10. pinMode(motor,OUTPUT);
  11. Serial.begin(115200);  //Initialization of serial interface at AT mode baudrate
  12. bluetooth.begin(115200);  //Initialization of BT communication at AT mode baudrate
  13. }
  14.  
  15. void loop(){
  16.  
  17. if(bluetooth.available() > 0){  //if bluetooth receives some data
  18.   c = bluetooth.read();  //data are placed in a char variable so as to suit both letters and numbers
  19.   Serial.write(c);  //data are written in serial monitor
  20.     for(c>10){
  21.       digitalWrite(motor,HIGH); //motor vibrates for 300ms
  22.       delay(300);
  23.       digitalWrite(motor,LOW);//motor turns off
  24.       delay(500);
  25.     }
  26.   }
  27. delay(10);
  28. }