Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 Based Health Monitoring Station with TFT Display and Environmental Sensing

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Based Health Monitoring Station with TFT Display and Environmental Sensing

Circuit Documentation

Summary

This circuit is designed to interface an Arduino Mega 2560 with several peripherals including an ili9341 TFT display, a KY-015 DHT11 temperature and humidity sensor, a DS1307 real-time clock (RTC), a MAX30100 pulse oximeter, and a pushbutton with a pull-up resistor. The Arduino Mega 2560 serves as the central microcontroller unit, managing data acquisition from the sensors, controlling the display output, and responding to user input via the pushbutton. The circuit is powered by the 5V output from the Arduino and includes necessary connections for I2C communication and digital signal interfacing.

Component List

ili9341 TFT Display

KY-015 DHT11

Arduino Mega 2560

RTC DS1307

MAX30100

Pushbutton

Resistor (10k Ohms)

Wiring Details

ili9341 TFT Display

KY-015 DHT11

RTC DS1307

MAX30100

Pushbutton

Resistor (10k Ohms)

Documented Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <RTClib.h>
#include <DHT.h>
#include <MAX30100_PulseOximeter.h>

// Pin definitions
#define TFT_CS     10
#define TFT_RST    9
#define TFT_DC     8
#define DHT_PIN    2
#define BUTTON_PIN A8

// Create instances for the components
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
RTC_DS1307 rtc;
DHT dht(DHT_PIN, DHT11);
PulseOximeter pox;

// Variables to store sensor data
float temperature, humidity;
uint8_t heartRate;
float spo2;
bool displayHeartRate = false;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize the display
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  // Initialize the RTC
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  // Initialize the DHT sensor
  dht.begin();

  // Initialize the MAX30100 sensor
  if (!pox.begin()) {
    Serial.println("Failed to initialize pulse oximeter");
    while (1);
  }
  pox.setOnBeatDetectedCallback(onBeatDetected);

  // Initialize the pushbutton
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // Check if the button is pressed
  if (digitalRead(BUTTON_PIN) == LOW) {
    displayHeartRate = !displayHeartRate;
    delay(500); // Debounce delay
  }

  if (displayHeartRate) {
    // Read heart rate and SpO2
    pox.update();
    heartRate = pox.getHeartRate();
    spo2 = pox.getSpO2();

    // Display heart rate and SpO2
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(0, 0);
    tft.print("Heart Rate: ");
    tft.print(heartRate);
    tft.println(" BPM");
    tft.print("SpO2: ");
    tft.print(spo2);
    tft.println(" %");
  } else {
    // Read temperature and humidity
    temperature = dht.readTemperature();
    humidity = dht.readHumidity();

    // Read time from RTC
    DateTime now = rtc.now();

    // Display time, temperature, and humidity
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(0, 0);
    tft.print("Time: ");
    tft.print(now.hour());
    tft.print(":");
    tft.print(now.minute());
    tft.print(":");
    tft.println(now.second());
    tft.print("Temp: ");
    tft.print(temperature);
    tft.println(" C");
    tft.print("Humidity: ");
    tft.print(humidity);
    tft.println(" %");
  }

  delay(1000); // Update every second
}

void onBeatDetected() {
  Serial.println("Beat detected!");
}

This code initializes and manages the various components connected to the Arduino Mega 2560. It includes setup routines for the display, sensors, and RTC, as well as a loop that alternates between displaying heart rate and SpO2 data or temperature, humidity, and time based on the state of the pushbutton. The onBeatDetected callback function is used to indicate when a heartbeat is detected by the MAX30100 sensor.