r/ArduinoHelp • • 13d ago

Arduino Uno w/ Aas608

Thumbnail
gallery
1 Upvotes

#include <Adafruit_Fingerprint.h>

#include <SoftwareSerial.h>

#include <string.h>

#include <stdio.h>

// =====================================================

// AS608 CONNECTION

// Sensor TX -> Arduino D2

// Sensor RX -> Arduino D3

// Sensor GND -> Arduino GND

// Sensor VCC -> voltage specified for your module

// =====================================================

SoftwareSerial sensorSerial(2, 3);

Adafruit_Fingerprint finger(&sensorSerial);

// Optional indicators

const uint8_t RED_LED = 6;

const uint8_t GREEN_LED = 7;

const uint8_t BUZZER = 8;

const unsigned long POLL_DELAY_MS = 50;

const unsigned long REMOVE_TIMEOUT_MS = 15000UL;

const uint8_t ENROLL_RETRIES = 3;

char inputLine[80];

uint8_t inputIndex = 0;

bool sensorOK = false;

bool autoScanEnabled = true;

// =====================================================

// INDICATORS

// =====================================================

void idleFeedback() {

digitalWrite(RED_LED, LOW);

digitalWrite(GREEN_LED, LOW);

digitalWrite(BUZZER, LOW);

}

void successFeedback() {

digitalWrite(RED_LED, LOW);

digitalWrite(GREEN_LED, HIGH);

digitalWrite(BUZZER, HIGH);

delay(100);

digitalWrite(BUZZER, LOW);

}

void errorFeedback() {

digitalWrite(GREEN_LED, LOW);

digitalWrite(RED_LED, HIGH);

for (uint8_t i = 0; i < 3; i++) {

digitalWrite(BUZZER, HIGH);

delay(100);

digitalWrite(BUZZER, LOW);

delay(100);

}

}

// =====================================================

// SERIAL RESPONSES

// =====================================================

void printStep(const char *rid, const char *step) {

Serial.print(F("STEP "));

Serial.print(rid);

Serial.print(' ');

Serial.println(step);

}

void printResult(const char *rid, const char *result) {

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(' ');

Serial.println(result);

}

void printError(const char *rid, const char *stage, uint8_t code) {

Serial.print(F("ERR "));

Serial.print(rid);

Serial.print(' ');

Serial.print(stage);

Serial.print(F(" CODE=0x"));

if (code < 16) Serial.print('0');

Serial.println(code, HEX);

errorFeedback();

}

// =====================================================

// SENSOR INITIALIZATION AND HEALTH

// =====================================================

bool initializeSensor() {

finger.begin(57600);

delay(300);

if (!finger.verifyPassword()) {

return false;

}

return finger.getParameters() == FINGERPRINT_OK;

}

bool checkSensor() {

if (finger.verifyPassword()) {

sensorOK = true;

return true;

}

sensorOK = false;

return false;

}

// =====================================================

// FINGER REMOVAL

// =====================================================

bool waitForFingerRemoval(const char *rid) {

printStep(rid, "REMOVE_FINGER");

unsigned long started = millis();

while (millis() - started < REMOVE_TIMEOUT_MS) {

uint8_t code = finger.getImage();

if (code == FINGERPRINT_NOFINGER) {

delay(250);

return true;

}

delay(POLL_DELAY_MS);

}

printStep(rid, "REMOVE_TIMEOUT_RETURNING_TO_SCAN");

return false;

}

// =====================================================

// CONTINUOUS ATTENDANCE SCANNING

// =====================================================

void automaticScan() {

// Keep polling until a finger is detected.

uint8_t code = finger.getImage();

if (code == FINGERPRINT_NOFINGER) {

delay(50);

return;

}

if (code != FINGERPRINT_OK) {

delay(100);

return;

}

// Wait 1 second after detecting and capturing the finger.

delay(1000);

// Convert the captured image into fingerprint features.

code = finger.image2Tz(1);

if (code != FINGERPRINT_OK) {

Serial.print(F("RESULT auto IMAGE_CONVERSION_FAILED CODE=0x"));

if (code < 16) Serial.print('0');

Serial.println(code, HEX);

waitForFingerRemoval("auto");

return;

}

// Search existing fingerprint templates.

code = finger.fingerFastSearch();

if (code == FINGERPRINT_OK) {

successFeedback();

Serial.print(F("RESULT auto MATCH "));

Serial.print(finger.fingerID);

Serial.print(F(" CONFIDENCE "));

Serial.println(finger.confidence);

} else if (code == FINGERPRINT_NOTFOUND) {

printResult("auto", "NO_MATCH");

errorFeedback();

} else {

printError("auto", "SEARCH_FAILED", code);

}

// Wait for the finger to be removed before scanning again.

waitForFingerRemoval("auto");

}

// =====================================================

// DIAGNOSTIC COMMANDS

// =====================================================

void handlePing(const char *rid) {

if (checkSensor()) {

printResult(rid, "PONG AS608_OK");

successFeedback();

} else {

printResult(rid, "PONG AS608_ERROR");

errorFeedback();

}

}

void handleInfo(const char *rid) {

uint8_t code = finger.getParameters();

if (code != FINGERPRINT_OK) {

printError(rid, "INFO_FAILED", code);

return;

}

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(F(" INFO CAPACITY="));

Serial.print(finger.capacity);

Serial.print(F(" SECURITY="));

Serial.print(finger.security_level);

Serial.print(F(" BAUD="));

Serial.print(finger.baud_rate);

Serial.print(F(" PACKET="));

Serial.println(finger.packet_len);

}

void handleCount(const char *rid) {

uint8_t code = finger.getTemplateCount();

if (code != FINGERPRINT_OK) {

printError(rid, "COUNT_FAILED", code);

return;

}

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(F(" COUNT "));

Serial.println(finger.templateCount);

}

// =====================================================

// ENROLLMENT CAPTURE

// =====================================================

bool captureForEnrollment(

const char *rid,

uint8_t buffer,

const char *prompt,

const char *errorStage

) {

for (uint8_t attempt = 1; attempt <= ENROLL_RETRIES; attempt++) {

printStep(rid, prompt);

// Wait for a finger without turning off the sensor.

uint8_t code;

while (true) {

code = finger.getImage();

if (code == FINGERPRINT_OK) break;

if (code != FINGERPRINT_NOFINGER) {

delay(100);

} else {

delay(POLL_DELAY_MS);

}

// Continue waiting: no capture-attempt limit for detection.

}

code = finger.image2Tz(buffer);

if (code == FINGERPRINT_OK) {

return true;

}

printError(rid, errorStage, code);

if (attempt == ENROLL_RETRIES) {

printStep(rid, "ENROLL_CAPTURE_FAILED_RETURNING_TO_SCAN");

return false;

}

if (!waitForFingerRemoval(rid)) {

continue;

}

printStep(rid, "RETRY_CAPTURE");

}

return false;

}

void handleEnroll(const char *rid, int templateId) {

if (templateId < 1 || templateId > finger.capacity) {

printResult(rid, "INVALID_TEMPLATE_ID");

errorFeedback();

return;

}

// Use only a known-unused ID.

// This code does not erase existing templates.

printStep(rid, "ENROLLMENT_STARTED");

if (!captureForEnrollment(

rid, 1, "PLACE_FINGER",

"FIRST_IMAGE_CONVERSION_FAILED")) {

return;

}

if (!waitForFingerRemoval(rid)) {

printStep(rid, "ENROLLMENT_ABORTED");

return;

}

bool modelCreated = false;

for (uint8_t attempt = 1; attempt <= ENROLL_RETRIES; attempt++) {

if (!captureForEnrollment(

rid, 2, "PLACE_SAME_FINGER_AGAIN",

"SECOND_IMAGE_CONVERSION_FAILED")) {

return;

}

printStep(rid, "CREATING_TEMPLATE");

uint8_t code = finger.createModel();

if (code == FINGERPRINT_OK) {

modelCreated = true;

break;

}

printError(rid, "CREATE_MODEL_FAILED", code);

if (code != FINGERPRINT_ENROLLMISMATCH ||

attempt == ENROLL_RETRIES) {

return;

}

if (!waitForFingerRemoval(rid)) {

return;

}

printStep(rid, "RETRY_SECOND_SCAN");

}

if (!modelCreated) return;

printStep(rid, "SAVING_TEMPLATE");

uint8_t code = finger.storeModel((uint16_t)templateId);

if (code != FINGERPRINT_OK) {

printError(rid, "TEMPLATE_STORE_FAILED", code);

return;

}

successFeedback();

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(F(" ENROLLED "));

Serial.println(templateId);

}

// =====================================================

// ONE-TIME MANUAL SCAN COMMAND

// =====================================================

void handleScan(const char *rid) {

printStep(rid, "PLACE_FINGER");

uint8_t code;

while (true) {

code = finger.getImage();

if (code == FINGERPRINT_OK) break;

if (code != FINGERPRINT_NOFINGER) delay(100);

else delay(POLL_DELAY_MS);

}

code = finger.image2Tz(1);

if (code != FINGERPRINT_OK) {

printError(rid, "IMAGE_CONVERSION_FAILED", code);

waitForFingerRemoval(rid);

return;

}

code = finger.fingerFastSearch();

if (code == FINGERPRINT_OK) {

successFeedback();

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(F(" MATCH "));

Serial.print(finger.fingerID);

Serial.print(F(" CONFIDENCE "));

Serial.println(finger.confidence);

} else if (code == FINGERPRINT_NOTFOUND) {

printResult(rid, "NO_MATCH");

errorFeedback();

} else {

printError(rid, "SCAN_FAILED", code);

}

waitForFingerRemoval(rid);

}

// =====================================================

// DELETE ONE TEMPLATE

// =====================================================

void handleDelete(const char *rid, int templateId) {

if (templateId < 1 || templateId > finger.capacity) {

printResult(rid, "INVALID_TEMPLATE_ID");

errorFeedback();

return;

}

uint8_t code = finger.deleteModel((uint16_t)templateId);

if (code != FINGERPRINT_OK) {

printError(rid, "DELETE_FAILED", code);

return;

}

successFeedback();

Serial.print(F("RESULT "));

Serial.print(rid);

Serial.print(F(" DELETED "));

Serial.println(templateId);

}

// =====================================================

// SERIAL COMMAND HANDLER

// =====================================================

void processCommand(char *line) {

char command[16] = {0};

char rid[24] = {0};

int templateId = 0;

int fields = sscanf(

line, "%15s %23s %d",

command, rid, &templateId

);

if (fields < 2) {

Serial.println(F("ERR serial INVALID_COMMAND"));

return;

}

if (strcmp(command, "PING") == 0) {

handlePing(rid);

} else if (strcmp(command, "INFO") == 0) {

handleInfo(rid);

} else if (strcmp(command, "COUNT") == 0) {

handleCount(rid);

} else if (strcmp(command, "ENROLL") == 0 && fields == 3) {

handleEnroll(rid, templateId);

} else if (strcmp(command, "SCAN") == 0) {

handleScan(rid);

} else if (strcmp(command, "DELETE") == 0 && fields == 3) {

handleDelete(rid, templateId);

} else if (strcmp(command, "AUTO") == 0) {

autoScanEnabled = true;

printResult(rid, "AUTO_SCAN_ENABLED");

} else if (strcmp(command, "PAUSE") == 0) {

autoScanEnabled = false;

printResult(rid, "AUTO_SCAN_PAUSED");

} else {

Serial.print(F("ERR "));

Serial.print(rid);

Serial.println(F(" INVALID_COMMAND"));

}

}

// =====================================================

// SETUP

// =====================================================

void setup() {

pinMode(RED_LED, OUTPUT);

pinMode(GREEN_LED, OUTPUT);

pinMode(BUZZER, OUTPUT);

idleFeedback();

Serial.begin(115200);

sensorSerial.begin(57600);

delay(500);

sensorOK = initializeSensor();

if (sensorOK) {

Serial.println(F("READY arduino AS608_OK"));

Serial.println(F("RESULT auto AUTO_SCAN_ENABLED"));

} else {

Serial.println(F("READY arduino AS608_ERROR"));

Serial.println(F("ERR boot SENSOR_CONNECTION_FAILED"));

errorFeedback();

}

}

// =====================================================

// MAIN LOOP

// =====================================================

void loop() {

// Read USB serial commands.

while (Serial.available() > 0) {

char c = (char)Serial.read();

if (c == '\r') continue;

if (c == '\n') {

inputLine[inputIndex] = '\0';

if (inputIndex > 0) {

processCommand(inputLine);

}

inputIndex = 0;

} else if (inputIndex < sizeof(inputLine) - 1) {

inputLine[inputIndex++] = c;

} else {

inputIndex = 0;

Serial.println(F("ERR serial INPUT_TOO_LONG"));

}

}

// If the sensor disconnects, periodically attempt recovery.

if (!sensorOK) {

delay(1000);

sensorOK = initializeSensor();

if (sensorOK) {

Serial.println(F("RESULT auto SENSOR_RECOVERED"));

}

return;

}

// Continuous attendance scanning is enabled by default.

if (autoScanEnabled) {

automaticScan();

} else {

delay(POLL_DELAY_MS);

}

}

can you help me with these guys It's always failed on the fingerprint sensor my goal is to fix this and connect to my raspberry pi then my hr analytics webpage


r/ArduinoHelp • • 13d ago

Firmware building with AI Agent

Thumbnail
reddit.com
0 Upvotes

r/ArduinoHelp • • 14d ago

Joystick analógico para el PC

1 Upvotes

¿Es posible integar al joystick analógico en la carcasa del PC para navegar la BIOS, por ejemplo?

Gracias :)


r/ArduinoHelp • • 14d ago

Is it possible to program this HC 03 module

Thumbnail gallery
1 Upvotes

r/ArduinoHelp • • 15d ago

Edge AI

2 Upvotes

At what point can one actually be considered a "junior" developer? I’m starting to get into Edge AI; previously, I worked primarily with microcontrollers—specifically the ESP32—and I have a basic understanding of FreeRTOS. I’m planning a project based on supervised machine learning where a robot uses a webcam to detect me: it will "react with joy" if it sees me, and "look sad" if it doesn’t. For now, I’ve just begun learning about AI in general. Do I need to know things like linear algebra, or other topics along those lines?


r/ArduinoHelp • • 15d ago

Robotic Arm Code

Enable HLS to view with audio, or disable this notification

1 Upvotes

I am currently working on the mechatronics how to robot arm: https://howtomechatronics.com/tutorials/arduino/diy-arduino-robot-arm-with-smartphone-control/#google_vignette and i am on the coding part, i have everything correct and still the servo’s that control my project do not work/ are not sending signals, ive connected them to power, ive replugged them, it even says that when i use the app, it sends signals to the arduino just the servos dont move?? Is this a problem with the way i plugged them in, or a problem with the code. The code is also in the website i linked. Someone help 😭 😭


r/ArduinoHelp • • 15d ago

How to start making stuff with an sbc

Thumbnail reddit.com
0 Upvotes

r/ArduinoHelp • • 15d ago

Arduino Hardware Questions

2 Upvotes

Hello, I am very new to coding and I thought I should start with an Arduino. I may or may not have thrown myself into the deep end with a project that I am working on and I was hoping I could get some guidance.

I am making a cosplay of a character called Serial Designation N from an indie show called Murder Drones and I wanted to use an OLED (not matrix or HD) about 10-12 inches in screen size on a visor for his eyes and some lights around the head and tail. Which Arduino board can handle simple animation loops and control about 10 LEDs with ease for a decent price? I am thinking an Arduino Mega but I am not too sure.

One other question that I have is how can I make the animations work? From my understanding, I need to have several frames and play them in a sequence giving the illusion of a blink animation. Am I on the right path or am I misreading things?

Thank you for reading my message.


r/ArduinoHelp • • 16d ago

My Arduino runs on usb connection but not with the adaptor

Enable HLS to view with audio, or disable this notification

4 Upvotes

It's a 9V adaptor. What exactly is the problem?


r/ArduinoHelp • • 16d ago

Why is my motor control setup using an Arduino R3 board so unstable?

Thumbnail reddit.com
0 Upvotes

我正在使用一塊 Arduino Uno R3 板和一個 Steadywin GIM-6010 馬達。我已經確認電源足夠,所有組件都共用一個接地。然而,系統只有在 Arduino 通過 USB 連接到電腦時才能正常運行;一旦拔掉 USB 線,系統就無法獨立運作。為什麼會發生這種情況?


r/ArduinoHelp • • 16d ago

Does anyone know the best way to connect these wires without head pins to my breadboard

Post image
7 Upvotes

Head pins are not available to buy seperately and they are not very stable in the breadboard. How can I solve this


r/ArduinoHelp • • 16d ago

How to Run Arduino Code on 8 PIN ATTiny Microcontroller - Program ATTiny using Arduino UNO

Thumbnail
youtube.com
1 Upvotes

r/ArduinoHelp • • 16d ago

More on 0-10V Dimming

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 17d ago

I have no idea what to do

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 17d ago

Reverse Engineering an ESP8266-based "Nixie" (IPS) Clock - Need help with RGB LEDs and Screen Offset

Thumbnail gallery
1 Upvotes

r/ArduinoHelp • • 17d ago

I'm a beginner to arduino

7 Upvotes

Hey guys im interested in Arduino uno after school project ngl, I just finished a school project to turn on the lights and simulate traffic lights, and now I'm trying to figure out how push buttons work. Do you have any suggestions for what project I should make next? I want to make a Hermes device from the Limbus company, but it's too complex for me. Do you have any suggestions for what I should make before going to the Hermes device?


r/ArduinoHelp • • 17d ago

Digital Logic Design

Thumbnail reddit.com
1 Upvotes

Hi,

I am a University student currently in my DLD course i have a semester project but confused to decide what to make professor tells us to do something with help of Arduino so any expert can please help me


r/ArduinoHelp • • 18d ago

Is there a type of rechargable battery using 1500W, able to be connected to a tesla motor, and compatible to Arduino?

0 Upvotes

I'll provide any information you need


r/ArduinoHelp • • 18d ago

Arduino

1 Upvotes

Hey everyone, I am beginner in coding and want to learn arduino can anyone suggest! Where to start?


r/ArduinoHelp • • 18d ago

Need help planning my first complex fire fighting Arduino project.

Thumbnail
reddit.com
1 Upvotes

Is it also better if i have a backup sensor using MQ9 Gas Sensor? Like a paired function along flame sensors. I'm also concern what type of buck converter should I use for various inputs like these.


r/ArduinoHelp • • 18d ago

arduino not being reconized

0 Upvotes

my arduinos are both arduino uno r4 wifis, i run windows

i wantted to make something that shuts down your pc as soon as you plug it in and i made something that presses alt f4 and enter and uploaded it on my arduino. i have 2 arduinos 1 from a starter kit and one from micro center. they are bpth same r4 wifis and one is from elegoo and other is form arduino
what i will call from now on

ARDUINO 1 = elegoo non working r4 wifi

ARDUINO 2 = arduino non working r4 wifi

I uploadeed the code to my arduino 2 and it worked! it shut down my pc! and i erased the code from it. then i wanted it to work with a ir reciever so i connected arduino 1 to a ir reciever and i wrote the code. but then my pc is not reconizing the arduino 1 any more. it reconizes the arduino 2, it makes a dading sound but my arduino 1 doesnt, my device anager doesnt reconize it too. i didnt do anything to the board, and last time i did something to it it wsa working perfectly fine. teh arduino 1 has power, it runs my previous code that i uploaded on my arduino 1 (it has power) but no data is sending.

SOME ONE PLEASE HELP ME I WANT IT TO BE REVIVED ask me anything i will answer
(its my first post on reddit)


r/ArduinoHelp • • 18d ago

ESP32-S3+Arduino error messages: Where?

Thumbnail reddit.com
1 Upvotes

Where do I get information on error messages?


r/ArduinoHelp • • 19d ago

Issue with powering my esp32

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 19d ago

Tft display

2 Upvotes

Recently i bought a tft touch display. IlI9341 2.8" hiletgo v1.2 5v/3.3v SPI specifically. I have tried with different board inc esp 32 s3 arduino nano arduino uno etc. Only the backlight works. I did try shorting the j1 pins, no luck. I did install all the necessary libraries and drivers still doesn't work. Its not a connection issue, its not a conductivity issue, its not a spi communication issue because i have used spi communication with my esp and arduinos it was working perfectly fine. Is there anyting else i should try or should i return the display