└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-coding-for-sugar-level-measurement 2 | To measure sugar level using Ardiuno 3 | // Include necessary libraries 4 | #include 5 | 6 | // Define input pins 7 | int irSensorPin = A0; 8 | 9 | // Define output pins 10 | int glucoseIndicatorPin = 9; 11 | 12 | // Initialize fuzzy logic objects 13 | Fuzzy irSensorFuzzy; 14 | 15 | void setup() { 16 | // Initialize serial communication 17 | Serial.begin(9600); 18 | 19 | // Initialize input and output pins 20 | pinMode(irSensorPin, INPUT); 21 | pinMode(glucoseIndicatorPin, OUTPUT); 22 | 23 | // Initialize fuzzy sets and membership functions for IR sensor readings 24 | irSensorFuzzy.addFuzzySet("Low", 0, 200, 400); 25 | irSensorFuzzy.addFuzzySet("Medium", 400, 800, 1200); 26 | irSensorFuzzy.addFuzzySet("High", 1200, 1600, 2000); 27 | 28 | // Define fuzzy rules 29 | irSensorFuzzy.addFuzzyRule("IF IR is Low THEN Glucose is Low"); 30 | irSensorFuzzy.addFuzzyRule("IF IR is Medium THEN Glucose is Medium"); 31 | irSensorFuzzy.addFuzzyRule("IF IR is High THEN Glucose is High"); 32 | } 33 | 34 | void loop() { 35 | // Read IR sensor value 36 | int irSensorValue = analogRead(irSensorPin); 37 | 38 | // Perform fuzzy inference for IR sensor reading 39 | float glucoseLevel = irSensorFuzzy.fuzzify("IR", irSensorValue); 40 | 41 | // Output glucose level (for testing purposes) 42 | Serial.print("Glucose Level: "); 43 | Serial.println(glucoseLevel); 44 | 45 | // Adjust glucose indicator LED brightness based on glucose level 46 | int glucoseIndicatorBrightness = map(glucoseLevel, 0, 1, 0, 255); 47 | analogWrite(glucoseIndicatorPin, glucoseIndicatorBrightness); 48 | 49 | // Add delay to loop 50 | delay(1000); 51 | } 52 | --------------------------------------------------------------------------------