The goal for our tow truck was to have a 4-axis crane and a movable vehicle that we could remotely control with an Android smart phone.
The parts we used for this project were:
- 2 axis camera mount
- motor and servo shield
- Arduino Mega
- Bluetooth serial module
- Arduino car chassis
- Meccano parts
- wire and duct tape
- USB phone charger
Hardware Setup
The tow truck project used a camera mount for up/down/left/right crane motion and an Arduino car chassis for mobility. The controls were done using Bluetooth.
Meccano was used to build a box for the main structure. Wire was used to secure everything together. We laid a folded piece of paper under the Arduino Mega to ensure that none of the Arduino solder connections shorted on the metal Meccano base.
The motor and servo shield that we used did not expose any of the extra Arduino pins, so we needed to use the Mega board. We then wired the Bluetooth module to the exposed pins on the end of the Mega.
Arduino Code
The Arduino code will vary a little based on the motor/servo shield that is used. Our shield was an older version 1 (V1) board that used direct pin connections (no I2C or SDA/SCL connections).
Also because Tx/Rx (Tx0/Rx)) were not available once our motor/servo shield was installed we used Tx1/Rx1 and so our Bluetooth connection was on Serial1 and not Serial.
For the Bluetooth communications we used the following command letters:
- R = drive right
- L = drive left
- f = drive forwards
- b = drive backwards
- s = stop driving
- r = move crane right
- l = move crane left
- u= move crane up
- d = move crane down
Our Arduino code is below:
#include <Servo.h> Servo servo1; Servo servo2; char thecmd; int xpos = 90; int ypos = 90; AF_DCMotor motor1(1); AF_DCMotor motor2(2); void setup() { pinMode( 19, INPUT_PULLUP ); Serial1.begin(9600); Serial1.println("Crane Controls"); Serial1.println("r = right, l = left, u= up, d = down"); Serial1.println("Driving Controls"); Serial1.println("R = right, L = left, f = forwards, b = backwards, s = stop"); servo1.attach(9); // attaches the servo on pin 9 to the servo object servo2.attach(10); // attaches the servo on pin 9 to the servo object servo1.write(xpos); servo2.write(ypos); motor1.setSpeed(255); motor2.setSpeed(255); } void loop() { if (Serial1.available() > 0) { // read the incoming byte: thecmd = Serial1.read(); Serial1.println(thecmd); if (thecmd =='l') { move_crane(servo1, 5); } if (thecmd =='r') { move_crane(servo1, -5); } if (thecmd =='d') { move_crane(servo2, 5); } if (thecmd =='u') { move_crane(servo2, -5); } if (thecmd =='f') { motor1.run(FORWARD); motor2.run(FORWARD); } if (thecmd =='b') { motor1.run(BACKWARD); motor2.run(BACKWARD); } if (thecmd =='L') { motor1.run(BACKWARD); motor2.run(FORWARD); } if (thecmd =='R') { motor1.run(FORWARD); motor2.run(BACKWARD); } if (thecmd =='s') { motor1.run(RELEASE); motor2.run(RELEASE); } } } void move_crane(Servo theservo, int direction) { int minpos = 50; int maxpos = 220; if (direction < 0) { if (ypos > minpos) { ypos = ypos + direction; theservo.write(ypos); } } else { if (ypos < maxpos) { ypos = ypos + direction; theservo.write(ypos); } } }
Android Program
To communication to an Android smart phone we used MIT’s App inventor. This is a free Web based Android development tool.
There are many ways to layout a control screen, for us we used a 10×3 table and then populated it with buttons. Our layout is shown below:
The button logic will pass the required letter command to the Bluetooth component:
Our final running App looked like: