BT Bot Control & IPCam Bot – Android App to control Arduino Robots
BT Bot Control is an Android application that allows you to remotely control a micro controller-based robot using Bluetooth (i.e. Arduino). It also allows you to (optionally) view a video stream from an IPCamera mounted to your robot. This could be any type wireless IP camera or phone that has the ability to broadcast a video stream/images to the web. Example Foscam, Ai-Cam etc. If you are looking to control your robot over WiFi, check out WiFi Bot Control.
- Use Joystick via finger movement, or the orientation sensor on your device. (default is Joystick mode).
- Ability to poll and display sensor and other data from your micro controller.
- Supports 8 individual commands via Command Buttons. 4 on by default. 4 more can be turned on in the Settings section.
- Sends the x/y coordinates as positive and negative integers based on 4 quadrants of the joystick. Data is sent via Bluetooth and can be parsed to set both direction and velocity. (sample code below)
- Coordinates are generated as X+/- and Y +/-. These are packaged and sent in the following format sX=val,Y=vale i.e. sX=75,Y=-55e where ‘s’ indicates the start and ‘e’ indicates the end.
- Command button values are packaged and sent in the following format: sC=[val]e i.e. sC=2e where ‘s’ is the start, ‘c’ indicates the a command button as pressed, ‘2’ is the value and ‘e’ indicates the end.
- Configurable Bluetooth packet send interval – used to set the speed (quantity) of packets sent. Default of 200ms works well.
- Shows video stream of IP Camera mounted to robot. (see FAQ below for important tips on getting your IP Camera working)
- Configurable camera URLs (3). Remembers last camera connection for easy re-connect.
- Configurable Bluetooth connections. Remember last Bluetooth connection for easy re-connect.
- Sample Arduino Sketch provided (below).
- Screen auto re-sizes for smaller phones.
- Supports any micro controller that can parse Bluetooth data (bluetooth module required).
- Should be compatible with other Bluetooth / Arduino modules such as the BLEduino, RFduino, Arduino Bluetooth Shields the Cortado, and many others. Please drop me a line if you get it working with other BT devices and I will update the list. Update (2015) – lately, a number of fully integrated Arduino/Bluetooth micro controllers have come to market via Kickstarter. This app is not particular. As long as the controller / bluetooth module can connect to your Android smartphone, this app will work.
Note on Lite version: The Lite version is a fully functional version. However, Bluetooth data will be sent as ‘9’s. i.e. s9,9e and c9e which will provide you with enough to determine if this app is right for you. If you like BT Bot Control, the Pro version has full functionality enabled with proper data, and can be yours for less than the price of a coffee. Also, you won’t be pestered by that start-up message either! We hope you agree that the features and functionality provided are well worth the pocket change. 🙂
Note on Bluetooth: The control distance is dependent on a number of factors including; your Bluetooth device range, battery power, obstacles etc. Typical distance for Bluetooth is 10 meters for most Bluetooth modules. However, higher classed BT modules could extend the range.
Get BT Bot Control:
If you are an existing BT Bot Control user, drop me a line on your project so I can feature it here.
Arduino Sample Sketches:
BT Bot Control – Recent Versions:
This version includes sample code to demonstrate sending data from the Arduino to BT Bot Control (you must have v 5.1.0 or later). It uses a Timer (library here) to call sending data every second (recommended).
- BT Bot Control Arduino Sketch (for BT Bot Control v5.1.0 or later)
BT Bot Control – Earlier Versions prior to v 5.1.0:
- Default Mode Joystick Sketch: BTBotControl12DefaultModeJoystick
- Simple Mode Joystick Sample Sketch: BTBotControl12SimpleJoystickSample
Note: For this project, I used a Digispark (Arduino-based micro controller). This sample sketch is targeted for a Digispark (ATTiny85), but was also tested on an Uno, so it should work for most Arduino’s. If using an ATTiny, remove any Serial.Print statements. Also watch the size of the sketch as there are limitations on the ATTiny85.
Displaying Sensor Data in BT Bot Control:
BT Bot Control (version 5.1.0 (14)) now has the ability to display sensor and other data from Arduino. Before getting into specifics, note that this feature is experimental due to the nature of both the joystick and sensor data using Bluetooth at the same time. Adding sensor polling may slow the robot’s response to joystick movements. Be sure to test this feature before implementing.
On the Arduino side, you need only add Serial.Print() commands to print sensor / data results to the serial port. The data also requires a start and end delimeter. For BT Bot Control, the “>” (start) and “<” (end) delimeters are uses. If you are passing more than one data item, each much be separated by a pipe character “|”. A simple single item example would be Serial.Print(“>MyData<“); This would display “MyData” once BT Bot Control has been configured. When enabled in BT Bot Control, the sensor / data information will show at the bottom of the main interface.
In BT Bot Control, go to Settings, check the box for “Enable Sensor / Data Polling“. This will reveal other options as follows:
- Manual / Timer base polling. In manual mode, you have to click the refresh icon that will be shown beside the data. Timer-based polling will automatically poll ever X seconds. The frequency can be configured by moving the slider (ranges from 1-30 seconds)
- Data Element Titles. This allows you to give each data element a title. If left blank, the app will use default values. i.e. Result =. To add titles, separate each item by a comma. i.e. Temperature =, Humidity =. Save the changes when done. Note that each title will be assigned to each data item parsed in the order it was passed. (example below)
Example Arduino code:
//Include and initiate the Timer library in the header section
#include “Timer.h” //get it here: https://github.com/JChristensen/Timer
//in the void Setup() section add the below code:
int sendData = t.every(1000, doDataSend);
//At the beginning of void loop() add:
t.update(); //timer for sending data
//The below flag is included in the code to stop data from being sent when data is being received from the joystick. It is highly recommended that this is include. The value is set to true in while(Serial.available() > 0) and set back to false after the motors are driven or turned off.
receivingCommands = true;
//Here’s a sample showing data being sent. Note that passed data must begin with a “>” and end with a “<” delimiter. All data sent via Serial.print within these delimiters will be passed to BT Bot Control.
//TESTING PRINTING SENSOR DATA TO BT BOT CONTROL
Serial.print(“>”); //Start of String
Serial.print(“|25° C”); //degrees = ALT + 0176
Serial.println(“<“); //End of Content
//END TESTING PRINTING SENSOR DATA TO BT BOT CONTROL
Based on the above example there are 2 data elements being sent. If you did not configure any titles in Data Element Titles, the results would look like this: Result = 75° Result = 45% If you added two titles; Temperature =, Humidity =. You would get Temperature = 75° Humidity = 45%
Note: During testing, it was observed that a sketch that ran very fast (i.e. with little delays), would not render data well to BT Bot Control. If this happens, try adding delay (100); or more to your code. Also note that this will affect the joystick commands and how the robot is driven. Alternatively, you can get creative by having the sensor data only send every x cycles (i.e. if your delay is 10 ms, put the sensor data print commands in a function and call them every X iterations. I suggest having them sent every 1 second.
Note that any Serial.Print command that is placed within the “>” and “<” will be parsed by BT Bot Control and displayed.
Bluetooth Wiring for Arduino (Nano)
BTBotControl - FAQ
Although the function of both these apps is the same, there are some underlying differences that are important to making your decision on which route to go. In general, BT Bot Control is faster in getting joystick commands to the robot. This is inherent in the design as it uses a direct link over Bluetooth between the Android device and your robot. WiFi Bot Control is slower as the commands have to a) share traffic with your WiFi network (this includes your IP camera stream), and b) are first sent to a server, and then to the robot. This is mitigated somewhat with the introduction of WiFi-enabled Arduino devices such as the Spark Core and Adafruit CC3000). However, if you do not have one of these devices, you would need to use a server with a webserver. BT Bot Control is also easier to set-up and configure. Once you have a Bluetooth connection, the sketch can interpret the commands. With WiFi Bot Control, there is the intermediary JSON configuration on the server side.
If you are having issues viewing a direct video stream from your IP camera (i.e. http://mycamera.com/videostream.cgi is not working), have a look at this site to see what varying modes your IP Camera has (be sure to search for your camera). If none of these work, you can setup a webpage to auto-refresh your camera in snapshot mode and then use the URL to the website in BT Bot Control / WiFi Bot Control. First, you must find the URL that your camera uses to view a snapshot.
- You need a website – either a personal or access to a remote webserver / website where you can put some files. In this case, we will assume you have a personal webserver and use the following URL www.yoursite.com.
- Note: If you are setting this up on an internal server, you can refer to internal IP addresses (i.e. 192.168.x.x). However, if you are hosting the page externally, you will have to a) enable port forwarding from an external IP to your camera and b) refer to the camera (within the file below) by your network’s external IP and port #. For this example, all references will assume you have a personal webserver and the IPs are internal.
- Download these files and place at the root of the website you want to use.
- Open default.htm.
- You will need to change only the highlighted parts to the full URL that will be used to take a single snapshot image from your IP Camera. Before moving on, be sure that you are able to see a snapshot within your PC’s browser window.
- Once complete, call the www.yoursite.com/default.htm file in your web browser (not BT Bot Control / WiFi Bot Control). Make sure you see the snapshot image and it should be refreshing. The refresh rate is configurable at the bottom (currently set to 100 ms). If it works here, then you can plug this URL into BT Bot Control / WiFi Bot Control and you should be able to see the video stream.
- Note – don’t expect fluid video here folks. This is a crude approach to getting video streaming working in these apps. Also note that this is not a limitation of BT Bot Control / WiFi Bot Control but rather the web control implementation from Android.
- You have an IPCamera that is configured and can be viewed in your web browser.
- You have the URL, username and password (if necessary) to access the IP camera.
- If you are viewing your IP camera outside your network, you will have to setup a dynamic DNS service and/or port forwarding to remotely access it.
- Click the Camera settings icon in the menu and setup your camera URL (see below)
- Enter the camera URL, click add, and check the button beside the camera you want to view.
- You can enter and store up to 3 cameras.
If you are having troubles setting up your IP Camera,the following are some approaches that may (or may not) work for your camera. Some of these are specific to certain camera manufacturers:
1) Generic interface to Foscam IP Cameras. You could build a webpage that displays the camera and then refer to the webpage URL in WiFi Bot Control / BT Bot Control. Once done, then use the URL you use to access the webpage in the apps.
3) Check this site and search for your camera. It will show you various ways to get access to direct stream and snapshot modes for IP Cameras
- Before starting BTBotControl, make sure Bluetooth is turned on.
- Make sure the Bluetooth device you are connecting to is powered on and you have previously paired the Bluetooth unit to your Android device.
- Open BTBotControl and click the Bluetooth Settings icon (A). You will see a screen similar to below. Select your Bluetooth device.
- After a few seconds, your Bluetooth device should be connected, and you should see a message indicating this.
- The main window will update by showing the MAC address of the connected Bluetooth device (below the camera viewing window). The icon for Bluetooth Connect (B above) will also change (arrows facing out).
- To disconnect the Bluetooth device, click the Bluetooth Connect/Disconnect icon (B above). After it is clicked, the Bluetooth status will be updated to show “disconnected” (below the camera viewing window) and the Bluetooth Connect/Disconnect icon (B) will change to an icon with arrows pointing in.
- To quickly reconnect, click the Bluetooth Connect/Disconnect icon (B above).
Posted in: BTBotControl - FAQ
If Bluetooth is disabled when you open BT Bot Control, the app will ask you if you want to enable it. Click yes to enable Bluetooth. Your Android phone will ask you if you want to proceed. Click Yes. If, Bluetooth still does not enable, check your Airplane Mode settings. If Airplane Mode is enabled, it will restrict the ability to turn Bluetooth on. You must disable Airplane Mode to turn Bluetooth on.
Posted in: BTBotControl - FAQ
You can verify that BTBotControl is sending data over Bluetooth by using an application such as Putty. You can do this by connecting your Android device to your computer/laptop over Bluetooth. Before using Putty, make sure you have paired the two devices and they are connected. To configure putty, setup a serial connection pointing to the Com Port (Serial Line) that your Bluetooth device/dongle is connected to. Typical speed settings are 9600 (Baud). Once configured, open the connection and then connect BTBotControl to your computer. Once it is connected, you should see coordinate / command data stream through when using the controls on BTBotControl.
If you have verified that data is being sent using Putty, but something still appears to be wrong in the Sketch. Try using Serial Print statements within the section of code where Bluetooth data is parsed and watch the response in the Arduino IDE Serial Monitor.
Posted in: BTBotControl - FAQ
There are two joystick modes. Default and Simple Joystick:
*** Remember – the Free version will send the number 9 for all joystick (Default/Simple) and Command Buttons. The Pro version will send actual values.
Default Joystick Mode:
When you move the ball around, coordinates are generated as X+/- and Y +/- and can be used to interpret both velocity and direction. These are packaged and sent in the following format: sX=val,Y=vale i.e. sX=75,Y=55e where ‘s’ indicates the start and ‘e’ indicates the end. In this mode, when you press a Command Button, values are sent in the following format: sC=[val]e (i.e. For Command #2 sC=2e is sent) where ‘s’ indicates the start, ‘C’ indicates it is a command button, ‘2’ is the value that you want to parse and ‘e’ indicates the end. These values can be parsed to have your robot move and perform additional tasks. (sample Arduino code provided at link below)
Simple Joystick Mode:
In Simple mode, you tap the arrows which generate single character values depending on the arrow you tapped (i.e. the top arrow sends U). Values generated are: U (up), D (down), L (left), R (right). Tapping the center of the joystick sends an S value (stop). Tapping any of the command value sends the respective command number. i.e. tapping Command Button 3, sends 3. In this mode, your micro-controller code can be simplified as need only parse single character values.In this mode, when you press a Command Button, values are sent as single characters in the value of the Command Button. i.e. If you press Command Button 3, the value 3 is sent. (sample Arduino code provided at link below)
You can change between Default and Simple modes in the Settings section.
There are two example Arduino programs – one for Default mode, and one for Simple mode. They have routines built into them to parse the values being sent over Bluetooth and performing motor actions.
Posted in: BTBotControl - FAQ
Check out BT Bot Control on Google Play for the most recent updates.
V5.0.7 – April 16 2013:
:: Pro Version: Fixed issue with Default Joystick and data being returned from joystick movement. Only affects small screen devices.
V5.0.6 – April 12 2013:
:: New: Added Simple Joystick Mode. Allows for simple joystick control using arrows. Sends single char data via Bluetooth as (U,D,L,R). Command Buttons send data as (1 to 8).
:: Cleaned up the Help page content.
:: Added Simple Joystick Mode info.
v5.0.5 – April 6 2013 :
:: NEW! Added option to turn on additional command buttons (5-8). Will send values as numbered. i.e. Command button 5 sends sC=5e. The enable them, go to the Settings section.
:: Discovered that an “emergency stop” on the joystick is necessary when in Orientation Sensor mode. When in this mode and controlling your robot, you may need to change a setting, add a camera etc. Tapping the joystick will temporarily disable the Orientation Sensor control and bring the Joystick to 0,0 so your robot does not move. Tapping the joystick again will turn the Orientation Sensor back on. Note – this only works when the Orientation Sensor is enabled in Settings.
v5.0.4 – April 3 2013:
:: Updated Bluetooth Packet Delay component. New slider. Better notifications.
:: Updated notifications for Joystick Touch Down Action.
:: Added ability to switch between joystick or orientation sensor to control the joystick. You can now tilt/roll the phone to control your robot. Note – Joystick Touch Down Action is disabled when this is on.
:: Cleaned up notifications.
:: Improved joystick response.
Posted in: BTBotControl - FAQ
Video: BT Bot Control In Action
Video: BT Bot Control Bluetooth Connection Testing
Pictures of CamBot:
Check out Umur’s Omnidirectional Bluetooth Controlled Robot:
Check out Jon’s Place for a very cool 3D printed roboot.