0% found this document useful (0 votes)
18 views

Program Arduino

This code is for a blood sugar monitoring system that uses a MAX30105 pulse oximeter sensor to measure blood sugar levels. It displays the results on an LCD and can print the results using a thermal printer. Buttons are used to trigger measuring the blood sugar level and printing the results. The code initializes the various hardware components, defines functions for displaying results on the LCD and printing results, and runs the main loop to check for button presses and handle readings and printing accordingly.

Uploaded by

Rahmat Official
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)
18 views

Program Arduino

This code is for a blood sugar monitoring system that uses a MAX30105 pulse oximeter sensor to measure blood sugar levels. It displays the results on an LCD and can print the results using a thermal printer. Buttons are used to trigger measuring the blood sugar level and printing the results. The code initializes the various hardware components, defines functions for displaying results on the LCD and printing results, and runs the main loop to check for button presses and handle readings and printing accordingly.

Uploaded by

Rahmat Official
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/ 5

#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() {
Serial.begin(9600);

pinMode(buttonCheckPin, INPUT_PULLUP);

pinMode(buttonPrintPin, INPUT_PULLUP);

mySerial.begin(9600);

printer.begin();

Wire.begin();

lcd.begin(16, 2);

lcd.backlight();

lcd.clear();

if (!particleSensor.begin()) {

Serial.println("MAX30105 was not found. Please check wiring/power.");

while (1);

particleSensor.setup();

lcd.setCursor(0, 0);

lcd.print("Blood Group Test");

lcd.setCursor(0, 1);

lcd.print("Press 'Check'");

delay(3000);

lcd.clear();
}

void printResult(float rate) {

printer.begin();

printer.setSize('M');

printer.justify('C');

printer.println("Blood Sugar Test");

printer.setSize('L');

printer.println("Sugar Level: " + String(rate, 0) + " mg/dL");

printer.feed(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) {

printer.println("Condition: Low");

} else if (sugarLevel == 2) {

printer.println("Condition: Normal");

} else {
printer.println("Condition: High (Possibly diabetic)");

printer.feed(3);

delay(1000); // Add a delay to separate prints

void loop() {

lcd.setCursor(0, 0);

lcd.print("Press 'Check'");

if (digitalRead(buttonCheckPin) == LOW) {

lcd.clear();

lcd.print("Checking...");

int ir = particleSensor.getIR();

float rate = ir * 0.8709;

lcd.clear();

lcd.print("Blood Sugar: ");

lcd.print(rate, 0);

lcd.print(" 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) {

lcd.clear();

lcd.print("Printing...");

delay(2000);

// Print the last result

printResult(lastRate);

printRequested = false; // Reset the print request flag

You might also like