Heart Rate With Custom IoT

2,251

20

5

Posted

Introduction: Heart Rate With Custom IoT

In this example we will measure the heartbeat with the light provides a Led and a photo-transistor. The phototransistor detects the light that passes our finger from LED. The oxygen in our blood will prevent light comes the photo-transistor and from there will draw the information to detect heartbeat.

Step 1: Neccesary Components

→ 1 CustomIoT board

→ 1 Red Led

→ 1 Green Led

→ 1 photo-transistor

Step 2: Code

Load the attached code on the board.

We read the sensor value via pin A0 and calculate the current value measured by this and previous one, giving more importance to the previous (alpha = 0.75). We make the difference to see if this value has changed a lot and we send it to flicker green led to the same frequency as the heartbeat.

int ledPin = 4;
int sensorPin = A0;
<br>double alpha = 0.75;
int period = 20;
double change = 0.0;

void <strong>setup</strong>()            
{
  pinMode(ledPin,OUTPUT);
  <strong>Serial</strong>.begin(115200);
}

void <strong>loop</strong>()             
{
    static double oldValue =0;
    static double oldChange =0;
    
    int rawValue =analogRead(sensorPin);
    double value =alpha * oldValue + (1 - alpha) * rawValue;
    change = value-oldValue;
    digitalWrite(ledPin, change);
    oldValue = value;
    delay(period);
}





Step 3: Hardware Connections

We employed a module like you see in the picture below (sensor + red Led). Connect the output of this sensor with A0 pin from our board CustomIoT. The green LED will be connected to pin 4 from the board.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    5 Comments

    Hi!

    You need Custom IoT board and arduino IDE for upload the code.

    Regards.

    I don't know how to load the code,could you elaborate it?

    Thanks for sharing this!