// Bluetooth Lesson Done by Motheeb Alkhashram, some code was inhereted from Manufaturer. //درس التحكم بالبلوتوث من المدرب مثيب الخشرم. تنويه: بعض من الكود مستخدم مصنع القطع // Software Serial Library //ارفاق مكتبة السوفتوير سيريال #include // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD) // تحديد منفذ 6 بأسم RXD #define RxD 6 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD) // تحديد منفذ 7 بأسم TXD #define TxD 7 // This is the pin for the connected LED //تحديد منفذ 9 باسم LED #define LED 9 // Setup pin 6 and 7 as TX RX for Software Serial //وضع منفذ 6 و 7 كمدخل و مخرج للتواصل بالبلوتوث SoftwareSerial blueToothSerial(RxD,TxD); /*----------------------SETUP----------------------------*/ void setup() { // Setup pin 6 to receive INPUT from the bluetooth shield //تفعيل منفذ 6 كمدحل من قطعة البلوتوث pinMode(RxD, INPUT); // Setup Pin 7 to OUTPUT data to the bluetooth shield // تفعيل منفذ 7 كمخرج إلى قطعة البلوتوث pinMode(TxD, OUTPUT); // Setup LED Pin as an OUTPUT // تفعيل منفذ ال led كمخرج pinMode(LED, OUTPUT); //Function to initiate the Bluetooth shield //نداء للدالة المعنية لتفعيل قطعة البلوتوث setupBlueToothConnection(); } //----------------------LOOP----------------------------// void loop() { // create a container for the char recieved. //تحديد حاوية لحفظ البيانات من البلوتوث int input = 0; // when characters arrive over the serial port... //عند استلام اي بيانات عبر منافذ البلوتوث if (blueToothSerial.available()) { // wait a bit for the entire message to arrive //انتظر لحظة لاستلام كل الرسالة delay(100); // read all the available characters //أقرأ كل البيانات المستلمة عن طريق البلوتوث while (blueToothSerial.available() > 0) { input = blueToothSerial.read(); // if recieved letter n then turn off LED //إذا استلم البلوتوث حرف n فأطفئ ضوء الLED if ( input == 'n' ){ digitalWrite(LED,LOW); } //if recieved letter y then turn on LED // إذا استلم البلوتوث حرف y فأشغل ضوء ال LED if ( input == 'y' ){ digitalWrite(LED,HIGH); } } } //repeat reading forever //اعد القراءة للأبد } //The following code is necessary to setup the bluetooth shield //هذه الدالة مهمة لتشغيل قطعة البلوتوث void setupBlueToothConnection() { //Set BluetoothBee BaudRate to default baud rate 9600 // وضع سرعة نقل البيانات بين البلوتوث والاردوينو الى 9600 blueToothSerial.begin(9600); //set the bluetooth work in slave mode //وضع البلوتوث كمستقبل blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth name as "Motheebtronic" //وضع اسم البلوتوث blueToothSerial.print("\r\n+STNA=Motheebotronic\r\n"); // Permit Paired device to connect me //السماح بالاجهزة المعرفة بالارتباط blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Auto-connection should be forbidden here // عدم السماح بالارتباط الاوتوماتيكي blueToothSerial.print("\r\n+STAUTO=0\r\n"); // This delay is required. // الانتظار لمدة ثانيتين للسماح للبلوتوث بضبط الاعدادات delay(2000); //make the slave bluetooth inquirable //وضع البلوتوث جاهز للتواصل blueToothSerial.print("\r\n+INQ=1\r\n"); Serial.println("The slave bluetooth is inquirable!"); // This delay is required. // الانتظار لمدة ثانيتين للسماح للبلوتوث بضبط الاعدادات delay(2000); //clean everything in the Serial buffer // مسح كل ما يوجد بحاوية البلوتوث لعدم استقبال بيانات خاطئة// blueToothSerial.flush(); }