We are first going to set up the fingerprint sensor device. As the library for the fingerprint sensor was designed for Arduino, we are going to use an Arduino Uno for this part of the project. For web connectivity, we are going to use an Adafruit CC3000 breakout board.
Let’s start by connecting the power supply:
- Connect the 5V pin from the Arduino board to the red power rail
- The GND from Arduino the blue power rail on the breadboard.
Now, let’s connect the fingerprint sensor.
- First, connect the power, by connecting the cables to their respective color on the breadboard: Red to +5V rail, Black to ground rail
- Then, connect the white wire from the sensor to Arduino pin 4
- & the green wire to pin number 3.
Now, the CC3000 module.
- First, connect the IRQ pin of the CC3000 board to pin number 2 of the Arduino board
- VBAT to pin 5
- CS to pin 10.
- Then, you need to connect the SPI pins to the Arduino board: MOSI, MISO, and CLK go to pins 11, 12, and 13, respectively.
- Finally, take care of the power supply: Vin goes to the Arduino 5V (red power rail), and GND to GND (blue power rail).
This is the completely assembled project:
Before building the sketch that will actually upload data to the Adafruit IO platform, we need to go through the process of enrolling your fingerprint into the sensor itself, so it can be recognized later. I recommend doing that with the Arduino board itself, and you can find the whole procedure at:
https://learn.adafruit.com/adafruit-optical-fingerprint-sensor/enrolling-with-arduino
At this point, also create an account on Adafruit IO if that's not done yet:
Once that's done, you can move on to the next step: building the sketch that will send data to Adafruit IO. As the sketch is really long, I will only highlight the most important parts here, and link later to the GitHub repository of the project.
It starts by including all the required libraries:
#include <Adafruit_SleepyDog.h> #include <Adafruit_CC3000.h> #include <SPI.h> #include "Adafruit_MQTT.h" #include "Adafruit_MQTT_CC3000.h" #include <Adafruit_Fingerprint.h> #include <SoftwareSerial.h>
Then, you'll need to modify the sketch by inserting your WiFi network SSID & password:
#define WLAN_SSID "your_wifi_ssid" #define WLAN_PASS "your_wifi_password" #define WLAN_SECURITY WLAN_SEC_WPA2
After that, you also need to enter your Adafruit IO username & AIO key:
#define AIO_SERVER "io.adafruit.com" #define AIO_SERVERPORT 1883 #define AIO_USERNAME "adafruit_io_username" #define AIO_KEY "adafruit_io_key"
Then, we also define a feed specific for the fingerprint sensor. It will simply contain '1' if the sensor has just been activated with a valid fingerprint:
const char FINGERPRINT_FEED[] PROGMEM = AIO_USERNAME "/feeds/fingerprint"; Adafruit_MQTT_Publish fingerprint = Adafruit_MQTT_Publish(&mqtt, FINGERPRINT_FEED);
We also need to create as SoftwareSerial instance, for the fingerprint sensor:
SoftwareSerial mySerial(3, 4);
After that, we can actually create the instance for the sensor:
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Inside the sketch, we specify which fingerID should actually activate the lock later on. I used 0, which is the ID of the first fingerprint I enrolled into the sensor:
int fingerID = 0;
Then, we'll define a counter & a delay for the project. Basically, we want the lock to automatically close again after it's been opened. I used 10 seconds here as an example, but you can of course modify this delay at your convenience:
int activationCounter = 0; int lastActivation = 0; int activationTime = 10 * 1000;
Then, in the setup() function of the sketch, we simply initialise the sensor, and also connect the CC3000 chip to your WiFi network.
In the loop() function of the sketch, we then connect to Adafruit IO using:
MQTT_connect();
Once we are sure to be connected to the Adafruit IO platform, we check for the last recognised fingerprint. If it matches, and the lock is currently not activated, we then send a '1' message to the feed on Adafruit IO:
if (fingerprintID == fingerID && lockState == false) { Serial.println(F("Access granted!")); lockState = true; state = 1; if (! fingerprint.publish(state)) { Serial.println(F("Failed")); } else { Serial.println(F("OK!")); } lastActivation = millis(); }
Still in the loop() function of the sketch, if the lock is currently active, and the delay we defined earlier has been reached, we send a '0' message to Adafruit IO:
if ((activationCounter - lastActivation > activationTime) && lockState == true) { lockState = false; state = 0; if (! fingerprint.publish(state)) { Serial.println(F("Failed")); } else { Serial.println(F("OK!")); } }
Note that you can find the latest version of the code on the GitHub repository of the project:
https://github.com/openhomeautomation/lock-control-fingerprint
It's now time to test the project! Use the Arduino library manager to download all the required libraries of this project.
Make sure that you modified the code with your settings, and then upload it to the Arduino board. Also open the Serial monitor.
Then, once the Arduino board is connected to the WiFi network, you should see that the fingerprint sensor is blinking with red light. Place the finger that you enrolled earlier on the sensor. You should see on the Serial monitor the ID number of the recognised finger, and if it matches, you should also see an 'OK!' message meaning that data has been send to Adafruit IO.
You can then also check on Adafruit IO, in your feeds, to make sure that the feed has been updated with the correct data. Then, after the delay defined in the code, this feed should automatically return to '0'.
Text editor powered by tinymce.