This shows you the differences between two versions of the page.
pm:prj2025:eradu:iulian_adrian.andrei [2025/05/26 00:24] iulian.andrei2608 |
pm:prj2025:eradu:iulian_adrian.andrei [2025/05/26 18:15] (current) iulian.andrei2608 |
||
---|---|---|---|
Line 98: | Line 98: | ||
===== Software Design ===== | ===== Software Design ===== | ||
+ | === Development Environment === | ||
- | <note tip> | + | The firmware was developed using the **Arduino IDE**, targeting the **ATmega328P** microcontroller on the Arduino Uno platform. Code is written in **C/C++** using only core Arduino libraries: |
- | Descrierea codului aplicaţiei (firmware): | + | * '''Wire.h''' – for I2C communication, |
- | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | * '''LiquidCrystal_I2C.h''' – for interfacing with the LCD display. |
- | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | |
- | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
- | * (etapa 3) surse şi funcţii implementate | + | |
- | </note> | + | |
- | === Firmware Description === | + | No third-party libraries beyond the standard Arduino ecosystem were required. |
- | The firmware was developed using the **Arduino IDE**, chosen for its compatibility with the ATmega328P-based Arduino Uno and ease of integration with external components. | + | === Algorithm and Logic === |
- | The code is written in C++ (Arduino-style) and follows a modular structure to separate functionalities such as signal reading, processing, display, and control outputs. | + | The application firmware performs the following main steps: |
- | === Libraries Used === | + | - **System Initialization** |
+ | * Sets pin modes for analog input, LEDs, LCD, and the interrupt pin for the button. | ||
+ | * Initializes the I2C communication and LCD display. | ||
- | * `Wire.h` – used for I2C communication with the LCD module. | + | - **Measurement Trigger** |
- | * `LiquidCrystal_I2C.h` – handles text output on the 1602 I2C LCD. | + | * A measurement is initiated by pressing a push button connected to digital pin `D2`. |
- | * `EEPROM.h` – allows persistent storage of calibration parameters between resets. | + | * This pin is configured to trigger an **external interrupt**. |
+ | * The interrupt sets a flag that is handled in the `loop()` function. | ||
- | No third-party libraries beyond standard Arduino ones were used. The code manually handles analog reading, PWM generation, and control logic. | + | - **Analog Signal Acquisition** |
+ | * The analog signal (a voltage) from the output of the OP07 amplifier is read using `analogRead()` on pin `A2`. | ||
+ | * The ADC returns a value between 0 and 1023, corresponding to a voltage between 0 and 5V. | ||
+ | * This voltage is proportional to the current generated by the simulated test strip (using potentiometer). | ||
- | === Implemented Algorithms and Structures === | + | - **Current and Glucose Calculation** |
+ | * The current in microamperes is calculated using Ohm’s law: //I = Vout / Rf// | ||
+ | * The glucose level (mg/dL) is then estimated using a fixed proportionality factor derived during calibration: //Glucose = (Current_in_uA) * Sensitivity_Coefficient// | ||
+ | * The sensitivity coefficient was selected manually during testing using reference glucose values. | ||
- | The main structure of the firmware is built around: | + | - **Classification and Output** |
- | + | * Based on calculated glucose value, the result is categorized into: | |
- | * **Setup phase** – initializes peripherals: ADC, I2C, LCD, LEDs, interrupts. | + | - Hypoglycemia, |
- | * **Loop function** – continuously checks for input triggers (e.g., button press) and performs: | + | - Normal, |
- | - Reading analog input on pin `A0`. | + | - Hyperglycemia. |
- | - Mapping the ADC value to glucose level using a calibrated linear equation. | + | * A corresponding LED is lit using PWM pins (D3, D5, D6, D9, D10, D13) for visual alert. |
- | - Classifying glucose levels (hypoglycemia, normal, hyperglycemia). | + | * The result is also displayed on the I2C LCD, showing both the glucose level and category. |
- | - Driving LEDs on PWM pins (`D5`, `D6`, `D10`, `D11`) to indicate levels. | + | |
- | - Displaying results on the LCD. | + | |
- | - Optionally saving calibration values to EEPROM. | + | |
- | + | ||
- | An external interrupt on `D2` allows triggering a new measurement cycle via a push button, without blocking the main loop. | + | |
=== Current Implementation Status === | === Current Implementation Status === | ||
- | * Analog signal reading via ADC (`A0`) – fully functional. | + | * Analog signal reading via ADC (A2) – fully functional. |
* Glucose calculation and classification – implemented and verified. | * Glucose calculation and classification – implemented and verified. | ||
- | * PWM output on LEDs (pins `D5`, `D6`, `D10`, `D11`) – working. | + | * PWM output on LEDs (pins D3, D5, D6, D9, D10, D13). |
* LCD display via I2C – correctly displays readings and thresholds. | * LCD display via I2C – correctly displays readings and thresholds. | ||
- | * External interrupt on `D2` – used for manual measurement triggering. | + | * External interrupt on D2 – used for manual measurement triggering. |
- | * EEPROM read/write – implemented for calibration persistence. | + | |
- | No UART logging or Timer-based routines were implemented in the current version. | ||
- | === Library Choice Justification === | + | === Implemented functions === |
- | We selected minimal standard libraries to retain low memory usage and ensure high compatibility with the ATmega328P. `LiquidCrystal_I2C` simplifies LCD communication, while `EEPROM.h` enables storing calibration data without relying on external storage modules. | + | * **handleButtonInterrupt()** – Interrupt service routine (ISR) called when the user presses the button. It toggles the state of the glucometer (//glucometerON//) and sets a flag (//buttonPressed//) for state management. |
- | === Novelty and Educational Value === | + | * **turnOffAllLEDs()** – Sets PWM output of all six LEDs to zero using //analogWrite//. This ensures a clean reset when the system is turned off or reinitialized. |
- | The project simulates a glucose meter using accessible components. A **potentiometer** is used to simulate the variable current output of an electrochemical test strip, allowing analog simulation of different glucose levels. This makes the project highly didactic and safe for experimentation. | + | * **adjustRedPWM(diff)** – Called when hyperglycemia is detected. It calculates the intensity of red LEDs proportionally to how far the glucose level exceeds 150 mg/dL. |
- | === Use of Laboratory Techniques === | + | * **adjustYellowPWM(diff)** – Called in hypoglycemia cases. It increases the brightness of yellow LEDs proportionally to how far below 100 mg/dL the glucose level is. |
- | * **ADC** (A0): reads the voltage from the OP07 output. | + | * **adjustGreenPWM(glucose)** – Called when glucose levels are within normal range. It calculates a ratio within the 100–150 mg/dL band to smoothly vary the intensity between the two green LEDs. |
- | * **PWM outputs** (D5, D6, D10, D11): control LED brightness based on glucose severity. | + | |
- | * **I2C communication** (A4, A5): used for the LCD. | + | |
- | * **External interrupt** (D2): triggers a reading without blocking the main loop. | + | |
- | * **EEPROM usage**: stores and retrieves calibration data. | + | |
- | + | ||
- | These features reflect the concepts covered in embedded systems lab sessions. | + | |
- | === Software Architecture === | + | ===== Results Obtained ===== |
- | * **Potentiometer** simulates sensor behavior by varying voltage into the op-amp. | + | During the operation of the project, the current value generated by the potentiometer, which simulates the current from an electrochemical test strip, is read through the Arduino’s analog input pin. Based on this current, the code calculates the estimated glucose concentration and displays it on the 1602 LCD screen. |
- | * **OP07** outputs a voltage proportional to this signal. | + | |
- | * **Arduino Uno** reads this voltage through `A0` using the ADC. | + | |
- | * The value is converted to glucose concentration (mg/dL) using a calibrated linear mapping. | + | |
- | * Glucose level is categorized: | + | |
- | - Below threshold → hypoglycemia. | + | |
- | - Within range → normal. | + | |
- | - Above range → hyperglycemia. | + | |
- | * PWM-driven LEDs light up accordingly. | + | |
- | * LCD displays current glucose value and category. | + | |
- | * Push button on `D2` allows manual triggering of a reading using interrupts. | + | |
- | * EEPROM retains calibration between power cycles. | + | |
- | Each feature was implemented and tested individually before integration, ensuring correctness. | + | According to the calculated glucose level, RGB LEDs are controlled via PWM signals to indicate different glycemic states: |
+ | * For values below 100 mg/dL, yellow LEDs light up, indicating hypoglycemia. | ||
+ | * For values between 100 and 150 mg/dL, green LEDs are active, indicating a normal level. | ||
+ | * For values above 150 mg/dL, red LEDs turn on, signaling hyperglycemia. | ||
- | === Sensor Calibration === | + | These results were validated through manual testing by adjusting the potentiometer and observing the corresponding changes on the display and LED intensity, confirming the correct operation of the system in simulating glucose measurement. |
- | Calibration was done manually using known positions of the potentiometer to simulate known glucose levels. For each setting: | + | The system responds quickly to changes in current and provides a clear user interface through the LCD display and visual LED indicators. |
- | 1. The ADC value was recorded. | ||
- | 2. A glucose value (in mg/dL) was associated with it. | ||
- | 3. A linear mapping formula was derived: | ||
+ | ===== Conclusion ===== | ||
- | ===== Rezultate Obţinute ===== | + | This project successfully demonstrates a basic but functional glucometer built with Arduino. By simulating the sensor signal with a potentiometer and using an operational amplifier, we were able to measure small currents and convert them into glucose levels. The system provides clear feedback through an LCD display and colored LEDs, offering both visual and numerical information to the user. |
- | + | ||
- | <note tip> | + | |
- | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | + | |
- | </note> | + | |
- | + | ||
- | ===== Concluzii ===== | + | |
===== Download ===== | ===== Download ===== | ||
- | <note warning> | + | Source code: |
- | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | |
+ | https://github.com/AdrianIulian26/GlucoMeter | ||
- | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | ||
- | </note> | ||
===== Jurnal ===== | ===== Jurnal ===== | ||
Line 218: | Line 194: | ||
===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||
- | <note> | + | ==== Hardware ==== |
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | |
- | </note> | + | * OP07 Operational Amplifier Datasheet |
+ | [https://www.ti.com/lit/ds/symlink/op07.pdf TI OP07 Datasheet] | ||
+ | |||
+ | * How Electrochemical Glucose Sensors Work | ||
+ | [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6790891/ PMC Article on Electrochemical Glucose Biosensors] | ||
+ | |||
+ | * Principles of Glucose Meter Operation (Explanation) | ||
+ | [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3904486/ NIH PMC Article on Glucose Meter Principles] | ||
+ | |||
+ | ==== Software ==== | ||
+ | * PWM Control with Arduino (Explanation and Examples) | ||
+ | [https://www.arduino.cc/en/Tutorial/PWM Arduino PWM Tutorial] | ||
+ | |||
+ | * Arduino Serial Communication Basics | ||
+ | [https://www.arduino.cc/en/Serial/Begin Arduino Serial] | ||
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||