Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

IOT-PROJECT

I done my mini project in the Third year of my college and this project give a hands on experience about ESP32 Microcontroller ,various Sensors and intergrating the both Hardware and Software together in Arduino IDE Platform and the software tool is Thingspeak IOT platform. This is source code we used in our project.

#include <Wire.h> #include <MAX30100_PulseOximeter.h> #include <WiFi.h> #include <HTTPClient.h>

const char* ssid = "Samsung"; const char* password = "qwertyuiop";

String serverName = "http://api.thingspeak.com/update?api_key=IXOZNPYDD79XXYZ2";

// Sensor Pins const int ecgPin = 34; // ECG analog output const int xPin = 32; // Accelerometer X-axis const int yPin = 33; // Accelerometer Y-axis const int zPin = 35; // Accelerometer Z-axis

PulseOximeter pox; uint32_t tsLastReport = 0;

int bit_ecgValue = 0; int ecgValue = 0; float xValue = 0, yValue = 0, zValue = 0; float bit_xValue = 0, bit_yValue = 0, bit_zValue = 0; float movement = 0; float heartRate = 0, spO2 = 0;

void setup() { Serial.begin(115200);

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

if (!pox.begin()) { Serial.println("MAX30100 initialization failed."); while (1);
}

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

Wire.begin(21, 22); // SDA (GPIO 21), SCL (GPIO 22)

pinMode(xPin, INPUT); pinMode(yPin, INPUT); pinMode(zPin, INPUT); }

void loop() {

pox.update();

// Read sensor data heartRate = pox.getHeartRate(); spO2 = pox.getSpO2();

// Read ECG sensor value ecgValue = analogRead(ecgPin); bit_ecgValue = ecgValue * 1023 / 4096;

// Read accelerometer values (MEMS) xValue = analogRead(xPin); yValue = analogRead(yPin); zValue = analogRead(zPin);

bit_xValue = xValue * 1023 / 4096; bit_yValue = yValue * 1023 / 4096; bit_zValue = zValue * 1023 / 4096;

// Print the values to the Serial Monitor Serial.println("-------------------------------------------------------------"); Serial.print("Heart Rate: "); Serial.print(heartRate); Serial.println(" bpm"); Serial.print("SpO2: "); Serial.print(spO2); Serial.println(" %"); Serial.print("ECG: "); Serial.println(bit_ecgValue); Serial.print(" X value: "); Serial.println(bit_xValue); Serial.print(" Y value: "); Serial.println(bit_yValue); Serial.print(" Z value: "); Serial.println(bit_zValue);

Serial.println("-------------------------------------------------------------");

if (millis() - tsLastReport > 30000) { tsLastReport = millis();

String serverPath = serverName + "&field1=" + String(heartRate) +
                    "&field2=" + String(spO2) +
                    "&field3=" + String(bit_ecgValue) +
                    "&field4=" + String(bit_xValue) +  // Sending X-axis accelerometer value
                    "&field5=" + String(bit_yValue) +  // Sending Y-axis accelerometer value
                    "&field6=" + String(bit_zValue);   // Sending Z-axis accelerometer value

// Send the data via HTTP
HTTPClient http;
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();

if (httpResponseCode > 0)
{
  Serial.print("Data sent. Response code: ");
  Serial.println(httpResponseCode);
} else {
  Serial.print("Error sending data: ");
  Serial.println(httpResponseCode);
}

http.end();

}

delay(100); // Delay to avoid overwhelming the system }

About

I done my mini project in the Third year of my college and this project give a hands on experience about ESP32 Microcontroller ,various intergrating the both Hardware and Software.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors