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 )
- 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
Description
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.
Hardware
Arduino Mega 2560 - http://arduino.cc/en/Main/arduinoBoardMega2560
Motor shield - http://www.adafruit.com/products/81
Ultransonic sensor - http://www.dfrobot.com/index.php?route=product/product&product_id=53
Temperature sensor - http://ww1.microchip.com/downloads/en/DeviceDoc/21942e.pdf
Robot chassis and 2 DC motors - https://www.sparkfun.com/products/10825
Servo motor - http://www.servodatabase.com/servo/modelcraft/rs-2
Buzzer
2 LED strip
11.1 Li-Po battery
Arduino Libraries
ArdOSCForWiFlyHQ - https://github.com/Zapalot/ArdOscForWiFl ( special thanks for Felix Bonowski's support )
Software
TouchOSC - iPhone/iPad app - http://hexler.net/software/touchosc
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 :-)