DEV Community

Qandil Tariq
Qandil Tariq

Posted on

Building a Real-Time Heart Rate Monitoring App with Kotlin + Google Cloud

Health monitoring apps are everywhere, but most rely on external wearables.

What if you could track your heart rate directly on your phone and still sync results to the cloud for secure storage and analysis?

That’s exactly what I built as part of my MSc dissertation: a Heart Rate Monitoring App powered by Kotlin (Jetpack Compose) and a Python + Firestore backend.


🚩 Problem

Wearables are expensive and not always accessible.

So the question was:

Can we capture, process, and store heart rate data using only a smartphone, and still keep it reliable and secure?


✨ Features

  • πŸ“± Real-time heart rate monitoring
  • 🚨 Threshold alerts (notify if BPM is abnormal)
  • ☁️ Cloud sync with Firestore
  • πŸ“Š Reports + trends visualization
  • πŸ” User authentication with Firebase

πŸ›  Tech Stack

  • Frontend: Kotlin, Jetpack Compose, MVVM, Coroutines
  • Backend: Python Flask microservice
  • Cloud: Google Cloud Firestore
  • Auth: Firebase Authentication
  • CI/CD: GitHub Actions

βš™οΈ How It Works

  1. User signs in (Firebase Auth).
  2. The app captures heart rate (camera/sensor).
  3. Readings are sent to Firestore.
  4. A Python backend checks for alerts.
  5. Users view reports + trends in the app.

πŸ’» Sample Code

Kotlin β€” Saving Data to Firestore

val db = FirebaseFirestore.getInstance()
val heartRateData = hashMapOf(
    "userId" to userId,
    "heartRate" to bpm,
    "status" to status,
    "timestamp" to System.currentTimeMillis()
)

db.collection("HeartRateReading")
    .add(heartRateData)
    .addOnSuccessListener { Log.d("Firestore", "Saved!") }
    .addOnFailureListener { e -> Log.w("Firestore", "Error", e) }
Enter fullscreen mode Exit fullscreen mode

Jetpack Compose β€” Displaying Trends

@Composable
fun HeartRateCard(avg: Int, max: Int, min: Int) {
    Column(
        modifier = Modifier.padding(16.dp)
    ) {
        Text("Avg: $avg BPM", fontWeight = FontWeight.Bold)
        Text("Max: $max BPM", color = Color.Red)
        Text("Min: $min BPM", color = Color.Blue)
    }
}
Enter fullscreen mode Exit fullscreen mode

Python β€” Simple Alerting Service

from google.cloud import firestore

db = firestore.Client()

def check_alerts():
    docs = db.collection("HeartRateReading").stream()
    for doc in docs:
        data = doc.to_dict()
        if data["heartRate"] > 140:
            print(f"⚠️ High HR detected: {data['heartRate']} BPM for {data['userId']}")
Enter fullscreen mode Exit fullscreen mode

πŸ“Š Screenshots

(Add your app UI and Firestore console screenshots here)


πŸŽ“ Lessons Learned

  • On-device vs cloud β†’ trade-offs between privacy and performance
  • Importance of data security in healthcare apps
  • A clean UI/UX makes adoption easier
  • Cloud pipelines = real-time dashboards + analysis

πŸ—Ί Roadmap

  • πŸ€– Add ML models for anomaly detection
  • ❀️ Expand to other vitals (SpO2, BP)
  • 🍎 Build iOS client with Kotlin Multiplatform
  • πŸ₯ Healthcare integration (e.g., NHS)

βœ… Conclusion

This project showed me how AI + Mobile + Cloud can combine to deliver meaningful health insights.

πŸ‘‰ Code available here: HeartRateMobile

πŸ‘‰ Medium version (more detailed): Real-Time Health Monitoring on Android


Thanks for reading! Follow me for more posts about Android, AI, and cross-platform development πŸš€

Top comments (0)