RC Rover Project (Old Post from 2014)
Back in January 2014 I built a BlueTooth controlled pan & tilt mechanism to attach to an RC Crawler. The primary use was to do some investigating in a crawl space under my father’s house. The project worked well and was a lot of fun to build. Recently a few people have asked through the videos related to the project on YouTube so I’ve rebuilt the original article and updated the information on the YouTube videos.
For the RC Rover project I needed a way to control the pan and tilt of the camera wirelessly. I decided to go with Bluetooth using a PS3 controller. To do this the following is required:
- Arduino board – I’m using an older Duemilanove that I’ve upgraded to an ATmega328p from the original ATmega168. An UNO would be a good board if you need to buy one
- USB Host Shield – While the Sparkfun board will work I prefer the SainSmart board
- Bluetooth Dongle – There are several that are said to work but after doing some research I found these to be the most consistent
- Sony PS3 Controller – This must be a Sony made controller, aftermarket models will not work
- You’ll also need the USB Host 2.0 Library found here to go along with the Arduino IDE.
The next step I had a few issues with. My bluetooth dongles did not come with their MAC address printed on them so I had to find them using a computer. I was not able to use my Macs to find the MAC addresses even though I could fully use the dongle. I ended up having to use a Windows laptop to find the MAC address. So use whatever method you need to find the MAC address of your bluetooth dongle then continue on.
Load the USB Host Library and open up your Arduino IDE. Open the example file included with the USB Host library called PS3USB. Upload this to your Arduino and open the Serial Monitor. Connect your PS3 controller to the USB Host Shield with a USB cable and make sure everything is working before continuing on and setting up bluetooth. You should see output for all of the PS3 controller’s buttons.
Once you know your USB Host shield and PS3 controller are working you can move on and setup the bluetooth. Open the example file under USB Host Shield called PS3BT. You will need to comment out the line that reads PS3BT PS3(&Btd); and uncomment the line under it. This is where you will put the MAC address of your bluetooth dongle. A MAC address is made up of 6 sets of 2 digits which looks like this:
1 |
00:15:83:0C:BF:EB |
Use your MAC address and replace the characters after each “0x” as shown below:
1 |
PS3BT PS3(&Btd,0x00,0x15,0x83,0x0C,0xBF,0xEB); |
Now verify and upload the sketch with your PS3 controller connected via USB, don’t insert the dongle into the USB Host shield yet. Once the controller’s light shows that it’s connected remove the USB Cable, insert the Bluetooth dongle, and then press the reset button on your Arduino. Once it’s back up press the connect button on your PS3 controller and you should be good to go. Once again open the Serial Monitor to verify everything is working. *Note: You may need to repeat this connection process if your PS3 controller won’t link via Bluetooth. I found I had to do this about every 5th time I powered everything up to work on the project.
That’s it for the connection, now you can use this part of the sketch to build your own project. I’m including the code I used on the RC Rover Project here as an example if you’re building something similar. This sketch is setup for the following:
- Right analog stick controls camera pan & tilt on digital pins 3(tilt) and 5(pan)
- Triangle button turns LED circuit 1 ON (digital pin 6)
- Circle button turns LED circuit 1 OFF (digital pin 6)
- Square button turns LED circuit 2 ON (digital pin 7)
- Cross button turns LED circuit 2 OFF (digital pin 7)
My sketch is also commented to show which lines need to be modified to change the operation from Bluetooth to USB connection.
RC_Rover Arduino .ino Download
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
/* RC Rover Project - Brad Arnold (borntoventure.com) You must have the default Arduino Servo Library and the USB Host Shield 2.0 Library. Both can be found at http://borntoventure.com/?p=71 if needed. This sketch has the necessary lines commented out and instructions on how to modify it for USB communication instead of Bluetooth. USB is much easier for testing and initial setup compared to Bluetooth. */ #include <PS3BT.h> //Comment this out for USB instead of BT //#include <PS3USB.h> //Uncomment this for USB instead of BT #include <Servo.h> USBUsb; BTDBtd(&Usb);//Comment this out for USB instead of BT // The next line contains the MAC Address of the BT dongle, change to your dongle's MAC Address PS3BTPS3(&Btd,0x00,0x15,0x83,0x0C,0xBF,0xEB);//Comment this out for USB instead of BT //PS3USB PS3(&Usb); //Uncomment this for USB instead of BT Servoservo1;//Pan Servoservo2;//Tilt constintledC1=6;//LED Circuit 1 constintledC2=7;//LED Circuit 2 voidsetup(){ Serial.begin(115200); if(Usb.Init()==-1){ Serial.print(F("\r\nOSC did not start")); while(1);//halt } Serial.print(F("\r\nPS3 Bluetooth Library Started")); pinMode(3,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(7,OUTPUT); servo1.attach(3);//Tilt servo2.attach(5);//Pan } voidloop() { Usb.Task(); if(PS3.PS3Connected||PS3.PS3NavigationConnected){ servo1.write(map(PS3.getAnalogHat(RightHatY),0,255,0,180));//Pan servo2.write(map(PS3.getAnalogHat(RightHatX),0,255,180,0));//Tilt } else{ servo1.write(110); servo2.write(90); } if(PS3.getButtonClick(TRIANGLE)){//Turn LED Circuit 1 On digitalWrite(ledC1,HIGH); } if(PS3.getButtonClick(CIRCLE)){//Turn LED Circuit 1 Off digitalWrite(ledC1,LOW); } if(PS3.getButtonClick(SQUARE)){//Turn LED Circuit 2 On digitalWrite(ledC2,HIGH); } if(PS3.getButtonClick(CROSS)){//Turn LED Circuit 2 Off digitalWrite(ledC2,LOW); } if(PS3.getButtonClick(PS)){ PS3.disconnect();//Comment this out for USB instead of BT } } |