Struggling with R307 Fingerprint Sensor Not Detected Problem

I'm currently working on an Arduino project using the R307 fingerprint sensor. However, when I run the code, I keep getting the error message: "Fingerprint Sensor Not Detected :(". I've double-checked the wiring and connections, but everything seems fine. I am using a clone arduino uno(CH340).

I have followed what seems like every suggestion on the internet, however it still does not work. The sensor only blinks blue for half a second once when it's connected to power and doesn't do anything else after that.

The code is the 'enroll' example from Adafruit fingerprint sensor library.

The fingerprint sensor.

Code:

/***************************************************
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit BMP085 Breakout
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  Small bug-fix by Michael cochez

  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_Fingerprint.h>


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x"));
  Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x"));
  Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: "));
  Serial.println(finger.capacity);
  Serial.print(F("Security level: "));
  Serial.println(finger.security_level);
  Serial.print(F("Device address: "));
  Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: "));
  Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: "));
  Serial.println(finger.baud_rate);
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (!Serial.available())
      ;
    num = Serial.parseInt();
  }
  return num;
}

void loop()  // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {  // ID #0 not allowed, try again!
    return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!getFingerprintEnroll())
    ;
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #");
  Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        break;
      case FINGERPRINT_NOFINGER:
        Serial.print(".");
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID ");
  Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        break;
      case FINGERPRINT_NOFINGER:
        Serial.print(".");
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");
  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID ");
  Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  return true;
}

The connections are:
Arduino 5V --> red wire
GND ----> Black Wire
pin2 --->Green
pin3 ----->White

The exact error is :
'Did not find fingerprint sensor :('

Any help will be appreciated.
Thanks!

This sounds very strange. Have you altered this at all?

BMP085 is a temperature/barometer sensor, not a fingerprint scanner...

Neither a fingerprint scanner or a temp/Barometer sensor is a display...

No, I have not altered anything: this is the code as it is in the given in the example. I have checked the code with other sources and confirmed that it is present in all other peoples codes.

Note: I have researched for hours on this issue and it seems like this is a common problem. However, none of the solutions work for me.

So maybe my fingerprint sensor is broken?

Note #2: In the code in this part :

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

I printed for the value of the function 'finger.verifyPassword();'. It returns 0 as the output. So whatever the problem is it seems to be occurring due to this function in the built in library. It seems that the sensor has a preset password that it is communicating with. I tried bypassing the function, however after a few lines it shows the following error :

Adafruit Fingerprint sensor enrollment
Did not find fingerprint sensor : (
Ready to enroll a fingerprint!
Please type in the ID # (from 1 to 127) you want to save this finger as...
Enrolling ID #1
Waiting for valid finger to enroll as #1
Communication error
Communication error
Communication error

Note #3: After running the sensor for while, the back of the fingerprint reader heats up. Does this mean that the sensor is broken or that voltage regulator is getting hot?

I FOUND THE SOLUTION!!!

Okay, I learned to not just believe the datasheet blindly.

The wire colors are all jumbled up. Its really weird.

You have to put the connections like this:
POWER: RED(1st pin);
GROUND: Black(2nd pin)
Now, no matter what color, put the third pin in PIN 2, ie. IN pin.
The fourth pin goes to PIN 3, OUT pin.

I hope this saves someone's time in the future.
Thanks!

When you say "IN pin" and "OUT pin", are those markings on the fingerprint scanner?

Or, by "IN" and "OUT" are you referring to the Arduino pins, because your code has

which would make pin 2 the Rx (receive/input) pin and pin 3 the Tx (transmit/output)?

Good work figuring your problem out.

No, I was referring to the pins as per given in the code's comments.

Yes, 2 is Rx and 3 is Tx. I didn't want to use these words as I thought it referred to Hardware serial, opposed to UNO's software serial which I was using.

Thanks for reading!

Are you sure it can accept 5V?

Maybe try powering it with 3.3V. Note: not all Arduino models can provide sufficient power at 3.3V. The classic Nano V3 cannot, for example.

Both Hardware and Software serial has its own RX and TX.
To be warned that you must swap RX and TX when connect it to another UART device.
Isn't your "solution" exact this way - you forget to swap RX and TX when connect the sensor?

That is what most people would assume. But if you mention SoftwareSerial, that will make it clear.

BTW, are you using Uno? That's what people will assume if you simply say "Arduino". But some other models have additional hardware serial ports, and you should always use those in preference to using SoftwareSerial, if they are available.

The datasheet seems to be correct, sensor pin 2 is TX, which should be connected to the RX of the Arduino, accordingly the RX of the sensor is connected to the TX of the Arduino

Yes, I am using an Arduino Uno. It is mentioned in the topic.

The data sheet mentions to use the green and white wires, however in my case, I had to use the yellow and green wires. That’s the reason I said not to trust the darshate blindly.

The datasheet contains a module schematic and table of pins with clear labels - TXD and RXD. You don't need any information about the colors of the wires, which can be varied from one module to another.

This is the conclusion you should make - use the important information in the datasheet and don't pay attention to the little things.

By the way, there is no reference to the wire's colors in the connection part of the datasheet at all:

Where did you get the instructions for using the white and green wire?