SUGAR ARDUINO CODE

 #include <LiquidCrystal.h>




LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD display pins: rs, enable, d4, d5, d6, d7



const int analogPin = A0;

const float A = 8e-5;

const float B = 0.1873;

const float C = 46.131;



const int numReadings = 10;

int readings[numReadings];

int readIndex = 0;

long total = 0;



void setup() {

  lcd.begin(16, 2);

  Serial.begin(9600);

  pinMode(analogPin, INPUT);

  for (int i = 0; i < numReadings; i++) {

    readings[i] = 0;

  }

}



void loop() {

  int rawValue = analogRead(analogPin);

  total -= readings[readIndex];

  readings[readIndex] = rawValue;

  total += rawValue;

  readIndex = (readIndex + 1) % numReadings;

  float averageVoltage = (float)total / numReadings * 5.0;



  float glucoseConcentration = A * pow(averageVoltage, 2) + B * averageVoltage + C;



  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print("Glucose:");

  lcd.setCursor(0, 1);

  lcd.print(glucoseConcentration, 1);

  lcd.print(" mg/dl");

  Serial.print("Glucose: ");

  Serial.print(glucoseConcentration, 1);

  Serial.println(" mg/dl");



  delay(1000);

}

Comments

Popular posts from this blog

BASICS OF ARDUINO UNO - LED BLINKING

ARDUINO UNO CODE TO DISPLAY HELLO WORLD !

ESP 32