You are on page 1of 7

#include <Adafruit_SSD1306.

h>

#define OLED_Address 0x3C // 0x3C device address of I2C OLED. Few other OLED has 0x3D

Adafruit_SSD1306 oled(128, 64); // create our screen object setting resolution to 128x64

#include <Adafruit_MLX90614.h>

#define buzzer 2

int a = 0;

int lasta = 0;

int lastb = 0;

int LastTime = 0;

int ThisTime;

bool BPMTiming = false;

bool BeatComplete = false;

int BPM = 0;

#define UpperThreshold 560

#define LowerThreshold 530

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

//Adafruit_SSD1306 display(OLED_RESET);

float suhu_tubuh, suhu_ruangan;

float Xsuhu_ruangan ; \

float Xsuhu_tubuh ;

int XBPMval ;

int z = 0;

bool hold = false;


#define INTERVAL_MESSAGE1 20

#define INTERVAL_MESSAGE2 500

unsigned long time_1 = 0;

unsigned long time_2 = 0;

void print_time(unsigned long time_millis);

void setup() {

Serial.begin(9600);

pinMode(3, INPUT_PULLUP);

pinMode(buzzer, OUTPUT);

Wire.begin();

mlx.begin();

oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);

oled.clearDisplay();

oled.setTextSize(2);

void loop()

suhu_ruangan = mlx.readAmbientTempC();

suhu_tubuh = mlx.readObjectTempC();
if (millis() > time_1 + INTERVAL_MESSAGE1) {

time_1 = millis();

if (z <= 10 && hold == false)

if (a > 127)

oled.clearDisplay();

a = 0;

lasta = a;

ThisTime = millis();

int value = analogRead(0);

oled.setTextColor(WHITE);

int b = 60 - (value / 16);

oled.writeLine(lasta, lastb, a, b, WHITE);

lastb = b;

lasta = a;

if (value > UpperThreshold)

if (BeatComplete)

BPM = ThisTime - LastTime;


BPM = int(60 / (float(BPM) / 1000));

BPMTiming = false;

BeatComplete = false;

tone(8, 1000, 250);

if (BPMTiming == false)

LastTime = millis();

BPMTiming = true;

if ((value < LowerThreshold) & (BPMTiming))

BeatComplete = true;

if (BPM <= 60) BPM = 60;

if (BPM >= 100) BPM = 100;

oled.writeFillRect(0, 50, 128, 16, BLACK);

oled.setCursor(0, 50);

oled.print("BPM:");

oled.print(BPM);

oled.display();

a++;

}
if (z > 10 && z <= 20 && hold == false)

oled.clearDisplay();

oled.setTextColor(WHITE);

oled.setTextSize(2);

oled.setCursor(30, 35);

oled.print(suhu_tubuh);

oled.print(" C");

oled.setTextSize(2);

oled.setCursor(0, 2);

oled.print("Suhu : ");

if (hold == true)

oled.clearDisplay();

oled.setTextColor(WHITE);

oled.setTextSize(2);

oled.setCursor(15, 2);

oled.print(" RESULT ");


oled.setTextSize(1);

oled.setCursor(0, 25);

oled.print("Suhu Tubuh: ");

oled.print(Xsuhu_tubuh);

oled.print(" C");

oled.setCursor(0, 35);

oled.print("Heart Rate: ");

oled.print(XBPMval);

oled.print(" BPM");

oled.display();

if (millis() > time_2 + INTERVAL_MESSAGE2) {

time_2 = millis();

z++;

if (z > 20)

oled.clearDisplay();

z = 0;

if (digitalRead(3) == 0)

digitalWrite(buzzer, HIGH);
delay(75);

digitalWrite(buzzer, LOW);

z = 0;

oled.clearDisplay();

Xsuhu_ruangan = suhu_ruangan;

Xsuhu_tubuh = suhu_tubuh;

XBPMval = BPM;

hold = !hold;

Serial.print("BPM : ");

Serial.print(BPM);

Serial.print("\t Suhu Ruangan = ");

Serial.print(suhu_ruangan);

Serial.print(" *C\t Suhu Tubuh = ");

Serial.print(suhu_tubuh);

Serial.print(" *C");

Serial.print('\t');

Serial.print(z);

Serial.println('\t');

You might also like