Arduino Input TCP

Read Arduino Sensors From Your App. This example shows how read data from 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.

Source code

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.

What you need

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.sockets.tcp

For the Arduino setup, you need:

  • WiFi shield or Ethernet shield
  • Some input device that produces analog input, e.g. a potentiometer

How to get up and running

Follow these steps to get started with this example:

  • Wire up the Arduino board. Connect e.g. a potentiometer to an input pin. Make a note of the input pin number.
  • Launch Evothings Workbench on your desktop/laptop computer.
  • In Evothings Studio, made a copy of the example app "Arduino Input TCP".
  • The app appears under "My Apps". Click the "CODE" button and open file index.html in a text editor.
  • In index.html, enter the pin number you used, see around line 81 in the code (set the variable app.analogInputPin to the pin you use).
  • Open arduinowifi.ino or arduinoethernet.ino (depending on the shield you use) in the Arduino development tool.
  • Enter the name and password for your WiFi network in arduinowifi.ino or configure your IP-address in arduinoethernet.ino.
  • Upload the program to the Arduino.
  • If using a WiFi shield, open the Serial Monitor Window and look for the IP address of the Arduino. (If the IP address is not displayed, check your WiFi network name and password.)
  • Launch Evothings Viewer on an iOS or Android mobile device and connect to the Workbench.
  • Run the example "Arduino Input TCP" from the Workbench window by clicking "RUN" on the app under "My Apps".
  • Enter the IP address of the Arduino in the app.
  • If everything works, you should now be able to see input from the potentiometer in the app. If it does not work, check your wiring and that the right pin number are used in the app.
  • Now you can proceed with making your own sketch designs and add more buttons to the app.