Serial Communications with the GT-511C3 Fingerprint Scanner using Arduino and Processing
Created on: 4 July 2015
Communications with the GT-511C3 fingerprint scanner (FPS) are demonstrated by sending data packets from a Processing application to switch the LED on the FPS on and off. An Arduino Uno is used to interface the FPS to a PC via a USB cable.
The Arduino acts as a simple serial communications relay device that receives serial data from the Processing application running on a PC and sends the serial data to the GT-511C3 FPS. Response data from the FPS is relayed back to the Processing application by the Arduino.
Although the Processing code only sends two hard-coded data packets to the fingerprint scanner and displays the response packet from the FPS in the Processing IDE text display console pane, the project can be used as a staring point for your own fingerprint application and also servers to demonstrate how the fingerprint scanner communications work.
Code for both the Arduino and the Processing application can be found below. This video shows the application being run.
Connecting to the GT-511C3 Fingerprint Scanner
The GT-511C3 is powered by 5V, but the pins used for serial communications operate at 3.3V. This means that the serial output pin from the Arduino Uno must be level-shifted from 5V to 3.3V, which can be done through a resistor divider.
A circuit diagram for connecting the GT-511C3 to an Arduino Uno and using a resistor divider can be found near the bottom of the article on GT-511C3 hardware, wiring and pin numbers. Be sure to locate the circuit diagram that uses an Arduino Uno and not the Arduino Due if you are using a 5V Arduino.
GT-511C3 Arduino Code
The code below uses a software serial port to communicate with the GT-511C3 because the only hardware serial port on the Arduino Uno is connected to the USB port and is used to communicate with the PC Processing application.
This code simply relays any data from the USB port / hardware serial port to the GT-511C3 on the software serial port. Response data packets from the GT-511C3 are relayed from the software serial port to the hardware serial port / USB port.
/*------------------------------------------------------------------------------ Program: FPS2processing Description: Relays data between GT-511C3 fingerprint scanner and processing application via the serial port at 9600 baud. Hardware: - Arduino Uno - GT-511C3 Optical Fingerprint Scanner Module - Interfacing resitors References: GT-511C3 datasheet v1.1, www.adh-tech.com.tw Date: 3 July 2015 Author: W.A. Smith, http://startingelectronics.org ------------------------------------------------------------------------------*/ #include <SoftwareSerial.h> // need a serial port to communicate with the GT-511C3 SoftwareSerial gtSerial(8, 7); // Arduino RX (GT TX), Arduino TX (GT RX) // the Arduino TX pin needs a voltage divider, see wiring diagram at: // http://startingelectronics.com/articles/GT-511C3-fingerprint-scanner-hardware/ void setup() { Serial.begin(9600); // serial connection to processing app. gtSerial.begin(9600); // for communicating with the GT-511C3 } byte rx_byte = 0; // stores received byte void loop() { if (Serial.available()) { // get byte from processing app. and send to FPS rx_byte = Serial.read(); gtSerial.write(rx_byte); } // check for a byte from the GT-511C3 if (gtSerial.available()) { // get a byte from the FPS and send it to the processing app. rx_byte = gtSerial.read(); Serial.write(rx_byte); } }
After connecting the hardware, simply load the Arduino sketch to the Aruduino board and then run the Processing application on the PC.
GT-511C3 Processing Application Code
The Processing code below sends a packet that either switches the LED of the FPS on or off, depending on which button is clicked. The response from the FPS can be seen in text area at the bottom of the Processing IDE.
The serial port number may need to be changed in the following line of the code:
//println(Serial.list()); serial_port = new Serial(this, Serial.list()[0], 9600);
Uncomment the top line to see a list of serial port numbers in the Processing IDE window. Modify the second line to set the serial port to the desired number.
Also see the article on determining the serial port number of the Arduino using a Processing application.
/*------------------------------------------------------------------------------------ Program: GT_FPS_on_off Description: Displays two buttons that allow the LED of the GT-511C3 finger print scanner to be switched on and off. Purpose: Demonstrates how to send packets to the GT-511C3 and displays the response packet in the Processing console window. Uses hard-coded packets for learning purposes. Can also be used to test the finger print scanner. Hardware: Arduino Uno or similar, GT-511C3, interface resistors Software: Load the FPS2processing sketch on the Arduino Date: 3 July 2015 Author: W.A. Smith, http://startingelectronics.org ------------------------------------------------------------------------------------*/ import processing.serial.*; Serial serial_port; Button btnOn = new Button("On", 30, 50, 140, 40); Button btnOff = new Button("Off", 30, 120, 140, 40); void setup() { size(200, 200); //println(Serial.list()); serial_port = new Serial(this, Serial.list()[0], 9600); } // called when mouse button is clicked void mousePressed() { if (btnOn.MouseIsOver()) { FpsTxLedOn(); } if (btnOff.MouseIsOver()) { FpsTxLedOff(); } } // switch the fingerprint scanner LED on void FpsTxLedOn() { byte[] tx_cmd = { 0x55, -86, // packet header (-86 == 0xAA) 0x01, 0x00, // device ID 0x01, 0x00, 0x00, 0x00, // input parameter 0x12, 0x00, // command code 0x13, 0x01 }; // checksum for (int i = 0; i < 12; i++) { serial_port.write(tx_cmd[i]); } } // switch the fingerprint scanner LED off void FpsTxLedOff() { byte[] tx_cmd = { 0x55, -86, // packet header (-86 == 0xAA) 0x01, 0x00, // device ID 0x00, 0x00, 0x00, 0x00, // input parameter 0x12, 0x00, // command code 0x12, 0x01 }; // checksum for (int i = 0; i < 12; i++) { serial_port.write(tx_cmd[i]); } } // serial port event handler void serialEvent(Serial p) { byte rx_byte; while (p.available() > 0) { // get a single character from the serial port rx_byte = (byte)serial_port.readChar(); println(hex(rx_byte)); } } void draw() { btnOn.Draw(); btnOff.Draw(); } // button class used for the on and off buttons class Button { String label; float x; // top left corner x position float y; // top left corner y position float w; // width of button float h; // height of button // constructor Button(String labelB, float xpos, float ypos, float widthB, float heightB) { label = labelB; x = xpos; y = ypos; w = widthB; h = heightB; } // draw the button in the window void Draw() { fill(218); stroke(141); rect(x, y, w, h, 10); textAlign(CENTER, CENTER); fill(0); text(label, x + (w / 2), y + (h / 2)); } // returns true if the mouse cursor is over the button boolean MouseIsOver() { if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) { return true; } return false; } }
Related Articles
Also see the article on testing the GT-511C3 fingerprint scanner module that uses an Arduino Uno for a basic communications test of the FPS.