Bluetooth is the standard for short-range, wireless communication between various electronic devices such as mobile phones, tablets, PC, headphones and even pressure cookers, which allow for adjusting the cooking timer and temperature through an app via Bluetooth.
To use this example, we will connect our robot to a mobile application and control the motors through the application. For this, we need to download VEELER application from Google Play Store (app is available for Android mobiles). Install the application and it is ready to use.
Bluetooth is a serial communication and we need to configure the pins on micro:Xbot to communicate with a mobile device. We can either use hardware serial pins (Tx, Rx) or any available pins can be configured as software serial pins.
Since we are using a FTDI programmer which uses Hardware Tx and Rx pins, we will use Pins D2 and D3 as software serial pins.
To connect mobile device to micro:Xbot, open Bluetooth services on your mobile phone and pair the module (HC-05) with password 0000 or 1234.
Upload the below program, Open Serial Monitor, Open VEELER Application, Click on HC-05 and start communicating with the board.
/* Bluetooth Control: Use a bluetooth module to wirelessly control the board At VEEROBOT, we invest time and resources providing this open source code, Please support VEEROBOT and open-source hardware by purchasing products from us @ http://veerobot.com ----------------------------------------------------------------------------- You are free to redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. See <http://www.gnu.org/licenses/>*/#include<SoftwareSerial.h>#include"config.h"SoftwareSerialbtSerial(3,2); // RX, TXchar cmd =0; //Variable for storing received datavoidsetup() {Serial.begin(9600); // initialize serial connectionbtSerial.begin(9600); // initialize bluetooth connection}voidloop() {decodeserialcommand();}voiddecodeserialcommand() {if (btSerial.available() >0) { cmd =btSerial.read(); //Read the incoming data and store it into variable dataSerial.println(cmd); //Print Value inside data in Serial monitorswitch (cmd) {case'W':Serial.println("Up Button");break;case'X':Serial.println("Down Button");break;case'A':Serial.println("Left Button");break;case'D':Serial.println("Right Button");break;case'Q':Serial.println("Top Left Button");break;case'E':Serial.println("Top Right Button");break;case'Z':Serial.println("Bottom Left Button");break;case'C':Serial.println("Bottom Right Button");break;case'S':Serial.println("Stop/Center Button");break;case'T':Serial.println("Down Arrow");break;case'Y':Serial.println("Up Arrow");break;case'R':Serial.println("Red Button");break;case'G':Serial.println("Blue Button");break;case'B':Serial.println("Green Button");break;case'O':Serial.println("White Button");break;case'L':Serial.println("Gray Button");break;case'M':Serial.println("Buzzer Button");break;case'1':Serial.println("Manual Key");break;case'2':Serial.println("Autonomous Key");break;case'3':Serial.println("Line Follower Key");break;default:break; } }}
Click on the buttons on the app and the respective details are printed on the serial monitor.