0% found this document useful (0 votes)
6 views11 pages

MediDose Code

The document contains an Arduino sketch for a project called 'MediDose' that integrates a fingerprint sensor, a stepper motor, a servo, and an audio player using Blynk for IoT functionality. It sets up WiFi credentials, initializes hardware components, and defines functions for fingerprint scanning and motor control. The system allows users to dispense medication based on fingerprint recognition, providing audio feedback and visual prompts on an LCD display.

Uploaded by

sckadam0304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

MediDose Code

The document contains an Arduino sketch for a project called 'MediDose' that integrates a fingerprint sensor, a stepper motor, a servo, and an audio player using Blynk for IoT functionality. It sets up WiFi credentials, initializes hardware components, and defines functions for fingerprint scanning and motor control. The system allows users to dispense medication based on fingerprint recognition, providing audio feedback and visual prompts on an LCD display.

Uploaded by

sckadam0304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

//------------------------------------------------------------------------------

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud

// See the Device Info tab, or Template settings

#define BLYNK_TEMPLATE_ID "TMPL3xSOTGBBh"

#define BLYNK_TEMPLATE_NAME "MediDose"

#define BLYNK_AUTH_TOKEN "xQsqwA5vyLK9iBfhcPhe79Dqg1B05djY"

//------------------------------------------------------------------------------

#include <Arduino.h>

#include <Adafruit_Fingerprint.h>

#include <HardwareSerial.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include "Arduino.h"

#include "DFRobotDFPlayerMini.h"

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

#include <ESP32_Servo.h>

#include <AccelStepper.h>

//----------------------------------------------------------------

const int stepsPerRevolution = 200;

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "iPhone";

char pass[] = "12344321";

//----------------------------------------------------------------------------------

BlynkTimer timer;
const int dirPin = 18;

const int stepPin = 5;

// Define motor interface type

#define motorInterfaceType 1

// Creates an instance

AccelStepper stepper(motorInterfaceType, stepPin, dirPin);

// Comment this out to disable prints and save space

#define BLYNK_PRINT Serial

#define INTERVAL 1000L

//------------------------------------------------------------------------------------------

HardwareSerial serialPort(2); // use UART2

LiquidCrystal_I2C lcd(0x27, 16, 2);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&serialPort);

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port

#include <SoftwareSerial.h>

SoftwareSerial softSerial(/rx =/15, /tx =/2);

#define FPSerial softSerial

#else

#define FPSerial Serial1

#endif

DFRobotDFPlayerMini myDFPlayer;

void printDetail(uint8_t type, int value);


uint8_t getFingerprintID();

///--------------------------------------------------

#define SERVO_PIN 13// Pin connected to servo

Servo myservo;

//-----------------------------------

void setup()

// Declare pins as Outputs

stepper.setMaxSpeed(1000);

stepper.setAcceleration(500);

// Set the initial position to 0 degrees

stepper.setCurrentPosition(0);

Serial.begin(9600);

lcd.init();

lcd.backlight();

finger.begin(57600);

Blynk.begin(auth, ssid, pass);

myservo.attach(SERVO_PIN);

delay(5);

if (finger.verifyPassword()) {
lcd.setCursor(0,0);

lcd.print(" Finger Print ");

Serial.println(" Finger Print ");

lcd.setCursor(0, 1);

lcd.print("Sensor Connected");

Serial.println("Sensor Connected");

delay (3000);

} else {

lcd.setCursor(0,0);

lcd.print("Unable to found ");

Serial.println("Unable to found ");

lcd.setCursor(0,1);

lcd.print("Sensor");

Serial.println("Sensor");

delay(2000);

lcd.setCursor(0, 0);

lcd.print("Please Check ");

Serial.println("Please Check ");

lcd.setCursor(0,1);

lcd.print(" Sensor Wiring ");

Serial.println(" Sensor Wiring ");

while (1) {

delay(1);

#if (defined ESP32)

FPSerial.begin(9600, SERIAL_8N1, /*rx =*/2, /*tx =*/15);

#else
FPSerial.begin(9600);

#endif

Serial.begin(115200);

Serial.println();

Serial.println(F("DFRobot DFPlayer Mini Demo"));

Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial to


communicate with mp3.

Serial.println(F("Unable to begin:"));

Serial.println(F("1.Please recheck the connection!"));

Serial.println(F("2.Please insert the SD card!"));

while(true){

delay(0); // Code to compatible with ESP8266 watch dog.

Serial.println(F("DFPlayer Mini online."));

myDFPlayer.volume(30); //Set volume value. From 0 to 30

void loop()

lcd.setCursor(0,0);

lcd.print("Place finger...");

Serial.println("Place finger...");

lcd.setCursor(0,1);
lcd.print(" start scan ");

Serial.println(" start scan ");

getFingerprintID();

delay(50); //don't ned to run this at full speed.

Blynk.run();

timer.run();

//--BLYNK ALRAM---------

BLYNK_WRITE(V0)

int alram = param.asInt();

if(alram == 1){

getFingerprintID();

myDFPlayer.loop(3); //Play the first mp3

if(alram == 0)

myDFPlayer.pause();

/////////////////////////

uint8_t getFingerprintID() {

uint8_t p = finger.getImage();

if(p == FINGERPRINT_NOFINGER){

return p;

}
else if(p != FINGERPRINT_OK){

lcd.setCursor(0,0);

lcd.print("Scan Error ");

Serial.println("Scan Error ");

lcd.setCursor(0,1);

delay(2000);

return p;

p = finger.image2Tz();

if(p != FINGERPRINT_OK){

lcd.setCursor(0,0);

lcd.print("Processing Error");

Serial.println("Processing Error");

lcd.setCursor(0,1);

lcd.print(" Try Again ");

Serial.println(" Try Again ");

return p;

// when access aloowed --------------------------------

p = finger.fingerSearch();

if (p == FINGERPRINT_OK) {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" Take Dose");

Serial.println(" TAKE THE DOSE");

lcd.setCursor(0, 1);

lcd.print(" GET WELL SOON");

Serial.println(" Welcome");
myDFPlayer.play(4); //Play the first mp3

stepper.moveTo(25);

// Run the stepper motor until it reaches the target position

while (stepper.distanceToGo() != 0) {

stepper.run();

stepper.setCurrentPosition(0);

myservo.write(180);

delay(6000);

myservo.write(0);

delay(5000);

//---------------------------------------------------------

else if (p == FINGERPRINT_PACKETRECIEVEERR) {

lcd.setCursor(0,0);

lcd.print("Comm Error ");

Serial.println("Comm Error ");

lcd.setCursor(0,1);

lcd.print(" ");

Serial.println(" ");

delay(2000);

return p;

} else if (p == FINGERPRINT_NOTFOUND) {

lcd.setCursor(0,0);

lcd.print("Access Denied ");

Serial.println("Access Denied ");

lcd.setCursor(0,1);

lcd.print(" ");

myDFPlayer.play(2); //Play the first mp3


delay(2000);

return p;

} else {

lcd.setCursor(0,0);

lcd.print("Error in matching");

Serial.println("Error in matching");

lcd.setCursor(0,1);

lcd.print("Not Valid Finger");

Serial.println("Not Valid Finger");

myDFPlayer.play(1); //Play the first mp3

delay(2000);

return p;

return finger.fingerID;

}
Code:-

You might also like