MasteringOpenCV / code

Code for the book "Mastering OpenCV with Practical Computer Vision Projects" by Packt Publishing 2012.
Other
2.71k stars 1.64k forks source link

Please help to solve error in this Arduino code #112

Closed sri415 closed 11 months ago

sri415 commented 11 months ago

include // Pulse Sensor library

include // Library for GSM module

include <TinyGPS++.h> // Library for GPS module

include // Library for I2C LCD

define HEARTBEAT_PIN A0 // Connect the heartbeat sensor to this pin

define SOUND_PIN A1 // Connect the sound sensor to this pin

define GSM_RX_PIN 10 // GSM module RX pin

define GSM_TX_PIN 11 // GSM module TX pin

// Create objects for the required sensors PulseSensorPlayground pulseSensor; SoftwareSerial gsmSerial(GSM_RX_PIN, GSM_TX_PIN); TinyGPSPlus gps; LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address if necessary

// Set threshold values for heartbeat and sound sensors const int heartbeatThreshold = 90; // Adjust this value as needed const int soundThreshold = 500; // Adjust this value as needed

// Variables to store sensor readings int heartbeatValue = 0; int soundValue = 0;

// Variables to manage emergency alerts bool emergencyAlertSent = false; unsigned long lastAlertTime = 0; const unsigned long alertCooldown = 30000; // Minimum time between consecutive alerts (30 seconds)

void sendSMS(const char recipient, const char message) { gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text delay(100); gsmSerial.print("AT+CMGS=\""); gsmSerial.print(recipient); gsmSerial.println("\""); delay(100); gsmSerial.print(message); delay(100); gsmSerial.write(26); // End SMS message delay(1000); }

// Function to send an emergency alert via GSM void sendEmergencyAlert() { if (!emergencyAlertSent && (millis() - lastAlertTime >= alertCooldown)) { // Get child's location if (gps.location.isValid() && gps.location.age() < 2000) { float latitude = gps.location.lat(); float longitude = gps.location.lng();

  // Send the emergency SMS with the Google Maps link
  char googleMapsUrl[100];
  snprintf(googleMapsUrl, sizeof(googleMapsUrl),
           "https://www.google.com/maps?q=%.6f,%.6f", latitude, longitude);

  char smsMessage[160];
  snprintf(smsMessage, sizeof(smsMessage),
           "Emergency! Child needs help! Check their location: %s", googleMapsUrl);

  sendSMS("+919676475713", smsMessage); // Replace with the recipient's phone number
  emergencyAlertSent = true;
  lastAlertTime = millis();
}

} }

void setup() { lcd.begin(16, 2); lcd.print("Heartbeat: ");

pulseSensor.setup(HEARTBEAT_PIN); gsmSerial.begin(9600); // Initialize other sensors and modules (GPS, GSM) // Add necessary setup for GPS module, if required }

void loop() { pulseSensor.update(); // Update the pulse sensor data soundValue = analogRead(SOUND_PIN); // Read sound sensor data

// Check for incoming SMS if (gsmSerial.available()) { String sms = gsmSerial.readStringUntil('\n'); sms.trim(); // Check if the received SMS contains the "LOC" command if (sms.equalsIgnoreCase("LOC")) { // Send the child's location to the sender's phone number if (gps.location.isValid() && gps.location.age() < 2000) { float latitude = gps.location.lat(); float longitude = gps.location.lng(); char googleMapsUrl[100]; snprintf(googleMapsUrl, sizeof(googleMapsUrl), "https://www.google.com/maps?q=%.6f,%.6f", latitude, longitude);

    char smsMessage[160];
    snprintf(smsMessage, sizeof(smsMessage),
             "Child's Location: %s", googleMapsUrl);
    sendSMS("+919676475713", smsMessage); // Replace with the sender's phone number
  } else {
    // GPS data is not valid or too old
    sendSMS("+919676475713", "Unable to get child's location.");
  }
}

}

// Check for emergency conditions and send alerts if (pulseSensor.sawNewSample()) { heartbeatValue = pulseSensor.getBeatsPerMinute(); if (heartbeatValue > heartbeatThreshold) { sendEmergencyAlert(); } }

if (soundValue > soundThreshold) { sendEmergencyAlert(); }

// Reset emergency alert flag if conditions are back to normal if (emergencyAlertSent && heartbeatValue <= heartbeatThreshold && soundValue <= soundThreshold) { emergencyAlertSent = false; }

// Display the heartbeat value on the LCD lcd.setCursor(11, 0); // Move the cursor to the 12th column of the first row lcd.print(heartbeatValue); lcd.print(" bpm"); }

BloodAxe commented 11 months ago

Please withstand from posting issues to unrelated repositories. You may get best luck on SO or chat gpt.