user37101: I did a project with a fingerprint sensor. You can do the fingerprinting process by typing down 4 on the serial port, but in the same time i want to do this process with pressing another button.Can someone help me?

code  http://www.heypasteit.com/clip/0IIQ6G 
> #define  VB

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>

SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

char data;
unsigned int p;
uint8_t id;

void setup()  
{
  Serial.begin(9600);
  finger.begin(57600);
  Serial.println("Sensore baglaniyor!");  
  if(finger.verifyPassword())
  {
    Serial.println("Baglanti basarili!");
  }
  else
  {
    Serial.println("Sensor bulunamadi ");
    while (1);
  }
}

void loop()
{
  delay(100);

  if(Serial.available()>0)
  {
    data=Serial.read();

    if(data=='1')
    {
      Serial.println("Delete all ID records");
      finger.emptyDatabase();
      delay(50);
      EEPROM.write(0,-1);    //reset ID counter
    }
    else if(data=='3')
    {     
      id = EEPROM.read(0) + 1;    //get next available ID
      Serial.print("Enrolling ID #");
      Serial.println(id);  
      getFingerprintEnroll(id);
      delay(50);
      EEPROM.write(0, id);        //save current ID
    }

    while (data=='4')
    {
      getFingerprintID();  
      delay(50);  

    }
  }
}

uint8_t getFingerprintEnroll(uint8_t id)
{ 
  uint8_t p = -1;
  Serial.println("Waiting for valid finger to enroll");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif  
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz(1);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  }

  Serial.println("Remove finger");
  delay(1000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER)
  {
    p = finger.getImage();
  }

  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz(2);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  default:
    Serial.println("Unknown error");
    return p;
  }

  p = finger.createModel();
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Prints matched!");
    break;
  case FINGERPRINT_ENROLLMISMATCH:
    Serial.println("Fingerprints did not match");
    return -1;
    break;
  default:
    Serial.println("Unknown error");
    return -1;
    break;
  } 

  p = finger.storeModel(id);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Stored!");
    break;
  default: 
    Serial.println("Unknown error");
    return p; 
    break;

  } 
} 

int getFingerprintID()
{ 
  p = -1;
  Serial.println("Waiting for registered ID");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz();
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  default:
    Serial.println("Unknown error");
    return -1;
  }

  p = finger.fingerFastSearch();
  switch (p)
  { 
  case FINGERPRINT_OK:
    Serial.println("Found a print match!");
    break;
  case FINGERPRINT_NOTFOUND:
    Serial.println("Did not find a match");
    return -1;
    break;  
  default:
    Serial.println("Unknown error");
    return -1;  
    break;
  }  

  digitalWrite(A1, HIGH);
  delay(500);
  digitalWrite(A1, LOW);
  delay(2000);

  Serial.print("Found ID #");
  Serial.print(finger.fingerID); 
  Serial.print(" with accuracy value of ");
  Serial.println(finger.confidence); 
  return finger.fingerID;
}


user-1: Take a look at the Button sketch in the examples menu in the Arduino IDE. That is the simplest example of how to use a button in Arduino.
Circuit
This is the test circuit. When you press the button, the built LED turns on/off.  The circuit is applicable to any Arduino Uno, Mini, etc. The two wires at right are not really needed, but it doesn't hurt if you put them in the breadboard).
Note: What follows is an excerpt from https://www.arduino.cc/en/Tutorial/Button.

Connect three wires to the board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10K ohm) to ground. The other leg of the button connects to the 5 volt supply.
When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that we read a HIGH.
You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.
If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit. 
Code
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}


37101: <p>I did a project with a fingerprint sensor. You can do the fingerprinting process by typing down 4 on the serial port, but in the same time i want to do this process with pressing another button.Can someone help me?</p>

<p><a href="https://i.stack.imgur.com/4nC8u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4nC8u.png" alt="Fingerprint command"></a></p>

<p>code  <a href="http://www.heypasteit.com/clip/0IIQ6G" rel="nofollow noreferrer">http://www.heypasteit.com/clip/0IIQ6G</a>   </p>

<pre><code>&gt; #define  VB

#include &lt;Adafruit_Fingerprint.h&gt;
#include &lt;SoftwareSerial.h&gt;
#include &lt;EEPROM.h&gt;

SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&amp;mySerial);

char data;
unsigned int p;
uint8_t id;

void setup()  
{
  Serial.begin(9600);
  finger.begin(57600);
  Serial.println("Sensore baglaniyor!");  
  if(finger.verifyPassword())
  {
    Serial.println("Baglanti basarili!");
  }
  else
  {
    Serial.println("Sensor bulunamadi ");
    while (1);
  }
}

void loop()
{
  delay(100);

  if(Serial.available()&gt;0)
  {
    data=Serial.read();

    if(data=='1')
    {
      Serial.println("Delete all ID records");
      finger.emptyDatabase();
      delay(50);
      EEPROM.write(0,-1);    //reset ID counter
    }
    else if(data=='3')
    {     
      id = EEPROM.read(0) + 1;    //get next available ID
      Serial.print("Enrolling ID #");
      Serial.println(id);  
      getFingerprintEnroll(id);
      delay(50);
      EEPROM.write(0, id);        //save current ID
    }

    while (data=='4')
    {
      getFingerprintID();  
      delay(50);  

    }
  }
}

uint8_t getFingerprintEnroll(uint8_t id)
{ 
  uint8_t p = -1;
  Serial.println("Waiting for valid finger to enroll");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif  
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz(1);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  }

  Serial.println("Remove finger");
  delay(1000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER)
  {
    p = finger.getImage();
  }

  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz(2);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  default:
    Serial.println("Unknown error");
    return p;
  }

  p = finger.createModel();
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Prints matched!");
    break;
  case FINGERPRINT_ENROLLMISMATCH:
    Serial.println("Fingerprints did not match");
    return -1;
    break;
  default:
    Serial.println("Unknown error");
    return -1;
    break;
  } 

  p = finger.storeModel(id);
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Stored!");
    break;
  default: 
    Serial.println("Unknown error");
    return p; 
    break;

  } 
} 

int getFingerprintID()
{ 
  p = -1;
  Serial.println("Waiting for registered ID");
  while (p != FINGERPRINT_OK)
  {
    p = finger.getImage();
    switch (p)
    {
    case FINGERPRINT_OK:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
#if !defined (VB)
      Serial.print(".");
#endif
      break;
    default:
#if !defined (VB)
      Serial.println();
#endif
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz();
  switch (p)
  {
  case FINGERPRINT_OK:
    Serial.println("Image converted");
    break;
  default:
    Serial.println("Unknown error");
    return -1;
  }

  p = finger.fingerFastSearch();
  switch (p)
  { 
  case FINGERPRINT_OK:
    Serial.println("Found a print match!");
    break;
  case FINGERPRINT_NOTFOUND:
    Serial.println("Did not find a match");
    return -1;
    break;  
  default:
    Serial.println("Unknown error");
    return -1;  
    break;
  }  

  digitalWrite(A1, HIGH);
  delay(500);
  digitalWrite(A1, LOW);
  delay(2000);

  Serial.print("Found ID #");
  Serial.print(finger.fingerID); 
  Serial.print(" with accuracy value of ");
  Serial.println(finger.confidence); 
  return finger.fingerID;
}
</code></pre>
 -1: <p>Take a look at the <code>Button</code> sketch in the examples menu in the Arduino IDE. That is the simplest example of how to use a button in Arduino.</p>

<p><strong>Circuit</strong></p>

<p>This is the test circuit. When you press the button, the built LED turns on/off.  The circuit is applicable to any Arduino Uno, Mini, etc. The two wires at right are not really needed, but it doesn't hurt if you put them in the breadboard).</p>

<p>Note: What follows is an excerpt from <a href="https://www.arduino.cc/en/Tutorial/Button" rel="nofollow noreferrer">https://www.arduino.cc/en/Tutorial/Button</a>.</p>

<p><a href="https://i.stack.imgur.com/frA4Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/frA4Y.png" alt="Button example"></a></p>

<p>Connect three wires to the board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10K ohm) to ground. The other leg of the button connects to the 5 volt supply.</p>

<p>When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that we read a HIGH.</p>

<p>You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.</p>

<p>If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit. </p>

<p><strong>Code</strong></p>

<pre><code>// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
</code></pre>
