domingo, 7 de julio de 2013

Internet controlled Arduino car


Just to give an idea of the project, firstable I want to show you the end result:




This is a car that can be controlled from a web that acts as a remote control panel where you can send simple movement commands to the car and see the pictures that the attached camera is sending continuously.

The parts used are:

- TTL Serial VC0706 camera.
- Arduino motor shield R3.
- GSM shield "bluevia".
- Arduino UNO

Probably the best way to control the car from internet is to deploy a web server at the gsm shield and receive commands through it. That is what I tried first, the GSM library has the proper class to do it: GSMServer, and it is well documented and with a couple of examples, but for this to work you need your ISP to allow incoming connections, what was not my case (Orange, in Spain). 

So I decided to set up the control in a server at internet where the car will connect to ask for the commands. The modem in the GSM shield (Quectel M10) has a maximum rate of 85Kbps for GPRS, so it would be good to have the least possible overhead on any TCP/UDP protocol used to make things run as fast as possible and have some acceptable responsiveness. It is also not easy to deploy a tcp server on any free hosting, so I though that the HTTP overhead in the communications would fit enough and as I had to deploy a web page for the remote control panel, a simple ASP page that accept POST calls asking for commands was the final solution. The final architecture of the system is this:

Remote Car Control architecture

The control panel appearance is like this:

Remote car Control Panel

It is a web where you can see the pictures that the car is sendind periodically, and where you can save orders for the car. That orders are simple movements (Forward, Backward, Left, Rigth) and the time you want each order to be executed. This is a very rude way of controlling a car, I know...but think of it as a starting point for controlling some motors from internet and having a view of the effect of that movement.

It uses a free ASP web hosting (SmartASP) and mysql database to store the commands. The picture is stored at the server filesystem and the web updates it continuously using Ajax. Here you can get the whole Visual Studio solution for the server part, the web that takes care of serving the commands and receiving the pictures, and the web frontend.

The algorithm in Arduino is simple (code):

  1. Connect to GSM and start GPRS
  2. Take a picture with the camera
  3. Compose a POST call which sends the picture to the server
  4. Process the POST response, where the command is contained in the form of "movement;time". For example "1;1" means: move forward during 1 second.
  5. GOTO 1


If you want to make this project you will find more information on other posts of this blog about the parts involved on it. This is just a proof of concept, I think both the GSM shield and TTL camera offer a lot of possibilities to improve this system and to do other interesting things, or just to enjoy!.


TTL Camera VC0706 

Using the camera is not complicated if you follow the detailed instructions at Adafruit. It is a great camera, just take care of the resistor divider at the reception pin, as Arduino works at 5V and the camera at 3.3V TTL. It has three resolutions, I used the smallest one (160x120) that results in a photo of about 3Kbytes. One tricky thing is that you have to put a little delay after the begin() of the serial connection to the camera, before taking the picture.

The camera can detect motion, that opens the door for a lot of interestings projects...


Here you have a video of the whole system working: