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

ESP32-Based Health Monitoring System with TFT Display and RTC

View and Edit Project In Cirkit DesignerImage of ESP32-Based Health Monitoring System with TFT Display and RTC

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that integrates an ESP32 microcontroller with various peripherals including an ILI9341 TFT display, an RTC DS3231 module, a MAX30102 sensor, and a 28BYJ-48 stepper motor driven by a ULN2003 driver. The circuit is designed to display health data and time on the TFT display, read sensor data, and control a stepper motor.

Component List

ESP32 on Baseboard

ILI9341 TFT Display

RTC DS3231

MAX30102

28BYJ-48 Stepper Motor

ULN2003

Wiring Details

ESP32 on Baseboard

ILI9341 TFT Display

RTC DS3231

MAX30102

28BYJ-48 Stepper Motor

ULN2003

Documented Code

ESP32 on Baseboard

sketch.ino

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

ILI9341 TFT Display

sketch.ino

#include "FS.h"
#include <SPI.h>
#include <TFT_eSPI.h>
#include <Wire.h>
#include <RTClib.h>  // Include RTC library
#include <MAX3010x.h>  // Include MAX3010x library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
RTC_DS3231 rtc;            // Declare RTC object
MAX30105 sensor;           // Declare MAX30105 sensor

#define CALIBRATION_FILE "/TouchCalData1"
#define REPEAT_CAL false

// Button parameters
#define BTN_W 60
#define BTN_H 40
#define BTN_SPACING_X 10
#define BTN_SPACING_Y 10
#define BTN_TEXTSIZE 2

// Button labels
char dayLabel[7][10] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
TFT_eSPI_Button dayButton[7]; // Create 7 buttons

// Display dimensions
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define PADDING 3 // Padding for UI elements

int pulse = 0;       // Placeholder for pulse measurement
int glucose = 0;     // Placeholder for glucose measurement

//------------------------------------------------------------------------------------------

void setup() {
  Serial.begin(115200);
  tft.init();
  tft.setRotation(0); // Portrait mode

  Wire.begin(21, 22);  // Initialize I2C (SDA, SCL)
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1); // Halt if RTC is not found
  }

  // Initialize MAX30105 sensor
  if (!sensor.begin()) {
    Serial.println("MAX30105 not found. Please check wiring/power.");
    while (1);
  }

  touch_calibrate();
  drawUI();
}

//------------------------------------------------------------------------------------------

void loop() {
  uint16_t t_x = 0, t_y = 0;
  DateTime now = rtc.now(); // Get current time from RTC

  // Simulate readings for pulse and glucose (replace with actual sensor readings)
  pulse = random(60, 100);      // Example pulse value (replace with actual reading)
  glucose = random(80, 180);    // Example glucose value (replace with actual reading)

  // Update Date/Time and Health Data on the display
  updateDateTime(now);
  updateHealthData();

  // Check for touch input
  bool pressed = tft.getTouch(&t_x, &t_y);

  for (uint8_t b = 0; b < 7; b++) {
    if (pressed && dayButton[b].contains(t_x, t_y)) {
      dayButton[b].press(true);
    } else {
      dayButton[b].press(false);
    }
  }

  for (uint8_t b = 0; b < 7; b++) {
    if (dayButton[b].justReleased()) dayButton[b].drawButton();
    if (dayButton[b].justPressed