Urgent Issues-arduino nano with electrochromic film and SEN0348 dfrobot fingerprint sensor project

Hello. I am creating a credit card shaped device which uses 3V battery-powered electrochromic switchable smart film (a paper-like material which turns transparent when on and opaque when off). I am using a SEN0348 DFRobot fingerprint sensor with the ID809.h library to control the switchable film's on and off function. After a fingerprint is enrolled on startup, the fingerprint scanner should act like a switch and turn on the film (transparent) if recognised. If not recognised, the film stays as is (blurred). I am currently using a breadboard but would like to remove that eventually.

I am unsure of how to wire the film, there are two 15 by 15 (cm) HOHOFILM film pieces which run on two AA batteries, 3V I believe. Also, the battery pack has a button to turn film on/off, so I don't of how to simulate the fingerprint sensor causing the switch instead of the button. The film has two wires, a red positive and black negative. The But I have checked the schematics of the SEN0348 and I'm pretty sure that has been wired correctly. I am using an official Arduino Nano A000005. In the end, I would like everything to be powered by a separate power supply as the credit card case has to be portable obviously.

The main issue I am facing right now is with the fingerprint sensor. When I open the serial monitor, the fingerprint sensor initializes and starts to try and enroll even if my finger is not on the sensor. Also, I don't see any LED light up on the fingerprint sensor (don't know if the SEN0348 has an LED). So whenever I open serial monitor and whether place my finger on the sensor or not, the sensor goes ahead and tries to enroll but the serial monitor says: Failed to enroll fingerprint. Error: 255. I cannot find anything online about this issue. I have bulb shaped two pin LEDs to test with instead of the film, but I don't know if the wiring will be the same.

Please help me wire the electrochromic film and solve the Error Code 255 problem.

Code:

<#include <DFRobot_ID809.h>

DFRobot_ID809 fingerprintSensor;

const int ELECTROCHROMIC_FILM_PIN = 9;
bool printFlag = false;            // Flag to indicate whether to print the message or not
unsigned long lastPrintTime = 0;   // Variable to store the time of the last print

void setup() {
    Serial.begin(9600);
    while (!Serial);

    fingerprintSensor.begin(Serial);  // Use Serial for UART communication
    Serial.println("Fingerprint sensor initialized!");

    pinMode(ELECTROCHROMIC_FILM_PIN, OUTPUT);

    Serial.println("Place your finger on the sensor to enroll an initial fingerprint:");
    enrollFingerprint();  // Enroll a fingerprint during setup
}

void loop() {
    if (Serial.available()) {
        char command = Serial.read();
        if (command == 'e') {
            enrollFingerprint();  // Allow manual enrollment if needed
        }
    }

    if (fingerprintSensor.detectFinger()) {
        if (fingerprintSensor.search()) {
            Serial.println("Fingerprint match found!");
            digitalWrite(ELECTROCHROMIC_FILM_PIN, HIGH);
            Serial.println("Electrochromic film activated!");
            delay(60000);
            digitalWrite(ELECTROCHROMIC_FILM_PIN, LOW);
            Serial.println("Electrochromic film deactivated.");
        } else {
            if (!printFlag) {
                Serial.println("Fingerprint not recognized!");
                lastPrintTime = millis(); // Update the last print time
                printFlag = true;         // Set the print flag to true
            }
        }
    }

    // Check if 5 seconds have passed since the last print
    if (millis() - lastPrintTime >= 5000) {
        // Reset the print flag after 5 seconds
        printFlag = false;
    }

    delay(50);
}

void enrollFingerprint() {
    Serial.println("Place your finger on the sensor for enrollment:");

    int id = fingerprintSensor.getEmptyID();  // Find an empty ID to store the fingerprint
    if (id == -1) {
        Serial.println("No empty ID available.");
        return;
    }

    while (!fingerprintSensor.collectionFingerprint(id)) {
        delay(100);
        Serial.println("Place your finger again.");
    }

    Serial.println("Fingerprint data being processed...");
    delay(2000);

    int result = fingerprintSensor.storeFingerprint(id);
    if (result == 0) {
        Serial.println("Fingerprint enrolled successfully!");
    } else {
        Serial.println("Failed to enroll fingerprint. Error: " + String(result));
    }
}

Wiring connections (fingerprint sensor to nano):
Yellow with yellow jumper(TX) to Nano RX0 pin
Black with brown jumper (RX) to Nano TX1 pin
White with white jumper (power/3.3V) to Nano 3.3V pin
Red with orange jumper (GND) to Nano GND pin
Green and Blue unused

Electrochromic film link: Amazon Electrochromic 15cmx15cm Film HOHOFILM
Fingerprint sensor link: DFRobot SEN0348 fingerprint sensor


IMG_9969
IMG_9971

Link to electrochromic film video: electrochromic film video

P.S: This is my first post so if I missed something sorry!
P.S.S:The project needs to be done by February 20, that is my competition deadline.

Hi @123manav ,
Welcome to the forum..
hmm.. your sensor is using that port, so you probably shouldn't..
Thinking you're going to need a separate port for the sensor, SoftwareSerial should work fine at 9600 for you..
Move the sensor that will correct your main issue i think..

good luck.. ~q

Thank you. I am new to Arduino and to create this code, I have used my limited knowledge and AI help. How do you want me to use SoftwareSerial and what do you mean by needing a separate port?

look here.. built-in-libraries software-serial

create a software serial port and assign it to the sensor, move the sensor off the built in serial..

~q

could use like pins 2 and 3..
then move them yellow and brown wires..
pins 0 and 1 are on board serial used for programming and sometimes debugging..
having something wired to these pins may even inhibit programming..
~q

ok will try. yellow to pin 2 and brown to pin 3 or does it matter?

it matters..

#include <SoftwareSerial.h>


const byte rxPin = 2;
const byte txPin = 3;


// Set up a new SoftwareSerial object
SoftwareSerial senSerial (rxPin, txPin);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Ready..");
 //init sesnor serial..
  senSerial.begin(9600);


}

void loop() {
  // put your main code here, to run repeatedly:

}

~q

hmm the code still has the error 255

this is the code:


#include <DFRobot_ID809.h>
#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

DFRobot_ID809 fingerprintSensor;
SoftwareSerial senSerial(rxPin, txPin);

const int ELECTROCHROMIC_FILM_PIN = 9;
bool printFlag = false;            // Flag to indicate whether to print the message or not
unsigned long lastPrintTime = 0;   // Variable to store the time of the last print

void setup() {
    Serial.begin(9600);
    while (!Serial);

    senSerial.begin(9600);  // Start software serial communication
    fingerprintSensor.begin(senSerial);  // Use software serial for UART communication
    Serial.println("Fingerprint sensor initialized!");

    pinMode(ELECTROCHROMIC_FILM_PIN, OUTPUT);

    Serial.println("Place your finger on the sensor to enroll an initial fingerprint:");
    enrollFingerprint();  // Enroll a fingerprint during setup
}

void loop() {
    if (Serial.available()) {
        char command = Serial.read();
        if (command == 'e') {
            enrollFingerprint();  // Allow manual enrollment if needed
        }
    }

    if (fingerprintSensor.detectFinger()) {
        if (fingerprintSensor.search()) {
            Serial.println("Fingerprint match found!");
            digitalWrite(ELECTROCHROMIC_FILM_PIN, HIGH);
            Serial.println("Electrochromic film activated!");
            delay(60000);
            digitalWrite(ELECTROCHROMIC_FILM_PIN, LOW);
            Serial.println("Electrochromic film deactivated.");
        } else {
            if (!printFlag) {
                Serial.println("Fingerprint not recognized!");
                lastPrintTime = millis(); // Update the last print time
                printFlag = true;         // Set the print flag to true
            }
        }
    }

    // Check if 5 seconds have passed since the last print
    if (millis() - lastPrintTime >= 5000) {
        // Reset the print flag after 5 seconds
        printFlag = false;
    }

    delay(50);
}

void enrollFingerprint() {
    Serial.println("Place your finger on the sensor for enrollment:");

    int id = fingerprintSensor.getEmptyID();  // Find an empty ID to store the fingerprint
    if (id == -1) {
        Serial.println("No empty ID available.");
        return;
    }

    while (!fingerprintSensor.collectionFingerprint(id)) {
        delay(100);
        Serial.println("Place your finger again.");
    }

    Serial.println("Fingerprint data being processed...");
    delay(2000);

    int result = fingerprintSensor.storeFingerprint(id);
    if (result == 0) {
        Serial.println("Fingerprint enrolled successfully!");
    } else {
        Serial.println("Failed to enroll fingerprint. Error: " + String(result));
    }
}

garbage is gone.. :slight_smile:
wonder, did you already change the baud rate, default is 115200??
wiki.dfrobot Capacitive Fingerprint Sensor
The have nice wikis..
Look at check module baud rate demo code..

~q

same error

this is the code now:

#include <DFRobot_ID809.h>
#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

DFRobot_ID809 fingerprintSensor;
SoftwareSerial senSerial(rxPin, txPin);

const int ELECTROCHROMIC_FILM_PIN = 9;
bool printFlag = false;            // Flag to indicate whether to print the message or not
unsigned long lastPrintTime = 0;   // Variable to store the time of the last print

void setup() {
    Serial.begin(115200); // Change baud rate for Serial communication
    while (!Serial);

    senSerial.begin(115200);  // Start software serial communication with 115200 baud
    fingerprintSensor.begin(senSerial);  // Use software serial for UART communication
    Serial.println("Fingerprint sensor initialized!");

    pinMode(ELECTROCHROMIC_FILM_PIN, OUTPUT);

    Serial.println("Place your finger on the sensor to enroll an initial fingerprint:");
    enrollFingerprint();  // Enroll a fingerprint during setup
}

void loop() {
    if (Serial.available()) {
        char command = Serial.read();
        if (command == 'e') {
            enrollFingerprint();  // Allow manual enrollment if needed
        }
    }

    if (fingerprintSensor.detectFinger()) {
        if (fingerprintSensor.search()) {
            Serial.println("Fingerprint match found!");
            digitalWrite(ELECTROCHROMIC_FILM_PIN, HIGH);
            Serial.println("Electrochromic film activated!");
            delay(60000);
            digitalWrite(ELECTROCHROMIC_FILM_PIN, LOW);
            Serial.println("Electrochromic film deactivated.");
        } else {
            if (!printFlag) {
                Serial.println("Fingerprint not recognized!");
                lastPrintTime = millis(); // Update the last print time
                printFlag = true;         // Set the print flag to true
            }
        }
    }

    // Check if 5 seconds have passed since the last print
    if (millis() - lastPrintTime >= 5000) {
        // Reset the print flag after 5 seconds
        printFlag = false;
    }

    delay(50);
}

void enrollFingerprint() {
    Serial.println("Place your finger on the sensor for enrollment:");

    int id = fingerprintSensor.getEmptyID();  // Find an empty ID to store the fingerprint
    if (id == -1) {
        Serial.println("No empty ID available.");
        return;
    }

    while (!fingerprintSensor.collectionFingerprint(id)) {
        delay(100);
        Serial.println("Place your finger again.");
    }

    Serial.println("Fingerprint data being processed...");
    delay(2000);

    int result = fingerprintSensor.storeFingerprint(id);
    if (result == 0) {
        Serial.println("Fingerprint enrolled successfully!");
    } else {
        Serial.println("Failed to enroll fingerprint. Error: " + String(result));
    }
}

do you think the sensor is defective?

idk, honestly..
try Sample Code 3 from the wiki, see if it adds fingers..
~q

sample code 6 is pretty sweet..
can switch between detecting and registering by long pressing..

you know, if i had one of these, probably the first thing I would try is led control, its got like all kind of options..

~q

so i havent changed any of the wiring and when i try sample 3 the serial monitor displays an error saying communication with device failed, please check connection.

rlly appreciate your help though

ok, fall back to sample code 1, check baud rate..
~q

now the serial monitor only shows a series of periods

this is the code correct?:

/*!
 * @file queryDeviceBPS.ino
 * @brief Query device baud rate
 * @n Experiment Phenomenon:Query device baud rate, and print from serial port 
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [Eddard](Eddard.liu@dfrobot.com)
 * @version  V1.0
 * @date  2020-03-19
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_ID809
*/
#include <DFRobot_ID809.h>

/*Use software serial when using UNO or NANO*/
#if ((defined ARDUINO_AVR_UNO) || (defined ARDUINO_AVR_NANO))
    #include <SoftwareSerial.h>
    SoftwareSerial Serial1(2, 3);  //RX, TX
    #define FPSerial Serial1
#else
    #define FPSerial Serial1
#endif

DFRobot_ID809 fingerprint;

uint32_t ID809_BPS[5] = {9600, 19200, 38400, 57600, 115200};
uint8_t i = 0;

void setup(){
  /*Init print serial port */
  Serial.begin(9600);
  /*Test module baud rate */
  FPSerial.begin(ID809_BPS[i]);
  Serial.print(".");
  while(fingerprint.begin(FPSerial) == false){
    i++;
    FPSerial.begin(ID809_BPS[i]);
    Serial.print(".");
  }
  Serial.println(" ");
}

void loop(){
  Serial.print("Module baud rate:");
  Serial.println(ID809_BPS[i-1]);
  Serial.println("-----------------------------");
  delay(1000);
}

check connections..
it's trying to start the module on every baud with a dot in between..
~q

I will say this, I am a bit worried after I read the one and only review from the link you posted to amazon..
so, yeah maybe could be a bad sensor.. :frowning:
sorry.. ~q

Probably. i havent seen any LEDs light up or any sign of working. the wiring is all correct. thanks for helping out anyways. i will keep this post up incase somebody figures something out.

that stinks and your welcome, anytime..
~q

The electrochromic film runs on very low current 50-65VAC, 60 Hz, not 3V. Inside the battery pack is a circuit that generates the AC voltage. If that film, or the AC wiring to it comes anywhere near the Arduino wiring, it will play havoc with a running program.

To switch the film on/off, open up the battery pack, replace the switch with relay contacts, and keep the associated wiring well away from the rest of the project.