Wednesday, April 24, 2013

iPhone Controlled Logging Robot

Building this remote controlled robot was really fun. Hope that these notes could help you in your own design.

The challenge here was to integrate different technologies in a working project. In particular I wanted to use the iPhone to send/receive data to/from an Arduino, build a  remotely controlled robot using a WiFi network and hook up a data logger station capturing the different sensor data.

This project includes 3 devices interconnected through a WiFi network:

- Arduino based robot
- iPhone for sending/receiving commands
- Windows running a data logger server

Main robot features

- Arduino board complemented with easily available  shields.
- Remote  driving commands and sonar positioning transmitted from an  iPhone/iPad ( OSC protocol over  UDP over WiFi )

- Robot data sent back to the iPhone including information about the distance from nearest obstacle and battery voltage

- Temperature, voltage and distance data sent from the robot  to an UDP logger server (automatically and manually triggered from the iPhone).

- Robot direction is modified by controlling the relative speed of each wheel

- If an obstacle is detected within 20 cm from the robot, it  stops automatically. A backwards command should then be sent to the robot for modifying its path.
- Robot is automatically stopped if battery voltage is below threshold preventing Li-Po battery discharge
- iPhone screen can be completely customised.

Robot control  screen on the iPhone


The robot receives driving commands from the iPhone and sends feedback information back to the iPhone and sensor data to the PC. 

For simplicity all messages are UDP using the OSC message structure.  The robot sends all messages in broadcast mode that are  received by the iPhone and the PC logger. The TouchOSC app for the iPhone was chosen due to its flexibility, low cost and simplicity for sending and receiving OSC messages. 

A special screen was configured for this project using existing graphical elements without any reprogramming. The OSCmonitor program runs in a Windows PC logging all messages sent from the robot including the data about its position, temperature and battery voltage.

The robot is manually remotely controlled; however, it has a “collision prevention” feature based on a sonar sensor. Specific serial communication routine was included to detect sensor time-out when no obstacle was in sight. Sonar sensor is mounted on a servo motor that can be remotely positioned from the iPhone.

Robot direction is controlled from the iPhone using a XY pad. In the provided sketch only the X value is used to set the relative wheels’ speed. When it is positioned in the middle it moves the robot straight ahead, when the cursor is on the far left side it turns sharply to the left and when clicking on the right side the robot turns right. Using this control scheme it is possible to control linearly  the robot direction, compensating for differences between the 2 DC motors and mechanics.
The LED’s strip is connected using the spare  2 DC motor connections in the motor shield signalling when the robot moves forward  or backwards.

2 Hardware Serial interfaces are being used in the Arduino Mega  in addition to the USB channel: one for the the communication with the WiFi shield and the other with the sonar sensor. It is possible to modify the project to used instead  “Software Serial communication” channels.

During the project development, I damaged twice the Li-Po battery due to over discharging it. The correct solution would be to cut the voltage to the robot 

using an external device

if the voltage goes under the threshold . Currently, the battery voltage is monitored using an analog input. The battery voltage is measured through a resistor trimmer to reduce the voltage to the 0..5V interval required by the Arduino. This measurement is then displayed on the iPhone and also logged in the PC logger - additionally, a buzzer in the robot is triggered.

Data Logger output

Wifi shield - ( RN-171 WiFly based )
Robot chassis and 2 DC motors -
2 LED strip
11.1 Li-Po battery

Arduino Libraries
ArdOSCForWiFlyHQ -  ( special thanks for Felix Bonowski's support )

TouchOSC -  iPhone/iPad app -
OSC Monitor - Windows .exe -

Tips  gotten from
Examples provided with each one of the libraries.

Attached files
Click here to download a complete copy of the Arduino sketch and the TouchOSC screen, but be aware that I am not a good programmer :-)


  1. Hi Rubens,
    I just happened to visit your interesting project while searching for a problem of mine:
    I am using a quite similar setup as yours: Touch OSD on iPHone, Arduino Mega with Wifly directly connected to 3.3v Gnd, RX, TX and the two libraries from Zapalot (ArdOscForWiFl and WiflyHQ).
    My project is to control LEDs with that setup, like having a fader to fadein/out LEDs in real-time.

    However, it seems like I have a huge latency coming up.
    So switching a button on TouchOSC does not work really stable. One time it works and LED lights up, but then I can press the button 6 times and nothing happens and with the next switch I can turn LED off again.

    Since I would says that with your project you need an even more stable and quick setup to turn the robot from left to right, I was wondering if you had this problem, too, and how you fixed that.

    WOuld be cool to get some feedback.
    Also, do you have some contact mail from Felix Bonowski, the creator of the libraries? May be he can help me with my project as well.


  2. you can contact Felix through his page at github