The Mediated Extensions of Self
GMDP-566
Creative Technology
weblink click here!
Esp32, Pulse Sensor, Arduino
3 Weeks, Individual Work
This code is an example of an Internet of Things (IoT) application that monitors a person's heart rate using a Pulse Sensor connected to an ESP32 microcontroller. The heart rate data is then sent to the Adafruit IO cloud platform, which can be used for remote monitoring, data visualization, or triggering alerts and actions based on the received heart rate data.
In the context of IoT, this application can be considered a part of a larger ecosystem, where the ESP32 device acts as a sensor node that collects heart rate data from the Pulse Sensor and sends it to a cloud platform, Adafruit IO in this case, for further processing and analysis.By leveraging the IoT infrastructure, the heart rate data can be made available to authorized users or applications, enabling remote monitoring and real-time analytics. This can be useful in various scenarios, such as healthcare, fitness tracking, or wellness monitoring.
The IoT aspect of this application lies in its ability to connect the physical world (the person's heart rate) with the digital world (the Adafruit IO cloud platform) through the ESP32 microcontroller, which serves as a bridge between the sensor and the internet. This allows for seamless integration with other connected devices or applications, offering the potential for expanded functionality and a richer user experience.
The IoT aspect of this application lies in its ability to connect the physical world (the person's heart rate) with the digital world (the Adafruit IO cloud platform) through the ESP32 microcontroller, which serves as a bridge between the sensor and the internet. This allows for seamless integration with other connected devices or applications, offering the potential for expanded functionality and a richer user experience.



/************************** Configuration ***********************************/
#include "config.h"
/************************ Code Starts Here **********************************/
// Variables
#define pulsePin A2 // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 2
unsigned long myTime;
int LED = 13; // The on-board Esp32 LED
int current_value = 0;
int last_value = -1;
int heartRate = 0;
int beatTimes = 0; // Determine which Signal to "count as a beat", and which to ingore.
//if state bigger than threshold, detect state change
bool lastState = false;
bool currentState = false;
int Threshold = 2500;
// set up the 'pulse' feed
AdafruitIO_Feed *pulse = io.feed("pulse");
void setup() {
pinMode(LED,OUTPUT);
pinMode(pulsePin, INPUT); // Sets the trigPin as an Output
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
// connect to io.adafruit.com target="_blank">adafruit.com
Serial.print target="_blank">Serial.print target="_blank">Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run target="_blank">io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
myTime = millis();
//detect change of states
if(myTime % 10000 < 100 && beatTimes > 2){
heartRate = (beatTimes % 10000) *6;
Serial.print("sending -> ");
Serial.println(heartRate);
//filter data
if(heartRate < 130 && heartRate > 50){
pulse->save(heartRate);
}
beatTimes = 0;
}
current_value = analogRead(pulsePin); // Read the current PulseSensor's value.
// If the signal is above "2500", then "turn-on" Esp32 LED.
// if current value > threshold and last_value < threshold : detected a transition, beatTimes ++
if(current_value > Threshold){
currentState = true;
digitalWrite(LED,HIGH);
if ( currentState && !lastState ){
beatTimes ++;
}
}else{
currentState = false;
digitalWrite(LED,LOW);
}
lastState = currentState;
last_value = current_value;
//Serial.println(beatTimes);
delay(10);
}