ESP32 ProjectsIOT Projects

IoT Based Health Monitoring system on ESP32 Web Server

Learn how to Build an IoT based patient health monitoring system using ESP32 Microcontroller board and display health data on webserver


In this project, we are going to learn how to create an IoT based health monitoring system using ESP32 Microcontroller with built in WiFi and Bluetooth to display health data such as:

  • Patient body Temperature,
  • Patient Blood Oxygen(SPo2),
  • Patient Heart rate,
  • Room Temperature
  • Room Humidity
  • and more (optional).

As the technology in the IoT industry improving every day with new inventions of health monitoring devices, It is becoming easy to monitor few health parameters easily at our home itself, So if any abnormal things happens we can immediately take some action against it by visiting a nearest clinic or doctor.

IoT based health monitoring system on webserver mutidevice

It is important to monitor some important health parameters like body temperature, heart rate and Blood Oxygen levels as they may indicate a precaution before any illness. Specially old age people health should be monitored regularly as their immunity weakens with the increase in age.

Due to work and busy schedules many people don’t have time to visit a clinic to track health status, so taking this scenario into consideration let’s build a patient health monitoring system using IoT which can sense and monitor few important health parameters at home or work.

So, in our IoT project we are interfacing few sensors with ESP32 Microcontroller such as DS18B20 waterproof temperature sensor to measure body temperature, MAX30100/MAX30102 heart rate and Pulse Oximeter sensor module to measure Blood SpO2 and Heart rate, BME280 temperature and humidity sensor to measure the room temperature and humidity as these parameters sometimes makes a person feel uncomfortable.

Before getting started with the project lets learn what are the required components and also learn about: Sensors we are using, why we are using them, what are their advantages over the other sensors.

Required components

Product NameQuantityamazon logoamazon logo india
ESP32 microcontroller with built in WiFi and Bluetooth1
MAX30100 or MAX30102 Pulse Oximeter sensor1
DS18B20 Waterproof temperature sensor1
BME280 temperature and humidity sensor1
Few Connecting Wires
Here are the required components along with Amazon buying links at best prices.

MAX30100 or MAX30102 Pulse Oximeter and Heart rate sensor

In this Project we are using MAX30102 instead of old model MAX30100 as the old model has a design issue between I2C pull up resistors as they are connected to 1.8V which is too low for a microcontroller to detect the signal. If you still want to use the old model MAX30100 this issue can be rectified by removing resistors and adding external resistors which we explained in detail in our previous article or you can buy GY-MAX30100 which has corrected hardware circuits.

MAX30102 has better hardware design and software support. This module has emitting Red LED, emitting InfraRed LED and a Photodetector to absorb the emitted light. It is built with low noise analog signal processing circuits with ambient light cancellation for better accuracy.

When the place our finger on the sensor the red light coming from the LED is passed through the finger, According to the biology when heart pumps blood has more oxygen when compared with the heart relaxed state. The Oxygenated blood absorb more Red and IR light than the deoxygenated blood, the Photodetector absorb the remaining light from the finger and analyze it to give the SpO2 results, and the time gap between the low light and high light is calculated which is nothing but Pulse rate or Heart rate. Which is sent to the microcontroller using I2C communication.

This sensor operates between 3.3v to 5v.

For more details refer: MAX30102 datasheet here

MAX30102 Pinout Diagram:

max30102 pulse oximeter heart rate sensor pinout diagramFrom the above image you can see the MAX30102 has 8 pins but in this project we use only 4 pins on the left side for I2C communication with ESP32.

DS18B20 waterproof temperature sensor

DS18B20 temperature sensor is a Onewire sensor which means it can send the data only through single data wire(and GND) to microcontrollers. A 64-bit unique serial code is given to each sensor to differentiate every sensor when more than one DS18B20 sensors are connected. This allows us to get multiple sensor data through single data line through single GPIO pin. By default it is configured with 12 bits and 0.0625°C sensitivity.

DS18B20 temperature sensor pinout diagram

DS18B20 temperature operates between 3v-5.5V, consuming very low power nearly 1mA. It has an accuracy of ±0.5°C. To know more about DS18B20 temperature sensor refer our previous article:

In this IoT health monitoring system project we are using DS18B20 instead of LM35 as DS18B20 comes with waterproofing which makes it easy to be placed anywhere on the body with moisture. DS18B20 has onewire technology where we can connect multiple sensors and measure the temperatures of head, neck, under arms or any place on the body according to the requirement. And finally the accuracy and stability over LM35.

For more details refer: DS18B20 official datasheet

BME280 Temperature and humidity sensor

In this health monitoring system project, we are using BME280 sensor which gives temperature and humidity values of the room. Based on BOSCH piezo-resistive technology BME280 has features like low energy consumption, ultra compact with great precision and stability in output signal.

BME/BMP280 pinout diagram

BME280 is superior to BMP180 and has relative humidity sensing, these sensors performs better than DHT22 and DHT11 in terms of accuracy and long term stability in output. BME280 heats up little bit than other sensors and measurements can vary with increase of 2-3°F, but we still choose BME280 instead of others because it’s output give vary stable results when compared with other sensors in the range.

BME280 works in the voltage range of 1.8v to 3.3v and measures temperatures between -40 to 85°C with an accuracy of 1°C. It also measures relative humidity ranging 0-100% at an accuracy of +-3%. It sends the data signals to microcontroller through both I2C and SPI communication protocols.

For more details refer: BME280 Official datasheet

IoT based health monitoring system circuit diagram interfacing sensors with ESP32

Now lets connect all the required components according to the below schematic diagram.

IoT based health monitoring system circuit diagram interfacing sensors with ESP32 web server

As you can see from the above circuit diagram of IoT based health monitoring system project, we connected 3 sensor which gives 5 health parameters as we discussed in the overview. Let’s see how they are connected.

MAX30102 SpO2 and heart rate sensor to ESP32

This sensor is connected in I2C communication protocol, so SDA and SCL pins from the sensor are connected to D21 and D22 pins of ESP32 respectively. The sensor is powered with 5V power supply from the ESP32 VIN pin to VIN pin of sensor as we are supplying 5V to ESP32, GND pin of sensor is connected to GND of ESP32.

BME280 temperature and relative humidity sensor to ESP32

This sensor also uses I2C communication protocol and connected same as the above sensor. SDA and SCL of sensor to D21 and D22 respectively. The only change is with power supply. As BME280 supports voltages up to 3.3V we are powering VIN pin of sensor with 3.3V pin of ESP32.

DS18B20 water proof temperature sensor to ESP32

We powered this sensor with 5V from the ESP32 and connected to red wire. Black wire is connected to GND. and the yellow wire is connected to digital pin D5(GPIO5) of ESP32. A 4.7 K.Ohm resisitor is connected between the yellow data wire and 5v supply to amplify the data signal.

That’s it for connection, now lets get into the coding section to upload code of IoT based health monitoring system using Arduino IDE to get data over ESP32 web server.

Source Code of health monitoring system using ESP32 web server:

Before getting started with program code. We need install few required libraries of sensors in Arduino IDE listed below. You can either install these libraries through Arduino IDE built in Library manager or just by downloading the latest libraries and paste it into libraries folder through the GitHub links below.

  • DallasTemperature  – Link   by Miles burton
  • Adafruit_BME280  – Link  by Adafruit
  • MAX30105  – Link    by Sparkfun
  • OneWire Library – Link  by Paul Stofforegen
  • WebServer.h Library download- Link

After downloading all the required libraries, connect ESP32 to PC where Arduino IDE is Installed. Next copy the below program code and paste it in the Arduino IDE workspace and change few parameter like WiFi username and Password. Select the board to ESP32 Wrover module and Port where it is connected from the tools menu.

Program Code:

Now hit upload button to upload the code to ESP32. After uploading open the serial monitor of specified baud rate to get the network connection status and IP address and few values as below output image.

IoT based health monitoring system output on ESP32 serial monitorHere I made buffer sample to 5 so all parameters are visible in the output. Here you can see all the patient health parameters like Body temperature, Blood Oxygen, Heart rate, Room temperature and humidity.

As you can see from the above output from serial monitor an IP address was generated, which you can type on any device browser (mobile or PC) connected to same network to check on the web server interface as shown in the below image.

IoT based health monitoring system output on ESP32 webserverWe are going to make a IoT based remote patient health monitoring system in our next article, where you can monitor patient health parameters remotely from anywhere in the world. So, please stay tuned with Circuitschools.

Tips, Notes and Error with solutions

Tips: You can interface other sensors like ECG sensor, Air Quality monitoring sensors and other latest sensors with the same ESP32 to get more parameters but limit till the maximum memory limit of the ESP32 code. ESP32 has Bluetooth and WiFi built in so you can monitor the data over Bluetooth also.

Notes: This sensors are just for prototyping and cannot be replaced with the certified medical devices. You can still use them by comparing the results with standard devices and modify the code.

For MAX30102 Attach finger with sensor using rubber band as humans cannot apply constant pressure on it.

Errors and Solutions:

Could not find a valid BME280 sensor, check wiring!

  • Use BME280 only as BMP280 cannot measure relative humidity.
  • Check wiring and mainly the I2C address, you can check the I2C address with I2C scanner from our previous articles.
  • If you got same error use example code of BME280 from the library.
  • If still not found maybe the sensor is damaged.

MAX30102 was not found. Please check wiring/power

  • Connect the sensor with 5v supply as sometimes 3.3v are not sufficient for the LEDs to perform correctly.
  • Check wiring
  • check whether LEDs are glowing if not remove lines 89 and 90 as they wait for you to click any key on serial monitor

If any other errors appear other than the above listed ones check with the sensor libraries are they installed from the mentioned creators. And also feel free to post it below in the comment section. And please share this article with your friends if you like them and follow us on Facebook page.

Video Tutorial:

IOT based Health monitoring system on ESP32 Webserver

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles


  1. hi

    i was verrifying the sketch and got the following error message :

    In file included from C:\Users\andy\AppData\Local\Temp\arduino_modified_sketch_753243\sketch_may08a.ino:8:
    C:\Users\andy\Desktop\Arduino\libraries\SparkFun_MAX3010x_Sensor_Library-master\src/MAX30105.h:42: warning: “I2C_BUFFER_LENGTH” redefined
    #define I2C_BUFFER_LENGTH 32

    In file included from C:\Users\andy\AppData\Local\Temp\arduino_modified_sketch_753243\sketch_may08a.ino:3:
    C:\Users\andy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3\libraries\Wire\src/Wire.h:38: note: this is the location of the previous definition
    #define I2C_BUFFER_LENGTH 128

    C:\Users\andy\AppData\Local\Temp\arduino_modified_sketch_753243\sketch_may08a.ino: In function ‘void setup()’:
    sketch_may08a:58:18: error: ‘handle_OnConnect’ was not declared in this scope
    server.on(“/”, handle_OnConnect);
    sketch_may08a:59:21: error: ‘handle_NotFound’ was not declared in this scope
    sketch_may08a:81:3: error: expected ‘}’ at end of input
    C:\Users\andy\AppData\Local\Temp\arduino_modified_sketch_753243\sketch_may08a.ino:40:14: note: to match this ‘{‘
    void setup() {
    exit status 1
    ‘handle_OnConnect’ was not declared in this scope

    any solution for this ?

    1. Hi Andy,
      I think this error is due to the mismatch in libraries or their versions. Please install the libraries given above the code.
      If still error occurs for you, add void handle_OnConnect(); this before the void setup().
      For us the code is working perfectly well.

Leave a Reply

Your email address will not be published.

Back to top button