Advertisement
Hitamputih07

aryafix

Apr 16th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. #define USE_ARDUINO_INTERRUPTS true
  2. #include <Adafruit_MLX90614.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
  6.  
  7.  
  8.  
  9. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  10. #define SCREEN_HEIGHT 64 // OLED display height, in pixels
  11. #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
  12. #define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
  13. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  14.  
  15. Adafruit_MLX90614 mlx = Adafruit_MLX90614();
  16.  
  17. double temp_amb;
  18. double temp_obj;
  19. double calibration = 2.36;
  20. const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
  21. const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
  22. int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
  23. // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
  24. // Otherwise leave the default "550" value.
  25.  
  26. PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
  27.  
  28.  
  29. void setup()
  30. {
  31. Serial.begin(9600);
  32. mlx.begin(); //Initialize MLX90614
  33. display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  34.  
  35. // Double-check the "pulseSensor" object was created and "began" seeing a signal.
  36. if (pulseSensor.begin()) {
  37. Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
  38. }
  39. //Serial.println("Temperature Sensor MLX90614");
  40. pulseSensor.analogInput(PulseWire);
  41. pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
  42. pulseSensor.setThreshold(Threshold);
  43.  
  44.  
  45. display.clearDisplay();
  46. display.setCursor(25,15);
  47. display.setTextSize(1);
  48. display.setTextColor(WHITE);
  49. display.println(" Thermometer");
  50. display.setCursor(25,35);
  51. display.setTextSize(1);
  52. display.print("Initializing");
  53. display.display();
  54. delay(2500);
  55.  
  56.  
  57.  
  58. }
  59.  
  60. void loop(){
  61. //Reading room temperature and object temp
  62. //for reading Fahrenheit values, use
  63. //mlx.readAmbientTempF() , mlx.readObjectTempF() )
  64. temp_amb = mlx.readAmbientTempC();
  65. temp_obj = mlx.readObjectTempC();
  66.  
  67. int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
  68. // "myBPM" hold this BPM value now.
  69.  
  70. if (pulseSensor.sawStartOfBeat()) // Constantly test to see if "a beat happened".
  71. // Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
  72. Serial.print("BPM: "); // Print phrase "BPM: "
  73. Serial.println(myBPM); // Print the value inside of myBPM.
  74.  
  75. //Serial Monitor
  76. Serial.print("Room Temp = ");
  77. Serial.println(temp_amb);
  78. Serial.print("Object temp = ");
  79. Serial.println(temp_obj);
  80.  
  81. display.clearDisplay();
  82.  
  83. display.setCursor(0,10);
  84. display.setTextSize(1);
  85. display.print("BPM: ");
  86. display.print(myBPM);
  87.  
  88. display.setCursor(0,20);
  89. display.setTextSize(1);
  90. display.print("Ruangan: ");
  91. display.print(temp_amb);
  92. display.print((char)247);
  93. display.print("C");
  94.  
  95. display.setCursor(0,40);
  96. display.setTextSize(1);
  97. display.print("Suhu: ");
  98. display.print(temp_obj + calibration()>37;
  99. display.print((char)247);
  100. display.print("C");
  101. delay(2000);
  102. display.display();
  103.  
  104. //delay(1000);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement