I used Fritzing to create the circuit diagram. For power input, I am using a 2S Li-ion battery pack, which provides an average voltage of 7.4V. This is connected to the Vin pin of the Arduino UNO Board.How It All Comes Together:
Data Collection:
- The ECG sensor (AD8232) continuously monitors the heart’s electrical activity, detecting anomalies.
- The MLX90614 temperature sensor tracks body temperature, alerting to potential fever or temperature changes.
- The MAX30102 pulse oximeter measures both blood oxygen levels and heart rate, providing insights into respiratory and cardiovascular health.
- Data Collection:The ECG sensor (AD8232) continuously monitors the heart’s electrical activity, detecting anomalies.The MLX90614 temperature sensor tracks body temperature, alerting to potential fever or temperature changes.The MAX30102 pulse oximeter measures both blood oxygen levels and heart rate, providing insights into respiratory and cardiovascular health.
Data Processing:
- The Arduino Uno R4 WiFi collects data from all the sensors.
- It processes this data to generate meaningful health metrics. For example, it can calculate heart rate variability from ECG signals or determine average SpO2 levels from multiple readings.
- Data Processing:The Arduino Uno R4 WiFi collects data from all the sensors.It processes this data to generate meaningful health metrics. For example, it can calculate heart rate variability from ECG signals or determine average SpO2 levels from multiple readings.
Real-Time Monitoring and Alerts:
- The Arduino sends the processed data to the Blink app via its WiFi capabilities.
- The Blink app provides real-time monitoring of health metrics, enabling remote observation.
- If any health parameters fall outside of predefined thresholds (e.g., abnormally high heart rate or low SpO2), the system can trigger alerts to both the patient and healthcare providers.
- Real-Time Monitoring and Alerts:The Arduino sends the processed data to the Blink app via its WiFi capabilities.The Blink app provides real-time monitoring of health metrics, enabling remote observation.If any health parameters fall outside of predefined thresholds (e.g., abnormally high heart rate or low SpO2), the system can trigger alerts to both the patient and healthcare providers.
Remote Access and Management:
- The Blink app enables users to view their health data remotely, reducing the need for frequent in-person visits to healthcare facilities.
- Healthcare providers can access the data to make informed decisions and intervene when necessary, improving patient outcomes through proactive care.
- Remote Access and Management:The Blink app enables users to view their health data remotely, reducing the need for frequent in-person visits to healthcare facilities.Healthcare providers can access the data to make informed decisions and intervene when necessary, improving patient outcomes through proactive care.
Adaptability and Scalability:
- The modular design allows for easy upgrades and integration of additional sensors or features as technology advances.
- This adaptability ensures the system can be customized for different healthcare needs and patient profiles.
- Adaptability and Scalability:The modular design allows for easy upgrades and integration of additional sensors or features as technology advances.This adaptability ensures the system can be customized for different healthcare needs and patient profiles.
Above, you can see the assembled image of the components. With the connections completed, let's move on to coding the Arduino board.
Code ExplanationThis code is designed for an Arduino UNO R4 WiFi microcontroller to collect physiological data (heart rate, SpO2, body temperature, and ECG) using multiple sensors, then send that data to Ubidots, an IoT platform, via Wi-Fi using MQTT (Message Queuing Telemetry Transport). Here’s a breakdown:
Libraries and ConfigurationLibraries:
Wire
: For I2C communication (used by some sensors).MAX30100_PulseOximeter
: To communicate with the MAX30100 pulse oximeter sensor.Adafruit_MLX90614
: To interact with the MLX90614 temperature sensor.WiFiS3
: To handle Wi-Fi communication.PubSubClient
: To send data to the Ubidots MQTT broker.- Libraries:
Wire
: For I2C communication (used by some sensors).MAX30100_PulseOximeter
: To communicate with the MAX30100 pulse oximeter sensor.Adafruit_MLX90614
: To interact with the MLX90614 temperature sensor.WiFiS3
: To handle Wi-Fi communication.PubSubClient
: To send data to the Ubidots MQTT broker.
Constants:
WIFISSID
,PASSWORD
: Credentials for Wi-Fi connection.TOKEN
: Ubidots API token for authorization.DEVICE_LABEL
andVARIABLE_LABEL_*
: Labels used in Ubidots to identify this device and its data variables.MQTT_CLIENT_NAME
: Unique name for the MQTT client.ECG_PIN
: Analog pin where the ECG sensor (AD8232) is connected.REPORTING_PERIOD_MS
: Interval (1000 ms) between each data upload to Ubidots.- Constants:
WIFISSID
,PASSWORD
: Credentials for Wi-Fi connection.TOKEN
: Ubidots API token for authorization.DEVICE_LABEL
andVARIABLE_LABEL_*
: Labels used in Ubidots to identify this device and its data variables.MQTT_CLIENT_NAME
: Unique name for the MQTT client.ECG_PIN
: Analog pin where the ECG sensor (AD8232) is connected.REPORTING_PERIOD_MS
: Interval (1000 ms) between each data upload to Ubidots.
Sensor Objects:
PulseOximeter pox
: Interface object for the MAX30100.Adafruit_MLX90614 mlx
: Interface object for the MLX90614.- Sensor Objects:
PulseOximeter pox
: Interface object for the MAX30100.Adafruit_MLX90614 mlx
: Interface object for the MLX90614.
WiFi and MQTT Objects:
WiFiClient espClient
: Used for Wi-Fi communication.PubSubClient client
: Used for MQTT communication with Ubidots.- WiFi and MQTT Objects:
WiFiClient espClient
: Used for Wi-Fi communication.PubSubClient client
: Used for MQTT communication with Ubidots.
Data Buffers:
topic
andpayload
: Used to store MQTT topic and JSON payload data.- Data Buffers:
topic
andpayload
: Used to store MQTT topic and JSON payload data.
This function connects the ESP32 to Wi-Fi.
- Prints Wi-Fi status in the Serial Monitor.
- Checks the connection status every second, printing dots (".") until successfully connected.
- Once connected, it displays the IP address.
This function reconnects to the MQTT broker if disconnected.
- Attempts to connect with
client.connect()
usingMQTT_CLIENT_NAME
andTOKEN
for authentication. - If the connection fails, it waits 2 seconds before retrying.
Callback function executed each time a heartbeat is detected by the MAX30100, printing "Beat Detected!" to the Serial Monitor.
setup()This is the main setup function for the program.
- Serial Communication: Starts Serial for data output to the monitor.
- Wi-Fi Setup: Calls
setup_wifi()
to establish Wi-Fi connection. - MQTT Setup: Configures Ubidots as the MQTT server at
industrial.api.ubidots.com
on port1883
.
Sensor Initialization:
- Initializes the MAX30100 pulse oximeter and sets the IR LED current.
- Initializes the MLX90614 temperature sensor.
- Sets the ECG pin (A0) as an input.
- Sensor Initialization:Initializes the MAX30100 pulse oximeter and sets the IR LED current.Initializes the MLX90614 temperature sensor.Sets the ECG pin (A0) as an input.
This function contains the main code loop, running continuously.
- MQTT Reconnection: Calls
reconnect()
if the MQTT client is disconnected. - MAX30100 Update: Reads and processes data from the MAX30100 for heart rate and SpO2.
- ECG Reading: Reads the analog ECG signal from the AD8232 connected to
A0
.
Data Reporting:
Every 1000 ms, retrieves sensor data:
- Heart Rate and SpO2: Reads heart rate and SpO2 values from the MAX30100.
- Temperature: Reads ambient and object temperatures from the MLX90614.
- ECG Value: Analog reading from ECG sensor.
- Every 1000 ms, retrieves sensor data:Heart Rate and SpO2: Reads heart rate and SpO2 values from the MAX30100.Temperature: Reads ambient and object temperatures from the MLX90614.ECG Value: Analog reading from ECG sensor.
- Prints all values to the Serial Monitor.
- Data Reporting:Every 1000 ms, retrieves sensor data:Heart Rate and SpO2: Reads heart rate and SpO2 values from the MAX30100.Temperature: Reads ambient and object temperatures from the MLX90614.ECG Value: Analog reading from ECG sensor.Prints all values to the Serial Monitor.
Payload Creation and Publishing:
- Constructs a JSON payload with the sensor data.
- Publishes the data to Ubidots via MQTT.
- Payload Creation and Publishing:Constructs a JSON payload with the sensor data.Publishes the data to Ubidots via MQTT.
- Timestamp Update: Updates the
tsLastReport
timestamp to control the reporting interval.
This setup continuously gathers sensor data and uploads it to Ubidots for real-time monitoring.Next, let's upload the code and see how it works.
Working DemonstrationAfter uploading the code to the Arduino UNO R4 WiFi board, I turned on the hotspot and waited for the system to connect to the network. After some time, it connected successfully and began updating the fields in the Ubidots Cloud dashboard.
Comments