Arduino and IPad Controled Car

So awhile back i started paying with Arduino and i have to admit its pretty cool. I’d been exposed to the idea of open source prototyping for years but every time i went to the store to get started i could never make up my mind on what i wanted and always seemed to talk myself out of it. So, in the spirit of moving forward and forcing myself to stop being lazy, a few months back i just gave up and decided to order a random kit and force myself to get started.
When you first get started with the kits, making lights blink and things buzz can get old pretty quick. So, in order to not get to bored to fast, one of the first things i decided to do was to give myself a short project to see if i could actually pull something off with all the electronicy, wirey goodness that came with my first kit.
The project i decided on fairly quickly was an Ipad controlled, networked remote controlled car. Mainly because i had a broken little car handy and secondly because i figured i could add just enough complication to actually make it kind of fun.
The build itself wasn’t that bad. I took apart the car and its remote control and after some experimentation with sending power down the little wires to see what they’d do, i patched the remote control board into the Arduino and wrote some quick code to make the little car move when certain data was intercepted by the serial port:
Arduino Code:
int forPin = 13;
int backPin = 12;
int leftPin = 11;
int rightPin = 10;
int inPin = 7;
int val = 0;
void setup(){
Serial.begin(9600);
pinMode(forPin, OUTPUT);
pinMode(backPin, OUTPUT);
pinMode(leftPin, OUTPUT);
pinMode(rightPin, OUTPUT);
}
void loop(){
if(Serial.available() > 0){
int tmpByte = Serial.read();
switch(tmpByte){
case 'w':
digitalWrite(forPin, HIGH);
digitalWrite(backPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, LOW);
break;
case 's':
digitalWrite(forPin, LOW);
digitalWrite(backPin, HIGH);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, LOW);
break;
case 'z':
digitalWrite(forPin, LOW);
digitalWrite(backPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, LOW);
break;
case 'q':
digitalWrite(forPin, HIGH);
digitalWrite(backPin, LOW);
digitalWrite(leftPin, HIGH);
digitalWrite(rightPin, LOW);
break;
case 'e':
digitalWrite(forPin, HIGH);
digitalWrite(backPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, HIGH);
break;
case 'a':
digitalWrite(forPin, LOW);
digitalWrite(backPin, HIGH);
digitalWrite(leftPin, HIGH);
digitalWrite(rightPin, LOW);
break;
case 'd':
digitalWrite(forPin, LOW);
digitalWrite(backPin, HIGH);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, HIGH);
break;
default:
digitalWrite(forPin, LOW);
digitalWrite(backPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, LOW);
break;
}
}
}
Second, i installed node.js on my laptop and set up a quick html5 based control screen for the iPad that would use webSockets to send direction data from the Ipad to the server running on my laptop. The server would then pick up the data being sent through the sockets and reroute it through the serial port where the Arduino code could pick it up. Once all that was done, i suddenly had a little car that could speed around the office and crash into every piece of furniture in its way:
Node.js Code:
var SerialPort = require("serialport").SerialPort;
var serial_port = new SerialPort("/dev/tty.usbmodemfd131", {baudrate: 9600});
var buffer = [];
var app = require('express').createServer()
, io = require('socket.io').listen(app);
app.listen(8080);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function(client){
client.send({ buffer: buffer });
//console.log("connected")
client.emit({ announcement: client.id + ' connected' });
client.on('message', function(message){
var msg = { message: [client.id, message] };
buffer.push(msg);
if (buffer.length > 15) buffer.shift();
client.send(msg.message[1]);
console.log("log:"+msg.message[1])
serial_port.write(msg.message[1]);
//serial_port.close();
});
client.on('disconnect', function(){
client.emit({ announcement: client.id + ' disconnected' });
});
});
After all this, one thing i quickly noticed was that i couldn’t see where i was going while driving the car in other rooms so the next little augmentation i had to add was an IPhone to the front of the car so i could utilize its camera. Running the miniwebcam App, i was able to take the output over wifi and add it to the Ipad’s HTML control setup. I choose this one because setting up a streaming video solution was a little more complicated than i wanted to go for this project and the miniwebcam app actually output a little image stream that is embeddable in an HTML page that i was able to add to the iPad control that allowed me to see where the little car was going as i drove it around. Problem solved. Now i was able to drive the little car over wifi using my IPad, spy on unsuspecting individuals in their offices, and continue to drive the car into random walls and furniture.
If anyone is every interested in the setup listed here feel free to hit me up and i’d be glad to share.Aside from one mishap with an exploding battery that happened to start shooting acid in the middle of the office, I have to say that my first foray into Arduino was a success. And, If you do try the above and a battery does happen to explode and splash burning acid on your face, you can always go into business as a Batman villain and use the wifi remote controlled cars as a nifty gimmick to take over the city.
See Ya!








