Graphical Data Display with Arduino and HTML5

Most Arduino-based projects use LCDs to show data, but this project instead uses webpage so that more details can be displayed in a graphical form and accessed from anywhere through the Internet. The project takes variable analogue inputs from Arduino and displays results in graphical form on a webpage that supports HTML5.

The project presented here includes four webpages coded in four .htm files, which are stored in a memory card and then hyperlinked with each other.

A web server created by an Arduino Ethernet shield loads the requested webpage from an SD card memory device into the browser. The webpage issues AJAX requests to the web server at regular intervals to get input data. The web server responds with an XML file containing measured input values in appropriate tags. The webpage reads input values from the XML format using JavaScript and displays them in an appropriate diagram/chart coded with HTML5 canvas element.

A canvas is a drawable region defined in HTML5 code specified by <canvas> tag for dynamically generating graphics. Animation of the graphics is possible using JavaScript code. Canvas enables programmers to create visually appealing drawings with a few lines of code. It is especially suited for Arduino because of its limited capability to deal with large files.

Circuit and working

The Ethernet shield with microSD card is shown in Fig. 1. The circuit for Arduino-based graphical data display is shown in Fig. 2. It is built around an Arduino Uno board along with some potentiometers (VR1 through VR6), resistors (R1 through R4) and tactile switches (S1 through S4).

Ethernet shield with microSD card
Fig. 1: Ethernet shield with microSD card
Circuit diagram for graphical data display with Arduino and HTML5
Fig. 2: Circuit diagram for graphical data display with Arduino and HTML5

Arduino web server

The web server is implemented by stacking Ethernet shield on top of Arduino board. The Ethernet shield used in this project has W5100 Ethernet controller and an onboard microSD card slot. Transfer HTML5 files required for this project (gauge.htm, bargraph.htm, analog.htm and digital.htm) to an SD card. Now insert the SD card in the onboard microSD card slot of Ethernet shield.

Arduino communicates with both W5100 and SD card using the SPI bus through the ICSP header, and hence only one of these can be active at a time. Arduino sketch (Arduino_html5.ino) in this project uses SPI, Ethernet and SD libraries to function. These libraries manage sharing of the SPI bus so that both W5100 and SD card can be utilised.

Connecting Ethernet shield to the PC

Connect Ethernet shield to the PC using Ethernet cable. The IP address assigned to Ethernet shield in Arduino code is So assign an IP address to the PC’s Ethernet connection, say,, with subnet mask (refer Fig. 3). After connecting Ethernet shield to the computer with Ethernet cable, open the web browser (for example, Google Chrome) and type the address as

Setting IP address of the PC’s connection
Fig. 3: Setting IP address of the PC’s connection

By default, this will load gauge.htm file from the SD card. To load other files or webpages, menu bars or links are given in the default webpage. It is possible to seamlessly switch between displays with hyperlinks given in each page. If files are not loaded, open the serial monitor of Arduino IDE to check any error message and take appropriate action.

Getting data from Arduino

After the webpage canvas code is loaded from the SD card to the system, input data is obtained from the Arduino. Here the technique used is AJAX (asynchronous JavaScript and XML), which helps to update only the diagram/chart without reloading the entire webpage. AJAX enables the browser to send and receive data from the server in the background. The webpage sends AJAX requests to the server at regular intervals. The Arduino server responds with an XML (Extensible Markup Language) file containing data values.

XML is much like HTML. It is designed to describe data with tags organised in a tree structure. The tree structure contains root (parent) elements and child elements as defined by the user. Here the XML file is created by Arduino code with as the root element and and as child elements for analogue and digital inputs, respectively. The XML file created by Arduino is given below:

where the first line is XML declaration.

Displaying graphical data on webpage

After the XML file is received from Arduino, the HTML5 file parses contents with a JavaScript code, which extracts the data and sends it to the canvas display code. The canvas code shows data in the appropriate diagram/chart.

Four types of displays are designed with canvas code as explained below.

Gauge meter

A gauge meter consists of a circular graduated dial and a pointer actuated by a measured input value. Here, the gauge meter is designed by plotting basic circles and lines (refer Fig. 4) in the HTML5 canvas with a few lines of code (gauge.html). The needle is rotated from left to right when the input value is increased.

Gauge meter readings
Fig. 4: Gauge meter readings