Arduino robot controlled from an Android phone via Bluetooth
This is a differential steering robot that can be controlled from an Android phone via Bluetooth. The robot’s “brain” is Arduino Uno compatible board (an “Arduino on a breadboard”). The robot uses a JY-MCU Bluetooth module for communication with the Android phone. A custom Android app, created with the MIT App Inventor 2 essentially acts as a remote control, sending commands to the Arduino that tell the robot to move forward, reverse, stop or rotate.
The robot also has two ultrasonic sensors (one mounted on the front and one on the back) that are used for obstacle detection. If you try to drive the robot into a wall using your phone remote, the robot will overwrite that command and will stop when it detects an obstacle closer than 10 cm.
The communication between the phone and the Arduino board is very basic at the moment. When you press a button on the phone, it sends a byte over the Bluetooth connection (currently the numbers 0 to 5 are used). The Arduino sketch reads the data on the serial port and acts based on the command (0 is stop, 1 is move forward etc.). This can be easily extended and can go both ways. For example, we can easily display the data from the two ultrasonic distance sensor on the phone.
- Arduino Uno (or compatible board)
- JY-MCU Bluetooth Module
- 2 Servos modified for continuous rotation
- 2 HC-SR04 ultrasonic sensors for obstacle detection
- Wheels (salvaged from a printer)
- Acrylic base
- 2 casters
- Android phone
- 9V battery with case for the Arduino
- 5 AA batteries and case for the servos and other components
- Screws, zip ties and some hot glue to keep it all together
- Protoboard & wires to connect the electronic components
- A couple of resistors used to make a voltage divider (shift down 5V signal from the Arduino to 3.3V)
Note: You may see a character LCD screen on the robot that is controlled from my “Arduino” through a shift register. Currently the LCD just shows the readings from the two ultrasonic sensors and is not needed for this application. It is just a side project / experiment to get an LCD salvaged from a trashed phone working with Arduino and I just used the same robot platform for the test.
- left servo signal to Arduino pin D2
- right servo signal to Arduino pin D4
- front HC-SR04 sensor echo and trigger pin connected to Arduino pin D6
- back HC-SR04 sensor echo and trigger pin connected to Arduino pin D7
- JY-MCU TX pin to the Arduino pin 12 (used as RX pin in SoftWareSerial)
- JY-MCU RX pin through voltage divider and to the Arduino pin 9 (used as TX pin in SoftWareSerial)
- all grounds connected together
- HC-SR04 sensors and the JY-MCU are powered from regulted 5V line
- the continuous rotation servos are powered from a 5 rechargeable AA battery pack
The Arduino sketch and the App Inventor 2 project file can be found on GitHub:
Disclaimer: This is a hobby for me and I am a noob. I am happy to share the code, as I learned from others who did the same, but you use it at your own risk.
The key components of the application have been already covered in earlier articles:
- Using Android Mobile to control Arduino (by kerimil on the Arduino Forums)
- Differential steering with continuous rotation servos
- Connecting an Arduino Uno to an Android Phone via Bluetooth
- Using Software serial library for Bluetooth communication
- Simple Android apps with App Inventor 2
- How to create an Arduino-compatible minimal board (by Nick Gammon)
Update (January, 28th, 2014): Posted on the awesome “Let’s make robots” community:
Tried last weekend easy and fun!
Thanks for the post.
Hye, I want to make a project like this but with using the accelerometer sensor built-in the android phone. I just wondering how the Arduino will read the data from the sensor? Is it in serial communication like this project or not? How about the programming?
This should be easily doable, even with AppInventor. If you read the AI2 documentation on sensors, you can see how to read the data from the built in accelerometers on the phone. Maybe worth checking out the features of the Orientation sensor as well: http://ai2.appinventor.mit.edu/reference/components/sensors.html
Then you can send the raw data to Arduino, over the same BlueTooth connection using serial, or do some processing on the phone and send heading info only.
Nice work! We built a similar project. However, we installed an Android device onto a RC car and used an IOIO board instead to control it autonomously. Here is the preliminary result:
Very cool, and much more advanced that what I have here! Thanks for sharing your project! Here is the link to the write-up, for the benefit of other who stumble into this post: http://www.socsci.uci.edu/~jkrichma/ABR/
I dabbled a bit with OpenCV, but had trouble getting to work on my older smartphone. Got better results with the Raspberry PI. This is inspiring me to try again…
I compiled the given arduino code but i got these errors:
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:399: error: 'PCICR' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:402: error: 'PCMSK2' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:402: error: 'PCMSK0' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:402: error: 'PCMSK1' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:417: error: 'PCMSK2' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:417: error: 'PCMSK0' was not declared in this scope
R:\arduino-1.0.5-r2\libraries\SoftwareSerial\SoftwareSerial.cpp:417: error: 'PCMSK1' was not declared in this scope
Hi Vatur, the code from the example here https://github.com/42Bots/ArduinoBlueBot/blob/master/BlueBotSonar/BlueBotSonar.ino compiles fine on my Arduino IDE (1.0.5 with the SoftwareSerial library installed). Not knowing more about your set-up it is difficult to say where the problem is. You may want to visit this thread on the Arduino forum – seems like the same error as yours: http://forum.arduino.cc/index.php?topic=223830.0.
I have arduino servino when i am compiling code with arduino uno its compiled and generates .hex file iam burning into Atmega8 but not working
Did you check the link to the Arduino forum thread I posted above? Apparently there compatibility issues with the Atmega8 boards and the SoftwareSerial library. Looks like the ATmega8 doesn’t have Pin Change Interrupt hardware support and SoftwareSerial uses that for receiving data. Try compiling and running one of the example sketches that come with the SoftwareSerial library, to confirm it yourself. You might need to switch to an ATmega328P based board, or use a different approach / library, if you need your RX / TX pins free while using Bluetooth.
Could you give me the circuit diagram of your assembled bot please? I am having a hard time assembling my bot.
Please could you provide me a detailed circuit diagram so that I’m able to understand how exactly the connections are to be done? Or if you could send me a picture of your own assembled bot with all connections properly visible? It would be of great help since microcontrollers is not my strongest subject.
Please respond asap! It will be really appreciated.
Thank you! 🙂
Hi Eshan, I do not have a clear picture, as there are far too many wires in little space. I would suggest to start by getting each component working individually and then putting them together. You can follow the links at the bottom of the post to see how the servos are set up and how to hook up the Bluetooth module.
Could you at least tell me how the connections are to be made? As in, could you tell me which ports/pins of each component are to be connected where? I’m sorry I’m asking so many questions but I’m a total amateur at this. I really need basic, step wise guidance.
Hi Eshan, I have listed the key connections in the post itself. I also put links to my posts with getting the basics BlueTooth connectivity working. Sorry, I did not make a detailed circuit diagram beyond that.
Not an issue, Stan. Thank you so much for the prompt reply. I will get back to you if I face any troubles.
can please help me for making program which will run the robot having msp430 processor.. im not getting the programming for Bluetooth..plz help me.
Hi Rose, unfortunately I have no experience with the TI msp430 processor.
Im runnning a very similair app , the only problem is that when i press the app buttons it gives me a broken pipe error . if i manually send the same signals to the arduino then the circuit works . any help ?
I have problems to understand the connections and pins. Can I use this code with Arduino Mega2560, and which pins I should use. I think I understand it right when you use the SoftwareSerial, because the Uno does not have enough serial (Rx and Tx) pins like the Mega? Can i use the SoftwareSerial on Mega, or should I directly wire the BT modul to Rx and Tx pins?
What modifications to your sketch would be needed for dc motors?
Bluetooth control Arduino is a nice project