Arduino Internet Voltage Monitoring

Arduino Internet voltage monitoring can be achieved in several ways. The Arduino can be set up as a client or a server in order to display measured voltage on a web page. In this article an Arduino is set up as web server that hosts a web page stored on SD card. The web page displays the voltage measured on Arduino analog pin A2 in near real-time. The web server also interacts with ThingSpeak, a Internet of Things (IoT) service which logs voltage over time. Voltage is displayed on the hosted web page on a gauge and in a ThingSpeak generated graph or chart.

Arduino Internet Voltage Monitoring

Arduino Internet Voltage Monitoring

How Arduino Internet Voltage Monitoring Works in this Project

The Arduino web server hosts a web page that communicates with the Arduino using JavaScript / Ajax. This allows the voltage to be sent from the Arduino to the web page over the Ethernet connection to update the voltage in the gauge on the web page. A potentiometer is used to vary the voltage on Arduino pin A2 between 0 and 5 volts.

The raw value from the Arduino analog input is sent to the web page and converted to voltage in the JavaScript that runs on the page. The raw analog value is also displayed on the web page and will be between 0 and 1023.

After the voltage is calculated, it is sent to ThingSpeak by JavaScript. ThingSpeak logs the voltage and plots the graph of the voltage. The graph in the above image is created by copying graph code from ThingSpeak which then updates the graph with the data from the ThingSpeak server.

Voltage Update Timing

Voltage is measured by the Arduino and updated on the web page every 200ms. ThingSpeak only updates graph or chart values every 15s (fastest update speed), so the JavaScript code only sends updates to the ThingSpeak server every 20s.

Tutorial for the Project and Other Resources

A full tutorial is available which explains how to set up this project on your own Arduino.

Learn how ThingSpeak works and how to set up a channel to send data from an Arduino to an account on the ThingSpeak server — ThingSpeak is a free service.

Learn about measuring voltage with Arduino.

Arduino Ethernet shield tutorial explains how to set up an Arduino and Ethernet shield as a web server.

 

 

How to Plot Sensor Data to a Graph over the Internet with Arduino

Getting sensor data from an Arduino and sending it over the Internet to display the data in a graph can be a rather challenging task. This task is made extremely easy when using a IoT (Internet of Things) web service instead of setting up the Arduino to host a web page that contains the sensor data graph. Any Arduino board that has Ethernet on it or any Arduino board with an Ethernet shield can be used to make an Arduino Internet graph.

Arduino Internet Graph

An Arduino Internet graph can easily be made by using the ThingSpeak platform to do all the hard work like capturing the sensor data and plotting it to a graph. The image below shows Arduino analog pin A0 voltage plotted on a graph that is displayed in an account on the ThingSpeak website.

Arduino Internet Graph

Arduino Internet Graph

 

 

 

 

 

 

 

 

 

How it Works

A ThingSpeak library is installed in the Arduino IDE using the Arduino library manager. The library provides functions that can be used to communicate with the ThingSpeak web server.

A free account can be opened on the ThingSpeak website which allows channels to be created. Data from the Arduino, which can be sensor data, voltage, or any other data, can then be sent to the channel and plotted on a graph at the website. Each channel can have up to eight fields, enabling data from up to eight sensors to be sent over one channel.

When using ThingSpeak, no SD card is needed and the Arduino and Ethernet shield or other Arduino board that has Internet capabilities is set up as a client rather than a server. No special Internet router settings need to be made when the Arduino is used as an Internet client, making setup and use very easy.

Arduino Internet Graph Plotting Tutorial

A full tutorial on how to plot sensor data over the Internet with Arduino is available in the article Logging Data and Displaying Graphs over the Internet with Arduino.

 

Processing Serial Port Number Programming and Selecting

Processing language applications that use the serial port to connect to serial devices such as Arduino need to use the correct serial port number that the serial device is connected to. Here are three methods for selecting and connecting to a serial device from a Processing application, namely, hard-coding, auto-detection and user selected Processing serial port.

Hard-coding a Processing Serial Port Number

Hard-coding the serial port number in the Processing application is the default way used in most Processing examples. In the library reference documentation for the Serial library, the hard-coded method is used.

Listing the Serial Ports and Connecting

Hard-coding examples usually print the list of serial ports on the computer to the text area at the bottom of the Processing IDE using the following line of code:

println(Serial.list());

This allows the programmer to determine which number the desired port is in the list of ports. The ports listed in the text area of the IDE are numbered from 0 in the list, so in the list of serial ports in the image below from a Linux computer, /dev/ttyACM0 would be 0 in the list, /dev/ttyS0 would be 1 in the list, etc.

Processing Serial Port List

Processing Serial Port List

 

 

 

 

 

On a Windows computer, these would typically be COM1, COM2, COM3, etc. which are also numbered in the list starting from 0.

After the correct serial port name from the list is found and the number of the serial port in the list has been determined, the serial port can be connected to in the Processing application code.

// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;       

// List all the available serial ports:
println(Serial.list());

// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 9600);
  
// Send a capital A out the serial port:
myPort.write(65);

The above code is taken from the Processing Serial library documentation and first lists the available serial ports on the computer, then connects to the first serial port in the list. The following line of code is where the serial port number from the list is hard-coded in the application:

myPort = new Serial(this, Serial.list()[0], 9600);

The parameter Serial.list()[0] connects to the first serial port in the list of serial ports. In the above image, this would be /dev/ttyACM0. On my Windows PC, there is a default COM port, COM3. When an Arduino is plugged into the PC, it appears as COM4 or COM5, depending on which USB port the Arduino is plugged into. Processing code for the Windows PC must use Serial.list()[1] to connect to the second serial port on the PC which would be either COM4 or COM5 in this particular case.

Disadvantages of Hard-coding the Serial Port Number

If a Processing application that connects to a serial port is run on a different computer, or more than one serial device is connected to a computer, the desired port to connect to may change position in the list of ports. It would then be necessary to modify the Processing code to select the correct serial port. This means that the Processing IDE would need to be loaded onto every computer that the application is run on, in case the serial port number changes.

Auto-detecting a Processing Serial Port Number

A USB serial port can be auto-detected by a Processing application by starting with the USB serial device unplugged and then starting the Processing application. The Processing application can be programmed to store the list of serial ports before the desired USB serial device is plugged into the computer. When the device is plugged in, the Processing application can detect it and find it’s serial port name and number.

Code from the Processing application that auto-detects which serial port number an Arduino is plugged into uses the USB serial port auto-detect method and can be used as a starting point for any Processing project that is to use serial port auto-detect.

User Selected Processing Serial Port Number

Window controls in a Processing application can be used so that a user can scroll through the list of available serial ports and connect to the desired port. This method has the advantage that if the application is to run on different computers, the correct serial port can be selected by the user at run-time.

The image below shows controls in a Processing application window used to select and connect to a serial port.

Processing Serial Port Select Using Window Controls

Processing Serial Port Select Using Window Controls

Up and down buttons allow the list of serial ports to be scrolled through to select the desired port. When the Connect button is clicked, the application will connect to the selected (currently displayed) serial port.

A Disconnect button allows disconnecting from the serial port, so that the application can connect to a different serial port.

The Refresh button updates the list of available serial ports, which is useful in cases where a serial device is connected to the PC after the application is started. The new device will be added to the list when the refresh button is clicked.

Arduino Uno Interfacing GT-511C3 Fingerprint Scanner Demo Software

ADH Technology, the company that sells the GT-511C3 fingerprint scanner provide SDK software that includes a demo application for running on a PC. The demo software allows the scanner to be used to enrol fingerprints, each with a unique ID and then identify enrolled fingerprints when a finger is placed on the scanner later. The GT-511C3 fingerprint scanner demo software also includes several other functions that allow fingerprints to be deleted, display number of registered fingerprints, etc.

A USB to TTL level device is normally needed to connect the fingerprint scanner to a Windows PC to use the demo application.

Connecting the GT-511C3 Fingerprint Scanner to a PC using an Arduino

The article on interfacing the GT-511C3 to a PC running the demo software provides a quick hack that uses an Arduino Uno as a USB to TTL converter. The Arduino Uno uses a software serial port to connect to the fingerprint scanner because the only hardware serial port on the Uno is connected to the USB chip which is used as the interface to the PC USB port.

Serial data is relayed between the fingerprint scanner and demo software on the PC by a sketch running on the Arduino. The image below shows the demo application and interface to the scanner. Also see the full article that explains the hardware connections and software needed for the project.

GT-511C3 Fingerprint Scanner PC Demo Software using Arduino Uno

GT-511C3 Fingerprint Scanner PC Demo Software using Arduino Uno

How to Use Arduino Serial Ports

Arduino boards such as the Uno, MEGA2560 and Due all have a serial port that connects to the USB device port on the board. This port allows sketches to be loaded to the board using a USB cable. Code in a sketch can use the same USB / serial port to communicate with the PC by using the Arduino IDE Serial Monitor window, or a Processing application for example. The USB port appears as a virtual COM port on the PC.

This article shows how to use Arduino serial ports when additional serial ports are needed for a project.

Arduino Serial Ports Available

The serial port for programming the Arduino mentioned above is a hardware serial port. The microcontroller on the Arduino board has a hardware serial port built-in, so that after the port has been initialized by software, a byte sent to the port will be sent out serially by the hardware.

The Arduino Uno has only one hardware serial port because the microcontroller used on the Uno has only one built-in serial port. The Arduino MEGA 2560 and Arduino Due both have 3 extra hardware serial ports.

Serial Port Technical Details

The hardware serial ports referred to here are UART (Universal Asynchronous Receiver Transmitter) ports. They may be referred to as USART (Universal Synchronous Asynchronous Receiver Transmitter) ports in the microcontroller documentation if they are configurable in both synchronous and asynchronous modes.

Arduino Uno Serial Port

This image shows the only serial port available on the Arduino Uno highlighted in red. The port connects through a USB chip to the USB device port.

Arduino Uno Serial Port

Arduino Uno Serial Port

Arduino MEGA 2560 and Due

Both the MEGA 2560 and Due have 4 serial ports in total. One that connects through a USB port chip to the USB device port on the board and three extra serial ports that connect to pins on one of the pin headers of the board.

Arduino Due Serial Ports

Arduino Due Serial Ports

 

Arduino MEGA 2560 Serial Ports

Arduino MEGA 2560 Serial Ports

Pins 0 and 1 of the Due and MEGA connect serial port 0 through to the USB device port so that these Arduino boards are compatible with the pin numbering of the Uno and therefore with Arduino shields.

The extra serial ports are ports 1 to 3 with each port having a transmit and receive pin.

It is important to be aware that the MEGA 2560 serial port pins use 5V voltage levels, but the Due uses 3.3V voltage levels.

How to Use Additional Arduino Serial Ports

An extra serial port can be used on an Arduino Uno, but must be simulated in software by using the SoftwareSerial library.

Arduino Uno

The following code is taken from the article on serial communications with the GT-511C3 fingerprint scanner which connects the fingerprint scanner to a software serial port on an Arduino Uno.

#include <SoftwareSerial.h>

SoftwareSerial gtSerial(8, 7); // Arduino RX, Arduino TX

void setup() {
  Serial.begin(9600);    // serial / USB port
  gtSerial.begin(9600);  // software serial port
}

byte rx_byte = 0;        // stores received byte

void loop() {
  // check if byte available from USB port
  if (Serial.available()) {
    rx_byte = Serial.read();
    // send a byte to the software serial port
    gtSerial.write(rx_byte);
  }

  // check if byte available on the software serial port
  if (gtSerial.available()) {
    // get the byte from the software serial port
    rx_byte = gtSerial.read();
    Serial.write(rx_byte);
  }
}

To use the software serial port, first the header file for the software serial library must be included.

#include <SoftwareSerial.h>

Next create the software serial port, selecting the Arduino pins to use for receive (RX) and transmit (TX). Here pin 8 has been set as the receive pin and pin 7 as the transmit pin.

SoftwareSerial gtSerial(8, 7);

The software serial port had been given the name gtSerial which will be used in the sketch to refer to this serial port.

The port can now be checked for incoming data.

if (gtSerial.available()) {

If data is available, it can be read from the port.

rx_byte = gtSerial.read();

Data bytes can also be sent on the port.

gtSerial.write(rx_byte);

How to Use Additional Serial Ports on the Arduino MEGA 2560 and Due

The additional hardware ports on the Arduino MEGA 2560 and Due can be used in the same way as the main USB serial port is used in sketches, only changing the name of the port. The USB serial port, or serial port 0 is referred to as Serial in sketches. To use serial port 1, the name changes to Serial1. Serial ports 2 and 3 are referred to as Serial2 and Serial3.

This sketch shows serial port 3 being used which transmits on pin 14 of the MEGA or Due and receives on pin 15.

void setup() {
  // initialize serial ports
  Serial.begin(9600);    // USB serial port 0
  Serial3.begin(9600);   // serial port 3
}

byte rx_byte = 0;        // stores received byte

void loop() {
  // check for data byte on USB serial port
  if (Serial.available()) {
    // get byte from USB serial port
    rx_byte = Serial.read();
    // send byte to serial port 3
    Serial3.write(rx_byte);
  }
  // check for data byte on serial port 3
  if (Serial3.available()) {
    // get a byte from serial port 3
    rx_byte = Serial3.read();
    // send the byte to the USB serial port
    Serial.write(rx_byte);
  }
}

The additional serial ports are immediately available in the sketch without having to include any libraries.

Serial port 3 must first be initialized to the desired baud rate.

Serial3.begin(9600);

The port can be checked for incoming data.

if (Serial3.available()) {

If a byte has arrived on the serial port, it can be read.

rx_byte = Serial3.read();

A byte can be written to the serial port.

Serial.write(rx_byte);

Arduino Serial Port Resources

Arduino Website References for Software and Hardware

Projects, Articles and Tutorials