Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us

Forward Logo (image)      

Arduino UNO/Mega Starter, controlled by Android/pfodApp
Control your UNO/Mega from your Android mobile, no coding required.
Then build your own controls. No Android coding required.

by Matthew Ford 29th June 2019 (original 7th May 2017)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

This Interface is NOT programmed into pfodApp.
It is completely generated and controlled from your Arduino Uno/Mega2560 Sketch

pfodApp (a paid Android app) is a general purpose Android app for controlling Arduino and other micros via Bluetooth, Bluetooth Low Energy, WiFi, Ethernet or SMS. When you have finished using this example control sketch, you can use the free pfodDesigner Android app to create your own menus, buttons and charts to log and plot Arduino data, and then have pfodDesigner generate the necessary Arduino Uno sketch to display your menu, charts etc on pfodApp. pfodDesigner also has limited support for creating drawings. To create a user interface like the one above, check out Custom Arduino Controls for Android (No Android Programming Required) and the comments below about the sketch. The pfodSpecification contains all the drawing primitive and menu messages.

None of these projects require any Android programming. The same pfodApp is used for all the examples. The menus on your mobile are completely controlled by string messages sent from your Arduino code.

This project replaces a previous Uno Starter project that used menus instead of graphical controls.

Parts Required

To control your Arduino Uno from your Andriod moble you need: (Here is a complete parts list) You can build the project for less then ~US53, plus shipping)
For an alternative Arduino Starter project that uses the more powerful Arduino101 BLE board see Arduino101Starter (cost less than ~US43, plus shipping)

i) Arduino Uno board -- https://www.sparkfun.com/products/11021 ~US$25 OR an Arduino Mega2560 board
ii) USB A to B cable -- https://www.sparkfun.com/products/512 ~US$4
iii) The pfodApp -- https://play.google.com/store/apps/details?id=au.com.forward.pfodApp ~US$10

and a communication shield to connect your Uno to your mobile. pfodApp supports a wide variety of connections so there are a number of choices. Some of these are:-

ITEAD Wireless Bluetooth Shield -- https://www.itead.cc/itead-bt-shield-master-slave.html ~US14 (just plugs in and works with all Andriod mobiles)
ITEAD Bluetooth Low Energy BLE Shield -- https://www.itead.cc/itead-ble-shield.html ~US19 (just plugs in, needs Android >= V4.4 with BLE capability)
Cheap/Simple WiFi Shield -- http://www.forward.com.au/pfod/CheapWifiShield/index.html ~US12 (requires some construction. Works with all Andriod mobiles)
Adafruit Bluefruit LE UART Friend (Bluetooth Low Energy) -- https://www.adafruit.com/product/2479 ~US18 (requires some soldering, needs Android >= V4.4 with BLE capability)

Here we will be using the ITEAD Wireless Bluetooth Shield. It is the cheapest board that just plugs in and it will connect to all Android mobiles, V2.2+, when pfodApp is installed.

Quick Start

1) Download and install Arduino IDE V1.8.2 from http://arduino.cc/en/Main/Software. That web page has links for various operating systems and a link to GettingStarted (http://arduino.cc/en/Guide/HomePage). Go through the GettingStarted steps for your operating system at the end of which you will have uploaded the BLINK program to your Arduino Uno board.

2) Download the latest pfodParser library V3.4+. Follow the instructions on that page for installing it. Delete any previous pfodParser library dir first.

3) Download the UnoStarter.zip and unzip it to your Arduino sketch directory. It will unzip an UnoStarter directory. Open UnoStarter.ino and compile and download to your Arduino Uno.

4) Plug in your communication shield. Note: Remove your communication shield when trying to program your Uno.

4) Download and install pfodApp V3.0.313+ on your Android mobile (Android V4.4.1 and above for BLE support). Follow the pfodAppForAndroidGettingStarted.pdf to pair your mobile with the Bluetooth Shield and setup a new pfodApp connection, I called mine “Uno”.
Finally click on your
Uno connection to connect to your Arduino Uno board. The UnoStarter sketch will progressively load this dwg.

Click on the area of the board you want to work with to zoom in.

Then click the Digital pin you want to configure.

Pins with ~ symbol can be configured as PWM outputs.

Analog pins are not configurable and are updated with the current reading when you are don't have the zoom window open.
The ? button provides brief on screen help. The x button closes the window.

Next Steps

The pfodApp is a general purpose control app for Arduino and other micros. You can use the free pfodDesigner Android app to create your own menu system and then generate the necessary Arduino code for a variety of boards. You can also add your own custom controls like the one above to your menu system. See Custom Arduino Controls for Android for a general introduction to creating custom controls. See the Arduino101 Starter project for a description of how the zoom window used in this example works.

For more pfod project examples, see www.pfod.com.au
For how your sketch handles the Pan and Zoom, see the Arduino101Starter project.

Program Optimization Notes

Code Size Optimization

This code was copied from the Arduino101Starter and modified for the Uno Board and a Serial communication connection. Not surprisingly, when first compiled the code would not fit in the 32K flash memory space available on the UNO. The initial compile needed 35932 bytes or 111% of the 32256 bytes available in the UNO flash program memory. This problem was solved by some code optimization.

Most of the code here and in Arduino101 Starter uses the convenience classes and methods provided by the pfodParser library to construct the dwg primitive messages. For example

void addCloseButton(double c, double r, double scale) {
. . .  
 dwgs.circle().filled().idx(closeTouchZone_order).radius(1.8).offset(0, 0).color(dwgs.BLACK).send();
. . .  

Creates the text string that defines a filled BLACK circle, radius 1.8, offset (0,0) from the current zero position, with an identifying idx for later reference. The actual text string generated by these functions calls, that is then sent to pfodApp to draw the rectangle, is


While those convenience methods are easier to read, they take up more program space then a simple print(F(“|C`700~0~1.8~~”))

So to squeeze the sketch into the UNO, the touchZone and touchAction methods were replaced with the equivalent text strings. For example in the IO_Pin.c draw() method

   //  dwgsPtr->touchZone().cmd(buttonCmd).size(20.5, 2.2).offset(-5.5, -1.1).filter(dwgsPtr->TOUCH).send();
  //  dwgsPtr->touchAction().cmd(buttonCmd).action( // create the action
  //    dwgsPtr->rectangle().filled().idx(z_idx).rounded().centered().size(2, 2.2).color(dwgsPtr->BLACK) //
  //  ).send(); // send the touchAction

was replaced with

  dwgsPtr->out->print(F("|x~")); dwgsPtr->out->print(buttonCmd); dwgsPtr->out->print(F("~20.5~2.2~-5.5~-1.1"));
  dwgsPtr->out->print(F("|X~")); dwgsPtr->out->print(buttonCmd); dwgsPtr->out->print(F("~RRc`39~0~2~2.2~~"));

This reduced the code size down to 30838 bytes (95%) of the UNO program memory. The pfod specification was designed around compact text strings, so this type of optimization is always possible, if needed.

Dynamic Memory (RAM) Optimization

The Dynamic Memory used by the UnoStarter sketch variables is 1539 bytes or 75% of the available 2048 bytes. This leaves about 500 bytes for stack space where arguments can be passed to subroutines. No optimization was need here.

However there is an optimization that is available, if you find you are running out of Dynamic Memory (RAM). If you are not using the pfodSecurity library, i.e. just using pfodParser, then you can free up about 200 extra bytes of dynamic memory by a changing the maximum receive message size in the the pfodParser library code.

The pfodSpecification.pdf limits the maximum command sent by pfodApp to your Arduino to 255 bytes, including opening { and closing }. However your sketch completely determines the type of commands and their maximum length that the user can send when interacting with the menu/dwg your sketch display on pfodApp.

For this sketch, UnoStarter.ino, a typical command received from pfodApp is {V46:A~x`15`11`4} That is only about 17 bytes. If you turn on the debug log in pfodApp for this connection, the you can log all the commands sent and find the maximum length. 30 bytes is usually enough if your sketch does not use multi-selection lists or text input screens.

So most of the 255 byte buffer that pfodParser allocates goes unused and it size can be reduced to 30, freeing up 225 extra bytes of RAM for your sketch's variables.

To do this edit the file pfodParser.h in pfodParser library, to change the line

    // you can reduce the value if you are handling smaller messages
    // but never increase it.
    static const byte pfodMaxMsgLen = 0xff; // == 255, if no closing } by now ignore msg


    static const byte pfodMaxMsgLen = 30; // == 30, if no closing } by now ignore msg

Note: After you make this change ALL your pfod projects will be limited to receive command no longer then 30 bytes, but as noted above if your sketch does not use multi-selection lists or text input screens that will usually not be a problem.

However this optimization was not need for UnoStarter and the pfodParser library was not edited, but was used unchanged as it was downloaded.


pfodApp is a general purpose app that allows you to create your own custom and sophisticated control apps without doing any Android programming. The Arduino sketch completely controls what the pfodApp displays to the user and how user interacts with it. The example above illustrates controlling the Arduino UNO board using a number of custom controls together with pan and zoom to make those controls easily available to the user. This sketch can also be loaded into an Arduino Mega2560 board and will update the name and PWM pins to suit.

pfodApp also connects to a wide variety of other BLE boards and shields as well as to Classic Bluetooth, Wifi, Ethernet and SMS shields. The free pfodDesigner allows to your to create you own menu system and then generates the Arduino code for you. Custom Arduino Controls for Android provides and introduction to creating your own custom controls. pfodSpecification.pdf contains a detailed description of the pfod messages. Also see www.pfod.com.au for numerous other example projects.

AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ

The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.