#include <Wire.
h>
#include <LiquidCrystal_I2C.h>
#include "MAX30105.h"
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 11 // Arduino transmit (YELLOW WIRE) labeled RX on printer
#define RX_PIN 10 // Arduino receive (GREEN WIRE) labeled TX on printer
#define BUTTON_CHECK_PIN 4 // Pin for blood sugar check button
#define BUTTON_PRINT_PIN 5 // Pin for printing button
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial object
Adafruit_Thermal printer(&mySerial); // Pass address to printer constructor
MAX30105 particleSensor;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buttonCheckPin = BUTTON_CHECK_PIN;
const int buttonPrintPin = BUTTON_PRINT_PIN;
float lastRate = 0; // Variable to store the last measured blood sugar level
bool printRequested = false; // Flag to indicate print request
void setup() {
[Link](9600);
pinMode(buttonCheckPin, INPUT_PULLUP);
pinMode(buttonPrintPin, INPUT_PULLUP);
[Link](9600);
[Link]();
[Link]();
[Link](16, 2);
[Link]();
[Link]();
if (![Link]()) {
[Link]("MAX30105 was not found. Please check wiring/power.");
while (1);
[Link]();
[Link](0, 0);
[Link]("Blood Group Test");
[Link](0, 1);
[Link]("Press 'Check'");
delay(3000);
[Link]();
}
void printResult(float rate) {
[Link]();
[Link]('M');
[Link]('C');
[Link]("Blood Sugar Test");
[Link]('L');
[Link]("Sugar Level: " + String(rate, 0) + " mg/dL");
[Link](1);
int sugarLevel;
if (rate >= 75 && rate <= 100) {
sugarLevel = 1; // Low sugar level
} else if (rate > 100 && rate <= 200) {
sugarLevel = 2; // Normal sugar level
} else {
sugarLevel = 3; // High sugar level (Possibly diabetic)
if (sugarLevel == 1) {
[Link]("Condition: Low");
} else if (sugarLevel == 2) {
[Link]("Condition: Normal");
} else {
[Link]("Condition: High (Possibly diabetic)");
[Link](3);
delay(1000); // Add a delay to separate prints
void loop() {
[Link](0, 0);
[Link]("Press 'Check'");
if (digitalRead(buttonCheckPin) == LOW) {
[Link]();
[Link]("Checking...");
int ir = [Link]();
float rate = ir * 0.8709;
[Link]();
[Link]("Blood Sugar: ");
[Link](rate, 0);
[Link](" mg/dL");
lastRate = rate; // Store the latest blood sugar level
printRequested = true; // Set the flag to indicate print requested
delay(2000);
if (printRequested && digitalRead(buttonPrintPin) == LOW) {
[Link]();
[Link]("Printing...");
delay(2000);
// Print the last result
printResult(lastRate);
printRequested = false; // Reset the print request flag