1

The project is Like a secured PiggyBank but it will count the coins inside it. Im using a coin sensor at default it has 5v, then goes to zer if inserted with a coin. I have 2 codes The one was form my old project then second one was a coinslot code got in youtube.

Im hoping someone can guide me where to deelte some codes, then add it at one lsit of code. Behavior of the project -Start > Display Total : Amount > if I will unlock the solenoid it will display Welcome "NAME" . Hope you can get my Idea. Some of code inside of the solenoid was not perfect sorry for that I just get it from scrath without proper knowledge.

This is code for FINGERPRINT TO SOLENOID LOCK

#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.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

int in2 = 4;

int But1=8;  // In order to add a push button I got the 5v from the pin 8 instead of "5v" arduino pin
int But2=9;

String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
                                                 //The first on which is Names[0] : Yassine 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

void setup() 
{
  pinMode(in2, OUTPUT);
  digitalWrite(in2, HIGH);
  pinMode(But1, OUTPUT);    //Push button stuff, I made the pin 8 permanent LOW level
  digitalWrite(But1,LOW);
  pinMode(But2,INPUT_PULLUP);     //And I read the button state on pin 9
 
  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 memory
  delay(2000);
  introScreen();
}

void loop()                     
{
  int result = getFingerprintIDez();  //This function keeps looping and waiting for a fingerprint to be put on the sensor
  //delay(50);
  bool Button1=digitalRead(But2);  //Reading the state of the pushbutton
  if(Button1==LOW or result >= 0){
    //If the button is pressed it opens the doorlock as the button is meant to be inside
    OpenDoor();
    introScreen();
  }
}

void introScreen()
{
    lcd.clear();
    lcd.print("Place finger");
}

//Main function taken from the "fingerprint" example and modified
//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);
    introScreen();
    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;
}

/*The two following functions depends on your locking system
 *mine has a DC motor that should turn in both ways for opening and closing
 *that's why I'm using H bridge, you could have a solenoid with a transistor
 *then you'll need only opening sequence but controlling the transistor
 *as the closing is spring loaded...
 */


void OpenDoor(){
  digitalWrite(in2, LOW); // turn on motor
  delay(5000);
  digitalWrite(in2, HIGH); // turn off motor
}

This code is for COINSLOT

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define coinSlot 6


LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified module

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


void setup() {
  Serial.begin(9600); 
 pinMode(coinSlot, INPUT_PULLUP);

 lcd.setBacklightPin(3,POSITIVE);
 lcd.setBacklight(LOW); // You can turn the backlight off by setting it to LOW instead of HIGH
 lcd.begin(16, 2);
lcd.write(EEPROM.read(5));
}

void loop() {
  while(!coinInserted){
  coinSlotSignal = digitalRead(coinSlot);
  if(coinSlotSignal < 1) {
    coinCount += 1;
    coinInserted = true;
EEPROM.write(0,coinCount);
Serial.println(EEPROM.read(0)); 


lcd.setCursor(0,0);
lcd.print("TOTAL:");
lcd.setCursor(0,1);
lcd.print(coinCount);
}
  }
  
while(coinInserted) {
  coinSlotSignal = digitalRead(coinSlot);
  if(coinSlotSignal >0) {
    coinInserted = false;
  
  }
}
if(coinCount >= requiredCoins) {
  delay(1500);
}
}
7
  • 1
    you cannot have two void setup() ... put codes from both into one ... same with void loop()
    – jsotola
    May 14 at 23:39
  • please fix the indentation of your code ... it will be much easier to follow the code flow and it will make it more difficult to make mistakes
    – jsotola
    May 14 at 23:42
  • why does PROJECT BEHAVIOR say nothing about the coinslot? ... is coinslot part of the project or not? ... it also does not say anything about the lock solenoid ....... not a very good description of the project behavior .... a clear, detailed description of the project behavior usually translates into code almost directly
    – jsotola
    May 15 at 0:10
  • 1
    I don't know how to sink the 2 project code in to 1 code :( May 16 at 4:40
  • 1
    I read the article sir and try to sink the code but its giving a short of a problem that I cant find why its causing it but try to see the error code it keep on saying that "expected unqualified-id before 'while' May 16 at 13:51

Browse other questions tagged or ask your own question.