You can read this and other amazing tutorials on ElectroPeak's official website.
OverviewNowadays, learning about IoT devices operation and implementation is so essential due to the increasing use of IoT systems. In this tutorial, we are going to make a fingerprint attendance device with Arduino, which in addition to storing the log-in information and working hours on the memory card, uploads this information on the ThingSpeak platform as soon as it is connected to the Internet and you can download this information from the panel in various formats, such as CSV.
What You Will Learn- Working with fingerprint sensors
- Uploading data on ThingSpeak using NodeMCU
- Make an attendance device with the fingerprint sensor and Arduino
The IoT (Internet of Things) envisions a world where a number of things are connected to the Internet, interacting with individuals and other devices, and usually, uploading data to the cloud for analysis.
ThingSpeak is an IoT platform that lets you display and collect live data in cloud computing.
Follow the steps below to start the ThingSpeak connection:
Step 1) Enter the ThingSpeak.com website and create an account.
Step 2) Login after activating your account and click on New Channel in the My Channel section.
Step 3) In the new window opened for you, write a name for your panel and any description if it is necessary. Determine the number of fields that you need by assigning their names. The remaining parts are optional. Save the panel after completing the information.
Step 4) Now go to API Keys in your panel.
Step 5) You need the Channel ID and Write API Key to transmit data, so write them down.
Step 6) Download the ThingSpeak library and add it to your Arduino IDE.
Step 7) Go to the Arduino IDE. Open the WriteMultipleFiels from examples part and enter the SSID, Password, Channel ID, and Write API Key values.
/*
WriteMultipleFields
Description: Writes values to fields 1,2,3,4 and status in a single Thingspeak update every 20 seconds.
Hardware: ESP8266 based boards
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and Thingspeak channel details. !!!
Note:
- Requires ESP8266WiFi library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details.
- Select the target hardware from the Tools->Board menu
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
Thingspeak ( https://www.Thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
analyze live data streams in the cloud. Visit https://www.Thingspeak.com to sign up for a free account and create a channel.
Documentation for the Thingspeak Communication Library for Arduino is in the README.md folder where the library was installed.
See https://www.mathworks.com/help/Thingspeak/index.html for the full Thingspeak documentation.
For licensing information, see the accompanying license file.
Copyright 2018, The MathWorks, Inc.
*/
#include "Thingspeak.h"
#include "secrets.h"
#include <ESP8266WiFi.h>
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Initialize our values
int number1 = 0;
int number2 = random(0,100);
int number3 = random(0,100);
int number4 = random(0,100);
String myStatus = "";
void setup() {
Serial.begin(115200); // Initialize serial
WiFi.mode(WIFI_STA);
Thingspeak.begin(client); // Initialize Thingspeak
}
void loop() {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
// set the fields with the values
Thingspeak.setField(1, number1);
Thingspeak.setField(2, number2);
Thingspeak.setField(3, number3);
Thingspeak.setField(4, number4);
// figure out the status message
if(number1 > number2){
myStatus = String("field1 is greater than field2");
}
else if(number1 < number2){
myStatus = String("field1 is less than field2");
}
else{
myStatus = String("field1 equals field2");
}
// set the status
Thingspeak.setStatus(myStatus);
// write to the Thingspeak channel
int x = Thingspeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// change the values
number1++;
if(number1 > 99){
number1 = 0;
}
number2 = random(0,100);
number3 = random(0,100);
number4 = random(0,100);
delay(20000); // Wait 20 seconds to update the channel again
}
After uploading the code, you will see some random numbers uploaded in fields 1 to 4 of your panel. The same structured code is used in the attendance system for uploading data.
Note
Wait at least 15 seconds between each time you upload the data on the ThingSpeak panel.
In this system, after registering the entry and exit of a person by his fingerprint, the information including date, name, time of arrival, time of departure and working hours for the employee are stored on the SD card. Then this information will be sent to ThingSpeak at the time you have specified. In the absence of the Internet connection, unpublished data is stored and will be forwarded to ThingSpeak as soon as it is connected to the Internet. Since the information is stored in the EEPROM of the microcontroller, they will not be lost in case of a power outage.
CircuitAfter connecting all modules, put the LCD shield on the Arduino.
Tip
Since the LCD Shield covers some of the Arduino pins, you can border wire to a specific pin from the bottom of the board, if you need these pin.
CodeYou need the following libraries for this code:
Adafruit-Fingerprint-Sensor-Library
Now download the following code and upload it to your Arduino. This code is written for 11 people with default names, but you can change them and remove it from the default mode. To register a new name, simply connect the device to your computer and press the key to enter the register mode, then open the Serial Monitor and follow the registration process as is shown on the Serial Monitor.
Download the code from attachmentes:
You can learn more about using an SD card, the clock module, and the LCD in the following links:
SD Card Module w/ Arduino: How to Read/Write Data
How to Use DS1307 RTC Module with Arduino & Make a Reminder
Absolute Beginner’s Guide to TFT LCD Displays by Arduino.
NodeMCU executes the task of uploading the information in this system. It takes the uploading information from Arduino through the serial port and returns the status of uploading to Arduino. Upload the following code on your NodeMCU.
#include "Thingspeak.h"
#include ESP8266WiFi.h>
char ssid[] = "YOUR SSID";
char pass[] = "SSID PASSWORD";
WiFiClient client;
unsigned long myChannelNumber = YOUR CHANNEL ID;
const char * myWriteAPIKey = "YOUR CHANNEL WRITE API KEY";
String Final = "";
String Date = "";
String Enter = "";
String Exit = "";
String Name = "";
String WT = "";
void String_Analyze(String input) {
int index1, index2, index3, index4;
index1 = input.indexOf('*', 0);
index2 = input.indexOf('*', index1 + 1);
index3 = input.indexOf('*', index2 + 1);
index4 = input.lastIndexOf('*');
Name = input;
Date = input;
Enter = input;
Exit = input;
WT = input;
Name.remove(index1);
Date.remove(index2);
Date.remove(0, index1 + 1);
Enter.remove(index3);
Enter.remove(0, index2 + 1);
Exit.remove(index4);
Exit.remove(0, index3 + 1);
WT.remove(0, index4 + 1);
}
void Get_String()
{
while (Serial.available()) {
Final = Serial.readString(); // read the incoming data as string
//Serial.println(Final);
}
}
void setup() {
Serial.begin(9600);
WiFi.mode(WIFI_STA);
Thingspeak.begin(client);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
if (WiFi.status() != WL_CONNECTED) {
//Serial.print("Attempting to connect to SSID: ");
// Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print("0");
delay(5000);
}
}
digitalWrite(LED_BUILTIN, LOW);
//Serial.println("\nConnected.");
Get_String();
String_Analyze(Final);
if (!Final.equals(""))
{
Thingspeak.setField(1, Date);
Thingspeak.setField(2, Name);
Thingspeak.setField(3, Enter);
Thingspeak.setField(4, Exit);
Thingspeak.setField(5, WT);
int x = Thingspeak.writeFields(myChannelNumber, myWriteAPIKey);
if (x == 200) {
delay(100);
Serial.print("1");
}
else {
delay(100);
Serial.print("0");
}
delay(17000);
Final = "";
}
First, change the Channel ID and Write API Key according to your ThingSpeak Panel.
The String_Analuze ();
function in this code divides the NodeMCU input strings into the date, name, arrival and departure time, and working hours, and sends this information to ThingSpeak. Then if the uploading process is successful, it sends the character “1”, and otherwise it sends the character “0” to the Arduino.
You can use the following maps and Plexiglass with different colors or any other material to build the body of the attendance device.
Download the device body laser cut map from attachments:
After placing electronic components and assembling the entire body, install it in the desired location. Now, just plug a 12V adapter to the device and it starts working.
What's Next?- Try to use more icons on the LCD.
- Try to add an RFID option to the system.
- Try to upload the data on the google spreadsheets instead of ThingSpeak.
If you find this tutorial helpful and interesting please like us on Facebook.
Comments
Please log in or sign up to comment.