Make a Wireless Robot With an Android Phone

by CallMeSwal in Craft > Costumes & Cosplay

10011 Views, 51 Favorites, 0 Comments

Make a Wireless Robot With an Android Phone

MouseBot: A Wirelessly Controlled Robot
IMG_0246.JPG
IMG_0245.JPG
IMG_0244.JPG
Screenshot 2015-05-15 22.03.18.png

In this Instructable we're going to build a MouseBot.

The MouseBot is a small wireless arduino robot that you can control with a computer. It doesn't require a Wi-Fi module. Instead it uses an android phone to connect itself to the internet. The android phone also provides the operator with a video feed from the robots point of view.

I made this robot because I wanted to give myself a method to manoeuvre an environment from the ease of my keyboard.

What I really like about this project is you don't need many special parts besides and Arduino and motors. There is no need for bluetooth modules or Wi-Fi modules. The other required components, like a phone, wire, 9v battery, are generally things people have lying around.

*For this robot to work the Android phone and computer MUST be connected to the same Wi-Fi network.

How It Works

Screenshot 2015-05-15 22.03.18.png
IMG_0257.JPG
IMG_0261.JPG
Screenshot 2015-05-15 22.23.40.png

So let us understand how the system works.

The robot's "remote control" is a webpage hosted on the computer. On this web page, the user can click buttons that make the robot go forwards, backwards, and turn left and right.

When the user clicks a button, the webpage writes a command to a txt file that is also hosted on the server. This txt file is called keyLog.txt.

There is a phone mounted on the robot. A program on the phone is continuously GETing the contents of keyLog.txt and then forwarding the data, over a usb cable, to an arduino.

The arduino has a simple sketch that controls the drive motors connected to it.

-if w is inputed

go forwards

-else if s is inputed

go backwards

-else if a is inputed

turn left

-else if d is inputed

turn right

*All of the code for this project has already been made. You will just be required to modify ip addresses.

Materials

Screenshot 2015-05-16 14.17.08.png
Screenshot 2015-05-16 14.17.26.png
Screenshot 2015-05-16 14.18.25.png
IMG_0247.JPG

Robot

  • arduino uno
  • android phone
  • wire
  • switch
  • 9v battery
  • 9v battery pack (i scrapped together a battery pack by taking apart a dead 9v battery)
  • usb OTG Cable(You need this to connect your phone to the arduino. You can pick this up at any electronics shop for a few bucks)
  • 2 continuous rotation servos(This is for the drive train. Any small motors that you can control with PWM will do)
  • 2 small wheels
  • castor wheel
  • android phone
  • computer

Phone Apps

  • IP Webcam (We use this app to send video feed from the robot to the computer)
  • Protocoder (We run our program on this app. It's not on Play Store so you have to download it off of here)

Computer Software

Build the Robot

IMG_20150516_144037[1].jpg
IMG_20150516_144049[1].jpg
IMG_20150516_144112[1].jpg
IMG_20150516_144121[1].jpg

Let us put together the robot now. We'll do the wiring in the next step.

The structure of your robot can vary, so feel free to be creative with it! The positioning of most of your components doesn't matter. Just make sure to have a castor wheel attached to one end of your robot and 2 drive train motors attached to the other end.

Grab a piece of wood or plexi, and mount your arduino, breadboard, drive train motors. I ended up Velcroing my arduino and hot glueing my servos and breadboard. I also glued a castor wheel to the other end of my robot.

Hot glue your wheels to your servo. Try to get your wheels as centred as possible.

Connect your battery pack to your breadboard. I soldered a little switch between my positive lead and the breadboard.

Plug your OTG cable into your USB AB cable and then plug in your USB AB Cable into your arduino.

I wrapped my cable up with tape and then I attached it to the robot with an elastic.

Make a Phone Holder

IMG_20150516_144121[1].jpg
IMG_20150516_145247[1].jpg
IMG_0002.JPG

You're going to want add something to your robot that holds your phone in place.

You'll also want to make it easy for you to attach and remove your phone.

I glued two sets of bricks to hold my phone in place.

I also plugged in a 9v into the battery pack and tied it to the bricks with an elastic.

Wiring the Robot

MouseBot Circuit.PNG

Wire it up

*Signal wire on the left motor should be connect to port5 and signal wire on right motor should be connected to port9

Upload Arduino Code

Congratulations! You have finished the physical portion of this robot. All that's left is uploading the code.

Upload this sketch onto your arduino.

After you upload the code, you now have a robot that you can drive around while tethered to the computer.

Downloads

Test Your Robot

Screenshot 2015-05-16 16.04.57.png

Before we make the robot wireless, let us drive it around while wired.

Connect your arduino to a computer with a USB AB cable. Then open the arduino Serial Monitor.

Now enter the commands w, a, s, d, and spacebar. The robot should move forwards, backwards, turn left, turn right, and stop.

If the servos don't spin at all, check the battery voltage. Make sure that the servo's black wire is connected to the arduino's ground and the battery's ground. Ensure that the signal wires are connected to the correct pins on the arduino.

If the controls are inverted you may have to invert values in the arduino code.

If you have any problems that you can't solve, comment below.

The arduino serial terminal doesn't provide the best interface to drive your robot around. I recommend you install PuTTY and use that serial monitor to play with the robot.

http://www.chiark.greenend.org.uk/~sgtatham/putty/...

Install MAMP

You need some sort of server software that can host a webpage. (MAMP, WAMP, Uniserver, etc)

I have found that MAMP is the easiest server software to use.

https://www.mamp.info/en/downloads/

Downloads

Make the Remote Control (Webpage)

Now we need to make a remote control that can drive the robot wirelessly.

Our remote control is going to be a webpage hosted on our server. The user can go onto this webpage and click buttons that control the robot.

When the user presses a button the webpage writes a command to a text file, also hosted on the server, called keyLog.txt. Since your phone is connected to the internet, it can read the contents of keyLog.txt and forward the command(contents) to the arduino.

Attached is the code and markup for the webpage. We need to make one change.

Open the file index.html and find the line: iframe src="http://192.111.1.111:8080/"

You must change the ip address to your phones ip address. So if your phone's ip address is 192.333.3.333 this line of code would now be: iframe src="http://192.333.3.333:8080/"

You can figure out your phone's ip address by installing IP Webcam. The app automatically gives you your ip address after you open it.

https://play.google.com/store/apps/details?id=com....

Save the Remote Control (Webpage)

Screenshot 2015-05-16 16.42.15.png

Go to program files, open MAMP, and then open a folder called htdocs.

You must save all of the files, from the last step, in this location. Make sure index.html has been edited first.

Now start a Mamp server and type localhost into your web browser. You should be greeted with the pictured page. If localhost isn't loading try checking Mamp's port number

Click on the left side buttons. Then type localhost/keyLog.txt into a new tab. Make sure the contents of keyLog.txt changes as you click on different buttons.

If you open IP webcam on your phone and start a server, a video feed should pop up on the webpage. If a video feed doesn't pop up make sure the IP address and port number that the app gives is the same one in index.html

*The right side buttons don't do anything yet. They're just there in case you want to add more functionality to the robot.

Install Protocoder on Your Phone

Congratulations! You now have a remote control and a robot that you can drive around. Now we just need to connect the two by adding a program to your phone.

Protocoder is the app that runs our program on the phone.

You can download it, on your phone, here:

http://www.protocoder.org/

Edit Phone Code

Screenshot 2015-05-16 17.03.12.png

Here is the code that GETs the file keyLog.txt from your computer and forwards it to the arduino.

You have to make one edit.

Find the line: network.httpGet("http://192.111.1.111/keyLog.txt", function(status, response) {

Change the ip address to your computer's ip address

So if your computer's ip address is 192.333.3.333 the line would now be: network.httpGet("http://192.333.3.333/keyLog.txt", function(status, response) {

You can find your computer's ip address by opening CMD and typing ipconfig

After you have edited the phone code, make a new project in Protocoder and paste the edited code.

Drive the Robot!

IMG_0004.JPG

There is procedure to getting the robot up and running.

Run IP Webcam on your phone

Start a Mamp server and open up the webpage.

Attach your phone to the robot and run the protocoder program

Finally, turn your bot on and drive it using the webpage.

Future

Eventually I want to turn this robot into Skype on Wheels. I want to give two people the ability to talk and interact with each other using this robot.

If you guys do end making a MouseBot, post a video in the comments. I would love to see them.

I added some extra buttons to the remote control page, so take a shot at adding some extra functions to your robot.

In the end, just make sure to have fun!