Control The Arduino From An App. This example shows how to make an app that controls an Arduino board, by communicating over the TCP networking protocol.
Communication with the Arduino is made using a WiFi shield or an Ethernet shield.
When using a WiFi shield, you communicate directly from your mobile device to the Arduino. Make sure you are on the same LAN for this to work.
When using am Ethernet shield, you communicate from your mobile device to a WiFi router, that in turn need to be able to connect to the IP-address of the Ethernet shield.
You can browse the source code for this example at the Evothings GitHub repository
The file index.html is the entry point of the app. File arduinotcp.js contains functions for scripting the Arduino from JavaScript. You can set pin mode and set HIGH/LOW for pins.
The file arduinowifi.ino contains the Arduino WiFi server that listens for commands from the app.
The file arduinoethernet.ino contains the Arduino Ethernet server that listens for commands from the app.
This example runs in Evothings Viewer on Android or iOS.
You need to run this example in Evothings Viewer. Alternatively, you can build a Cordova application if you wish to distribute the app. You then need to include the Cordova plugin org.chromium.socket. Read more in the documentation of the Evothings Viewer.
For the Arduino setup, you need:
Here is a sketch using the Arduino Ethernet shield:
Here is a photo of a board configured to work with this example, using an Arduino WiFi shield. Note that output pin 2 is used (it may look like pin 3 in the photo).
Follow these steps to get started with this example: