Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Windows - Arduino S...
 
Share:
Notifications
Clear all

[Solved] Windows - Arduino Solenoid Lock using FingerPrint with CoinCounter

65 Posts
2 Users
1 Likes
13.4 K Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2675
 

Alright! Cool 😊 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
Topic starter  

@hans Thanks for being so responsive sir ☺️


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2675
 

You're most welcome 😊 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
Topic starter  

@hans  

 

I tried to use the code sir then If I tied to inserct coin it mixed with the text

 

The number below was the coincount it wont dissaper it keep on the below

 

here is the full code

 

#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define coinSlot 3 // coinslot 5v to 0v if coin passes on the sensor
#define I2C_ADDR 0x27          //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define ReplaceTotalTime 2000
unsigned long StartTotalTime;
int relayPin = 4;

String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
//The first on which is Names[0] : "" has the ID 1 in the fingerprint sensor

SoftwareSerial mySerial(0, 2);                  //Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);                    //Fingerprint sensor declaring

volatile int coinCount = 0;
int requiredCoins = 1;
boolean coinInserted = false;
int coinSlotSignal;
void setup()
{
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  pinMode(coinSlot, INPUT_PULLUP);
  lcd.write(EEPROM.read(5));
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(3), coinInterrupt, FALLING);
  Serial.print(coinSlot);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  delay(2000);
}
void coinInterrupt() {
      coinCount++ ;
      coinInserted = true;
}
void loop() {
  int FingerPrintResult = getFingerprintIDez();


  if (FingerPrintResult != -1) { //This function keeps looping and waiting for a fingerprint to be put on the sensor
    OpenDoor();
  }
  else
  {
    coinSlotSignal = digitalRead(coinSlot);

    if (coinInserted) {
      coinInserted = false;
      
      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
  StartTotalTime = millis(); // store this time
    } else {
      if(StartTotalTime+ReplaceTotalTime<millis()) { // 2 seconds passed? Then show "WELCOME"
        lcd.setCursor(0, 0);
        lcd.print("Biometric Coin");
      }
    }
  }
}

//Only the modifications are commented
int getFingerprintIDez() {
  uint8_t p = finger.getImage();        //Image scanning
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();               //Converting
  if (p != FINGERPRINT_OK)  return -1;

  lcd.clear();                     //And here we write a message or take an action for the denied template
  p = finger.fingerFastSearch();     //Looking for matches in the internal memory
  if (p != FINGERPRINT_OK) {         //if the searching fails it means that the template isn't registered
    lcd.print("Access denied");
    delay(2000);
    return -1;
  }
  //If we found a match we proceed in the function

  lcd.print("Welcome");                  //Printing a message for the recognized template
  lcd.setCursor(2, 1);
  lcd.print(Names[finger.fingerID - 1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
  return finger.fingerID;
}
void OpenDoor() {
  digitalWrite(relayPin, LOW); // turn on solenoidlock
  delay(5000);
  digitalWrite(relayPin, HIGH); // turn off solenoidlock
}

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2675
 

Before printing a new message, you should probably call lcd.clear(). I hope that is the right function to clear the screen.

I've added two lcd.clear() lines in void loop(), which clears the display before displaying a message (total or welcome message).

Note: I see that 'coinSlotSignal" is not used anywhere, so this may no longer be needed in the code (see comments in the code below).

#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>

#define coinSlot 3      // coinslot 5v to 0v if coin passes on the sensor

#define I2C_ADDR 0x27   // LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

#define ReplaceTotalTime 2000
unsigned long StartTotalTime;

int relayPin = 4;

String Names[] = { "RAVEN", "Surtr", "Tech",};  // Those are the names affected to the fingertemplates IDs
                                                //The first on which is Names[0] : "" has the ID 1 in the fingerprint sensor
                                                
SoftwareSerial mySerial(0, 2);                  // Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); // LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);   // Fingerprint sensor declaring

volatile int coinCount = 0;
int requiredCoins = 1;
boolean coinInserted = false;
int coinSlotSignal; // <-- I don't think this is needed anymore

void setup()
{
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  pinMode(coinSlot, INPUT_PULLUP);
  lcd.write(EEPROM.read(5));
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(3), coinInterrupt, FALLING);
  Serial.print(coinSlot);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  delay(2000);
}

void coinInterrupt() {
      coinCount++ ;
      coinInserted = true;
}

void loop() {
  int FingerPrintResult = getFingerprintIDez();

  if (FingerPrintResult != -1) { //This function keeps looping and waiting for a fingerprint to be put on the sensor
    OpenDoor();
  }
  else
  {
    coinSlotSignal = digitalRead(coinSlot); // <-- I don't think this is needed anymore

    if (coinInserted) {
      coinInserted = false;
      
      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.clear(); // <--- added this line
      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
      StartTotalTime = millis(); // store this time
    } else {
      if(StartTotalTime+ReplaceTotalTime<millis()) { // 2 seconds passed? Then show "WELCOME"
        lcd.clear(); // <--- added this line
        lcd.setCursor(0, 0);
        lcd.print("Biometric Coin");
      }
    }
  }
}

//Only the modifications are commented
int getFingerprintIDez() {
  uint8_t p = finger.getImage();        //Image scanning
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();               //Converting
  if (p != FINGERPRINT_OK)  return -1;

  lcd.clear();                     //And here we write a message or take an action for the denied template
  p = finger.fingerFastSearch();     //Looking for matches in the internal memory
  if (p != FINGERPRINT_OK) {         //if the searching fails it means that the template isn't registered
    lcd.print("Access denied");
    delay(2000);
    return -1;
  }
  //If we found a match we proceed in the function

  lcd.print("Welcome");                  //Printing a message for the recognized template
  lcd.setCursor(2, 1);
  lcd.print(Names[finger.fingerID - 1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
  return finger.fingerID;
}
void OpenDoor() {
  digitalWrite(relayPin, LOW); // turn on solenoidlock
  delay(5000);
  digitalWrite(relayPin, HIGH); // turn off solenoidlock
}

 


   
ReplyQuote
Page 5 / 5
Share: