In this tutorial we are going to design and construct an IoT based patient health monitoring system using Arduino and generic ESP8266. The proposed project can collect and send patient’s health data to an IoT cloud server such as Thingspeak where real time health status of the patient can be recorded and monitored in a remote location where a healthcare professional is present.
We will see:
- What is IoT based health monitoring system?
- Block diagram of IoT health monitoring system.
- How to setup Thingspeak account?
- Circuit diagram of IoT health monitoring system.
- How to upload code to ESP8266 correctly?
- Program code for ESP8266 and Arduino.
- Prototype, result and troubleshooting.
What is IoT patient based health monitoring system?
IoT based patient health monitoring system is a generic term given to any medical equipment that has internet capability and can measure one or more health data of a patient who is connected to the device such as heartbeat, body temperature, blood pressure, ECG, steps etc. The equipment can record, transmit and alert if there is any abrupt change in the patient’s health.
By this definition, it includes devices such as smart-watches, fitness trackers, smart-phones to expensive hospital equipment which can connect to internet.
IoT based health monitoring system is used where the patient and heath expert(s) are at different locations. For example, a patient can stay at home and continue his/her routine life and a doctor can monitor patient’s heath. Based on the received data the heath expert can prescribe a best treatment or take an immediate action in case of an emergency.
The proposed design of IoT based heath monitoring system is built around Arduino microcontroller which is the brain of the project.
Arduino collects real time health data from pulse sensor which measures heartbeat in minutes or BPM (beats per minute). A digital temperature sensor connected to Arduino measures body temperature of the patient.
A buzzer produces auditory beeps when the patient’s heartbeat occurs / detected. This gives a brief insight to a healthcare professional how a patient’s heart is performing in a particular health condition. Abnormal heartbeats can be detected by just listening to the beeps.
A generic ESP8266 IoT module is connect to Arduino via UART, it is responsible for connecting the machine to internet and also for sending health data to a IoT server (Thingspeak) for storing and monitoring.
This circuit is not only capable of sending patient’s health data to a server but also can show real time data on a 16×2 LCD display. This is useful for a healthcare professional who is actively monitoring a patient on site.
How to set-up Thingspeak account to receive patient data:
You need to setup your Thingspeak account correctly to receive patient’s health data.
- You need to create a Thingspeak account by clicking this link.
- Enter the credentials it asks while signing up.
- Click “new channel” and edit the following in the channel settings tab.
- Don’t forget to click save.
- Now click “API keys” tab on Thingspeak dashboard to see your “write” API key. The API key is an access code using which you can write data to your Thingspeak channel.
- Take note of your “write API key” and channel ID which need to be inserted in the given program code.
- By clicking “Private view” tab you can see a couple of empty channels which are ready to receive data.
Circuit diagram of IoT based patient health monitoring system:
As mentioned earlier Arduino is the brain of the project and you may use any Arduino board that is available with you and you can connect to the same pin numbers that are shown in the schematic.
The arduino is responsible for collecting, displaying and sending the data to ESP8266. The whole circuit can be powered using USB or via “Vin” pin (9V-12V).
The generic ESP8266 module is a miniature microcontroller board which has RAM, ROM, clock, communication protocols and I/O pins just like any other microcontrollers and it need to be programmed to make it functional.
It does not come with a USB port so we need to use its UART pins to upload a code which will be discussed in the later part of this post.
It operates at 3.3V (5V can kill) and it supports UART / serial communication protocol and it has (only) two GPIO pins which we are not going to use.
Arduino collects and sends patient data to this ESP8266 over its UART pins. ESP8266 will connect to its designated server which is programmed to it and passes the data.
The pulse sensor / heartbeat sensor is an inexpensive analog sensor which can measure reasonably accurate pulse rate of human heart with the help of a microcontroller.
A microcontroller like Arduino can be programmed to calculate its analog output to BPM or beats per minute.
It can operate from 3.3V to 5V, but here we are connecting it to 5V supply. It has just 3 pins: Vcc, GND and signal (Analog out).
On the front we have a green LED with a specific wavelength and a light sensor; you can place your finger (except thumb) on front part of the sensor with a slight pressure.
The process behind detecting heartbeat is when our heart pumps there will be blood flow in our nerves, this flow changes the light intensity reflected to the light sensor.
On the back of the pulse sensor there is an amplifier and noise reduction circuit which outputs analog signal proportional to the changes in the reflected light.
The pulse senor must be used with dry fingers and the back of the sensor must not be touched and since ambient light can interfere with the sensor while measuring, it is recommended to wrap your finger and the sensor with an insulation tape as shown below for the best result:
We are using a general purpose water proof digital temperature sensor DS18B20 to measure body heat which comes in a sealed metallic enclosure.
Measuring body temperature can reveal a lot about patient’s health and a healthcare professional can identify abnormalities in a patient’s health.
Inside the metallic enclosure there is a transistor like sensor which measures the temperature (that’s why a transistor like component is shown in the circuit diagram).
It has 3 wires: Vcc, GND and data, the data wire must be connected to a pull-up 4.7K resistor.
We are using a water proof sensor because the sensor will be placed on human body for prolong amount of time and dust, sweat and other body fluids can accumulate on the sensor which could lead to inaccurate temperature measurement.
A water proof sensor can be easily cleaned and dust and body fluids won’t able to clog the sensor much.
Where the temperature sensor can be place on human body?
There are several places on human body where temperature sensor can be placed like: oral, ear, underarm, rectal etc. Our best recommendation is underarm for the sensor placement after considering accuracy and convenience. You need to place it for at-least 2 minutes so that temperature gets settled properly.
A LCD display is provided to see the real time data from the sensors; it is set to show the body temperature and heartbeat in BPM. A 10K potentiometer is provided using which you can adjust LCD contrast for optimum legibility.
We are utilizing a 5V DC buzzer to detect heartbeat rhythm, just like in hospital rooms (or in TV serials/movies) where beep sound emerges when a patient is monitored using ECG / EKG etc.
The DC buzzer has polarity, the –Ve of buzzer is connected to GND and +Ve is connected to pin 8 of Arduino.
Audio beeps can give a healthcare professional an insight about pulse of a patient, for example, slow pulse indicates that the patient is sleeping or in coma or fast beep indicates that the patient is in some health trouble and need immediate medical attention.
Please note that not all medical devices in hospitals beep is indication of heartbeat, it can be of several types of alerts ranging from not so important alerts to extreme emergency alerts.
How to upload code to generic ESP8266?
As mentioned earlier the ESP8266 does not come with a USB like Arduino or NodeMCU which allows us to upload code directly, instead we have to wire up the ESP8266 according to the given circuit.
Before we do that we need to install core ESP8266 files to Arduino IDE software only then we will able to compile and upload code.
- Copy this link: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Open Arduino IDE and go to Files > Preferences.
- A window will pop up as shown below:
- Now paste the URL to the box and click OK.
- Now go to Tools > Board > Boards Manager. A window will open as shown below.
Type “ESP8266” and you will see a drop-down option and install button. Select the latest version and click install. Installation could take about 5 minutes.
ESP8266 code upload circuit diagram:
- Wire-up circuit as shown above, the microcontroller IC must be removed from Arduino’s socket.
- Now copy and paste the code to your IDE and insert your Wi-Fi credentials, channel ID and write API key.
- Select Tools > Board > Generic ESP8266 Module.
- Now press and hold the flash button and press reset button momentarily once and release the flash button. This will make the ESP8266 ready for uploading a new code.
- Select baud rate as 115200, select the correct COM port and click upload.
- Once the code is uploaded you will see “Done uploading” as shown below:
- Once you successfully uploaded the code to ESP8266, you need to re-wire the circuit as per the main circuit diagram and don’t forget to insert the microcontroller IC back to the socket.
Download Thingspeak.h library: Click here
Program code for generic ESP8266:
You need to insert your Wi-Fi credentials here:
You need to insert channel details here:
Program code for Arduino:
You need to upload the below given code to Arduino once you successfully uploaded the ESP8266 code. So, yes this project uses two set of program codes to function. Don’t forget to select the correct Arduino board and COM port to upload the code.
Download “Onewire.h” library: Click here
Download “DallasTemperature.h” library: Click here
Download “PulseSensorPlayground.h” library: Click here
Result: Private view on Thingspeak
It could take more than 30 seconds to update a field and each field will be updated one after the other.
If your channels are not getting updated with any values after few minutes, you can check your Wi-Fi router’s connected devices (for ESP8266) by logging in to its admin control.
In the above list of connected devices (to Wi-Fi router) we can see that ESP8266 has been connected successfully. It will be like “ESP” followed by some numbers.
If it does not appear here, please check the wiring and Wi-Fi credentials on the code.
If you have any questions regarding this project feel free to ask us in the comment, you will get a guaranteed reply from us.