1NH21CE061 Sonu Kumar
Created September 4, 2024

Climber Guardian: Real-Time Health and Location Tracker

Ensure climber safety with real-time health monitoring and GPS tracking, enabling swift rescue in emergencies.

19
Climber Guardian: Real-Time Health and Location Tracker

Things used in this project

Story

Read more

Code

Climber Guardian: Real-Time Health and Location Tracker

C/C++
Library Inclusions: The code includes necessary libraries for Wi-Fi, DHT sensor, and software serial communication for the GSM module.
Pin Definitions: The code defines the pins for the heartbeat sensor, DHT sensor, and GSM module.
Wi-Fi and GSM Setup: The code connects to the specified Wi-Fi network and initializes the GSM module for sending SMS.
Loop Function: In the main loop, the code reads the heartbeat and temperature values. It checks if they exceed the defined limits and, if so, sends an alert via SMS.
Sending Alerts: The sendAlert function constructs a message containing the heart rate, temperature, and GPS coordinates (simulated in this case) and sends it to the specified phone number.
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <SoftwareSerial.h>

// Define pins
#define HEARTBEAT_PIN A0 // Connect heartbeat sensor to A0
#define DHTPIN 2         // Connect DHT sensor to pin 2
#define DHTTYPE DHT11    // Define the type of DHT sensor
#define GSM_RX 10        // GSM module RX pin
#define GSM_TX 11        // GSM module TX pin

// Wi-Fi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// GSM settings
SoftwareSerial gsmSerial(GSM_RX, GSM_TX);
const char* phoneNumber = "YOUR_PHONE_NUMBER";

// DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Threshold values
const int upperHeartRateLimit = 120; // Set your upper limit
const int lowerHeartRateLimit = 60;  // Set your lower limit
const float upperTempLimit = 37.5;    // Upper temperature limit (Celsius)
const float lowerTempLimit = 35.0;    // Lower temperature limit (Celsius)

void setup() {
  Serial.begin(115200);
  gsmSerial.begin(9600);
  
  // Initialize DHT sensor
  dht.begin();

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  // Read heartbeat (simulated, replace with actual sensor reading)
  int heartRate = analogRead(HEARTBEAT_PIN); // Replace with actual heartbeat sensor code
  heartRate = map(heartRate, 0, 1023, 50, 150); // Simulating heart rate

  // Read temperature
  float temperature = dht.readTemperature();
  if (isnan(temperature)) {
    Serial.println("Failed to read temperature");
    return;
  }

  // Check limits and send alerts
  if (heartRate > upperHeartRateLimit || heartRate < lowerHeartRateLimit || 
      temperature > upperTempLimit || temperature < lowerTempLimit) {
    sendAlert(heartRate, temperature);
  }

  // Display values on Serial Monitor
  Serial.print("Heart Rate: ");
  Serial.print(heartRate);
  Serial.print(" bpm, Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  delay(5000); // Delay for 5 seconds before the next reading
}

void sendAlert(int heartRate, float temperature) {
  // Get GPS coordinates (simulated, replace with actual GPS code)
  String gpsCoordinates = "Latitude: 12.345678, Longitude: 98.765432"; // Replace with actual GPS data

  // Create alert message
  String message = "Alert! ";
  message += "Heart Rate: " + String(heartRate) + " bpm, ";
  message += "Temperature: " + String(temperature) + " °C. ";
  message += "Location: " + gpsCoordinates;

  // Send SMS
  gsmSerial.println("AT+CMGF=1"); // Set SMS mode
  delay(100);
  gsmSerial.print("AT+CMGS=\"");
  gsmSerial.print(phoneNumber);
  gsmSerial.println("\"");
  delay(100);
  gsmSerial.print(message);
  delay(100);
  gsmSerial.write(26); // Send Ctrl+Z to send the message
  delay(1000);
  Serial.println("Alert sent: " + message);
}

Credits

1NH21CE061 Sonu Kumar

1NH21CE061 Sonu Kumar

1 project • 0 followers

Comments