USBphpTunnel © LGPL

An Android app for MXQ TV box to control an Arduino board via USB from PHP.

  • 8 respects

Components and supplies

Apps and online services

About this project

Android app for MXQ TV box to control an Arduino UNO board via USB from PHP. Designed for data-logging applications (weather, hydroponics, greenhouses, aquariums, home automation, power consumption, solar or wind generators, etc.), this solution can also be useful in alarm systems.

How it works

On USBphpTunnel terminal you can see:

Data received from Arduino ("Read 49 bytes"):

The data MUST be a relative URL, like: '"/testio/add.php primo=32&secondo=4.5&terzo=18:09 "' and MUST start with "/". So [phpPath (in config) + data] makes an absolute URL, called by USBphpTunnel.

Note: Your Arduino Sketch will build relative URLs using the required PHP pages and actual values.

The PHP sample code in add.php (see test_files/www/testio/add.php):

  • adds a record to MySQL table datatest.esempio
  • builds the response: pure ASCII (not HTML)

USBphpTunnel sends the response to Arduino.

Data sent to Arduino ("Send 11 bytes")

The data are commands, as defined in testser02.ino (see /test_files/arduino/testser02.ino):

  • Analog write, sent as "A port value": A [3..11] [0..255] [0xD|0x0A] (as decimal, 0-octal, 0x-esa)
  • Digital write, sent as "D pin value": D [2..13] [0|1|2] [0xD|0x0A] (as decimal, 0-octal, 0x-esa) values: 0 = LOW, 1 = HIGH, 2 = TOGGLE
  • Parameter set, sent as "P index long-value": P [0..15] [[-]0..2'147'483'647] [0xD|0x0A] (as decimal, 0-octal, 0x-esa)

Note: USBphpTunnel accepts any line terminator (\n or \r or \r\n) and transforms it in single "0x0A" (\n)

Note: In your Arduino Sketch you can eliminate unused commands or add your custom commands. Commands MUST NOT start with "*" char.

Debug messages from Arduino ("** Echo: D 13 2")

The message MUST start with "*". It appears in the terminal (not sent to php).

Note: green - color set on config.ini

Debug messages from PHP

The message MUST start with "*". It is show on terminal (not sent to Arduino).

Note: red - color set on config.ini

Because this protocol is pure text, we can also do testing with a standard terminal application. Arduino console terminal: the only terminal app that worked with my Arduino board is "Serial USB terminal". Developed and tested using:


  • Download USBphpTunnel01_d.apk and the full /test_files/ dir
  • See file: /test_files/readme.txt

see also

Using this USBphpTunnel the master is Arduino, and the Android app uses ports like /dev/bus/dev/00X/00Y, so you don't need the serial driver.

Using the new USBphpTunnel_fifo the master is php. It is NOT blocking the master, allows payload up to 4k, allows concurrence (many users via WIFI). Works in background and it is not fast (depending from polling Arduno frequence, 3-10 sec. plus processing time). Well placed for long Arduino processes (like waiting user actions).

Using the simple ArduinoLinuxSerial the Master is PHP, and you need the serial driver (it uses devices like /dev/ACMx or /dev/USBx). Blocking master, but fast and robust protocol (CRC and repetions). Useful with simple and fast Arduino responses.


Now you can develop MySQL and web-enabled Arduino applications only working on Arduino and PHP. To keep the Arduino Sketch light, you can port all non-realtime logic to PHP side. At the end, your application will work on MXQ+Arduino UNO even 24/7 with only 20 Watt AC power, and can be controlled by smartphone via WiFi, or from ewerywhere using a Dynamic DNS (like the free no-ip).

What more?





Similar projects you might like

Master Slave I2C Connection


  • 10 respects


Project tutorial by msillano

  • 1 comment
  • 1 respect

Telegram Bot with ESP8266

Project tutorial by Shebin Jose Jacob

  • 72 respects

8X8 Matrix LED Snake Game (HTML5 Web Socket)

Project showcase by hmkim

  • 1 comment
  • 19 respects
Add projectSign up / Login