CoinIntterupt was not declared in the scope

Hi im having a bit of a problem in code I tried the change my code and used attachedinterrupt ( not very good at it) hope someone can give me an insight of the problem of my code


#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#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
const int coinSlot = 9;
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(2, 3);                  //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;

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

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
  {
    if (coinInserted) {
      coinInserted = false;
      coinCount++;

      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
    }

    void coinSlot() {
      coinCount++ ;
      insert = true;

      else {
        lcd.clear();
      }
    }
  }
}
//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
}

my project consist of
Coinslot sensor 5v to 0v if coin is detected
FingerPirnt
ardiuno relay module

Arduino: 1.8.14 (Windows 10), Board: "Arduino Uno"





















C:\Users\asus\Documents\MARVE THESIS\interrupt\interrupt.ino: In function 'void setup()':

interrupt:39:45: error: 'coinInterrupt' was not declared in this scope

   attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);

                                             ^~~~~~~~~~~~~

C:\Users\asus\Documents\MARVE THESIS\interrupt\interrupt.ino:39:45: note: suggested alternative: 'noInterrupts'

   attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);

                                             ^~~~~~~~~~~~~

                                             noInterrupts

C:\Users\asus\Documents\MARVE THESIS\interrupt\interrupt.ino: In function 'void loop()':

interrupt:72:21: error: a function-definition is not allowed here before '{' token

     void coinSlot() {

                     ^

Multiple libraries were found for "Adafruit_Fingerprint.h"

 Used: C:\Users\asus\Documents\Arduino\libraries\Adafruit_Fingerprint_Sensor_Library

 Not used: C:\Users\asus\Documents\Arduino\libraries\fing

exit status 1

'coinInterrupt' was not declared in this scope

...but I'm not going to share the error messages about functions embedded in other functions, and undefined functions.
How's that approach working for you?

Does software serial even go that fast?

Hint: when you auto format your code, if any function definition does not start on the extreme left edge of the window, you've done something wrong. with your { and } braces.

You'll notice when you've sorted that out, that you still have no function called "coinInterrupt"

I think I warned you on another topic about not wanting/needing an interrupt

can I just do it sir without using interrupt sir? what do I need to use?

It's not so much what you need to use, it's what you must not use.

Mostly, that something is "delay".

You didn't answer my question about software serial

inside here is ? the serialbegin?

No, the "finger.begin"

if I tried to change it to lower value the fingerprint is not working down know why

it will not lightup

I can imagine that transmitting to the fingerprint unit will be OK, but I'm a little surprised the receiver will work at that speed.

even me sir I tried to use it in the enroll code using the 34800 baudrate but its working but in my code I need to change it to hihger value

do I have also problem on my if and else statement sir?

Which one?

(Please can we cut out the "sir"?
By a curious omission of the UK honours system, I am neither a baronet, nor GBE, nor KBE)

OK then. inside my void loop is there a problem thats why coins wont detect sometimes.

I can't comment on code I can't see.

I tried to revise the code again without using the interrupt. If Ijust used my void loop those the code is lacking something?

  int FingerPrintResult = getFingerprintIDez();
  if (FingerPrintResult != -1) { //This function keeps looping and waiting for a fingerprint to be put on the sensor
    OpenDoor();
  }
  else
  {
    // only check for coins to be inserted if we're not opening the door
    coinSlotSignal = digitalRead(coinSlot);

    if (coinSlotSignal < 1) {
      coinCount++;
      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
      delay(100);
      // add a little delay, since the coinslot may show a signal longer
    } else {
      lcd.clear();
    }
  }
}

Please see, and really, really understand, reply #14.

sorry

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


#define coinSlot 9 // different pin!!! untested!!!
#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

int in2 = 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(2, 3);                  //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

int coinCount = 0;
int coinSlotSignal;
int requiredCoins = 1;
boolean coinInserted = false;

void setup()
{
  pinMode(in2, OUTPUT);
  digitalWrite(in2, HIGH);
  pinMode(coinSlot, INPUT_PULLUP);
  lcd.write(EEPROM.read(5));
  Serial.begin(9600);               //Serial begin incase you need to see something on the serial monitor
  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 memor
}

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
  {
    // only check for coins to be inserted if we're not opening the door
    coinSlotSignal = digitalRead(coinSlot);

    if (coinSlotSignal < 1) {
      coinCount++;
      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
      delay(100);
      // add a little delay, since the coinslot may show a signal longer
    } else {
      lcd.clear();
    }
  }
}
//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(in2, LOW); // turn on motor
  delay(5000);
  digitalWrite(in2, HIGH); // turn off motor
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.