Health Monitoring and Tracking System Using GSM/GPS

 Objective

The objective of this project is to provide an effective application for a Real-Time Health Monitoring and Tracking System. The system monitors the patient’s oxygen saturation content (SpO2) and sends a short message (SMS) to a mobile number with the following information:

  • SpO2 Measurement
  • Current GPS location of the patient

 Materials

Hardware Tools

Tool About Purchase
ICD3-50px.png
MPLAB® ICD 3
In-Circuit Debugger

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
swtool-28px.png
MPLAB® Code Configurator
Dynamic Code Generation
MPLAB® XC8
C Compiler

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Project and Source Files

 Connection Diagram

The Health Monitoring and Tracking System uses a PIC16F19175. The PIC16F19175 communicates with an SpO2/heart rate module through I²C.

The PIC16F19175 also communicates with the GSM-GPS module through a USART interface to read the patient’s current location. The PIC16F19175 then sends the measured SpO2 and location as an SMS to a phone number through GSM.

MonitoringBlockDiagram.png

Jumper Configuration

JumperConfiguration.png

Make sure the following jumpers are present on the Explorer 8 development board to ensure proper functionality:

  1. No need for any jumpers on components 1-3 in the image above.
  2. In component 4, configure the jumpers such that:
    • J56: RB7 must be connected to the center pin to configure it as the microcontroller UART2 TX pin to the MCP2221 RX pin.
  3. No need for any jumpers on components 5-7 in the image above.
  4. In component 8, configure the jumpers as follows:
    • J27: RB5 must be connected to the center pin to configure it as the microcontroller UART2 RX pin to the GSM-GPS module TX pin
    • J44: RC6 must be connected to the center pin to configure it as the microcontroller UART1 TX pin to the GSM-GPS module RX pin
  5. No need for any jumpers on components 9-14 in the image above.
  6. In component 15, configure the jumpers such that:
    • J30, J14: The board is supplied with 3.3 V.
  7. In component 16, configure the jumpers such that:
    • J2: The board is supplied with 5 V power via the USB.
  8. In component 17, configure the jumpers such that:
    • J51, J52: RB7 is connected to the center pin at J51 and RB6 is connected with the center pin at J52 to connect the PGD and PGC pins of the ICD to the PIC® MCU ICSPDAT and ICSPCLK, respectively for ICSP™.
  9. No need for any jumpers on component 18 in the image above.
  10. In component 19, configure the jumpers such that:
    • J24: The two pins are connected to each other to supply a regulated 3.3 V output to the mikroBUS™.
  11. Hook the GSM-GPS module on J32 and the Heart Rate/SpO2 click on J35.
Setup.jpg

 Procedure

The major steps to implement this project are as follows:

  • Set up Project Recourses
  • Set up the Heart Rate/SpO2 Modules
  • Set up the EUSART
  • Configure the Pin Manager
  • Generate Code
  • Add Functionality
  • Program the Device

1

Create New Project

Create a new 'Standalone' project in MPLAB® X IDE for a PIC16F18875. If this is your first time using MPLAB X IDE, follow the instructions in the article, "Create a Standalone Project".

2

Launch MPLAB Code Configurator

Open the MPLAB® Code Configurator (MCC) under the Tools > Embedded menu of MPLAB X IDE as shown in the following image.

OpenMCC.png

3

Set Up Project Resources

Click on 'System Module' in the 'Project Resources' tab.

SystemModule.png

The System section will appear.
To set the Oscillator configurations, follow these steps:

  1. Select 'EXTOSC' from the Oscillator Select drop-down menu.
  2. Select 'EC for 500 kHz to 8 MHz: PFM set to medium power' from the External Clock Select drop-down menu.
  3. Enter 4 MHz for External Clock.
  4. Select '4' from the Clock Divider drop-down menu.
  5. Check the 'Low-voltage Programming Enable' box to turn it on.

This will set the system clock at 1 MHz using the external oscillator.

InternalOscillator.png

4

Registers

The MPLAB Code Configurator generates default settings for the registers as shown below:

Register1.png
Register2.png
Register3.png
Register4.png
Register5.png

Make sure the register OSCTUNE is set to 0x00 as shown below.

OSCTUNE.png

5

Set Up Heart Rate/SpO2 click

The Heart Rate/SpO2 click needs to be set up. The heart rate module is shown in the MCC under 'Device Resources'. Choose 'Sensors' and then 'Heartrate' from the drop-down menu as shown below:

HeartRate.png

MikroElektronika's Heart Rate click sensor and its corresponding libraries are now added to the Project Resources. Select 'Heartrate' from the 'Project Resources' tab to set up the Heart Rate click.

HeartRate2.png

Click on the 'Configuration' tab and select 'Pulse Oximeter Mode'. Set the number of samples to be taken as 100 SPS and the 'Pulse Width' to 1600 µs. IR and RED LED currents are programmable. IR and RED LED wavelengths vary depending on the set current values.

Set the 'IR LED Current' to 30.6 mA and 'RED LED Current' to 14.2 mA to get optimal value for the IR and RED values.

Under 'Interrupts', check the boxes for 'Heart Rate', 'Temperature', 'SPO2 Ready', and 'FIFO Buffer Almost Full'. Uncheck the 'Generate Example' box. The configuration for the Heart Rate board is shown below:

HRSettings.png

6

Set up the EUSART1

Under the 'Device Resources' tab of the MCC, select the 'EUSART1' peripheral.

EUSART.png

The EUSART1 and its corresponding libraries are now added to the Project Resources. Click on the 'EUSART1' label under the 'Project Resources' tab to configure EUART1.

EUSART1.png

Set the EUSART baud rate to 9600. This is the default baud rate for the GSM-GPS module in asynchronous mode. Check the 'Enable EUSART Interrupts' box to indicate the end of the transmission. The configuration is shown below:

EUSARTSettings.png

7

Set up the EUSART2

As a reference, we are going to set up EUSART2 to receive/transmit responses from GSM-GPS to a command terminal.

Under the 'Device Resources' tab, select the peripheral 'EUSART2'.

EUSART2.png

The EUSART2 and its corresponding libraries are now added to the Project Resources.

ProjectResourcesEUSART2.png

Click on the 'EUSART2' label under the 'Project Resources' tab to configure EUART2. Click on the 'Enable EUSART Interrupts' box to indicate end of transmission and reception. Configure the EUSART2 peripheral as shown below:

EUSART2Settings.png

8

Configure the Pin Manager

There are multiple pins that need to be set in the Pin Manager. Enable the pins that are shown in the picture below:

PinManager.png

The Grid View of the Pin Manager should look like the image above when completed.

Custom Name for Pins

Click on 'Pin Module' in the 'Project Resources' tab.

PinModule.png

Rename RD7 as PWKEY. The PWKEY is the power key for the GSM-GPS module. To rename a pin, click on the 'Custom Name' for the pin and type in the new name as show below:

PWKEY.png
PackageView.png

9

Generate Code

Click on the Generate Code button to generate source code for this project.

Generate.png

The project will now have generated both Header Files and Source Files. It should also have a generated main.c file.

GeneratedFiles.png

10

Adding Functionality

Download the project ZIP file, locate the SpO2_GPS_SMS.c and SpO2_GPS_SMS.h files and add them to your project folder.

Files.png

Go back to MPLAB X IDE and right click on 'Source Files' in the 'Projects' tab.

Click on 'Add Existing Item' from the drop-down menu.

AddItem.png

Choose SpO2_GPS_SMS.c from the working project folder and click on 'Select'.

SelectFiles.png

The 'Projects' tab must look like the following picture after adding the file:

AddedFile.png

Now right click on 'Header Files' in the Project tab.

Click on 'Add Existing Item' from the drop-down menu.

AddHeaderFile.png

Choose SpO2_GPS_SMS.h from the working project folder and click on 'Select'.

HeaderFile.png

The 'Projects' tab must look like the following picture after adding the file:

HeaderFileAdded.png

11

Computing the SpO2 Value

The function COMPUTE_SpO2() computes the SpO2 value as follows:

  • It checks for a minimum number of SpO2 samples received from the Pulse Oximeter.

  • If the IR and RED values are greater than 1000, then the average values of RED and IR LED are computed. Else, the function resets the number of samples to zero.

  • The SpO2 value is then calculated as shown below:

12

main.c

The main file needs modifications to incorporate the SpO2_GPS_SMS file. To add them, double click on the main.c file to open it up in the editor window.

mainFile.png

The main.c file requires a few lines to be uncommented for the interrupts to work properly. In order for the interrupt to work, Global Interrupts and Peripheral Interrupts need to be enabled. MCC already has the control commands in the default main.c file, they are just commented out with two forward slashes (//). The forward slashes need to be removed to enable these lines of code.

EnableInterrupts.png

To include the functionality defined for the Heart Rate/Pulse Oximeter and GSM-GPS module, the header file SpO2_GPS_SMS.h must be included in the main file. The following line is included before the main () function definition:

AddHFile.png

The Pulse Oximeter and the GSM-GPS module must be initialized. To initialize the pulse oximeter, call SpO2_Initialize (). To initialize the GSM-GPS module, call the GSM_GPS_Initialize () function.

Initialize.png

13

Programming the Device

Make sure your development board is connected to power and that the project has the correct programming tool selected. Click on the Make and Program Device button. This will build the project and launch the programmer. In the Output window you should see a series of messages and if successful, it will end with a Programming/Verify complete message.

Complete.png

 Results

Place the index finger over the Pulse Oximeter Sensor for six seconds for the system to take samples and compute SpO2. The SpO2 value and the current location of the patient is sent as an SMS to the desired phone number as shown below:

+CGPSINF: 32,000304.000,V,0000.0000,N,00000.0000,E,0.000,0.00,060180,,,N
OK
Your SPO2 99.562496 %

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.