Advertisement
Hitamputih07

GY906

Apr 11th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Wire.h> // I2C
  3. #include <WiFi.h>
  4. #include <WiFiClient.h>
  5. #include <SparkFunMLX90614.h> // SparkFunMLX90614 Arduino library
  6. #include <Adafruit_GFX.h>
  7. #include <Adafruit_SSD1306.h>
  8. #include <BlynkSimpleEsp32.h>
  9.  
  10. const char* ssid = "Hidden";
  11. const char* password = "medan1234";
  12. // You should get Auth Token in the Blynk App.
  13. // Go to the Project Settings (nut icon).
  14. char auth[] = " ufro3stBt5jJ3OFcOc4Gg3hJZ-zgXxVp";
  15.  
  16. IRTherm therm; // Create an IRTherm object to interact with throughout
  17.  
  18. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  19. #define SCREEN_HEIGHT 64 // OLED display height, in pixels
  20.  
  21. // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  22. #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
  23. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  24.  
  25.  
  26. #define BLYNK_PRINT Serial
  27. BlynkTimer timer;// This function sends Arduino's up time every second to the Virtual Pins
  28.  
  29.  
  30. void setup()
  31. {
  32. Serial.begin(9600);
  33. Blynk.begin(auth, ssid, password);
  34. display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
  35. therm.begin(); // Initialize thermal IR sensor
  36. therm.setUnit(TEMP_F); // Set the library's units to Farenheit
  37. // Alternatively, TEMP_F can be replaced with TEMP_C for Celsius orTEMP_K for Kelvin.
  38. timer.setInterval(1000L, sendSensor);
  39. }
  40.  
  41. void loop() {
  42. // Call therm.read() to read object and ambient temperatures from the sensor.
  43. if (therm.read()) // On success, read() will return 1, on fail 0.
  44. {
  45. printTobject();
  46. printTobjecTval();
  47. unit1();
  48. printTambient();
  49. printTambienTval();
  50. unit2();
  51. delay(500);
  52. }
  53. display.display();
  54. Blynk.run();
  55. timer.run();
  56. }
  57. //Display data to OLED
  58. void printTobject()
  59. {
  60. display.clearDisplay();
  61. display.setTextSize(1);
  62. display.setTextColor(WHITE);
  63. display.setCursor(5,0);
  64. display.println("Object: ");
  65. }
  66.  
  67. void printTobjecTval()
  68. {
  69. display.setTextSize(1);
  70. display.setTextColor(WHITE);
  71. display.setCursor(60,0);
  72. display.println(therm.object());
  73. }
  74.  
  75. void unit1()
  76. {
  77. display.setTextSize(1);
  78. display.setTextColor(WHITE);
  79. display.setCursor(100,0);
  80. display.println("F");
  81. }
  82.  
  83. void printTambient()
  84. {
  85. display.setTextSize(1);
  86. display.setTextColor(WHITE);
  87. display.setCursor(5,20);
  88. display.println("Ambient:");
  89. }
  90.  
  91. void printTambienTval()
  92. {
  93. display.setTextSize(1);
  94. display.setTextColor(WHITE);
  95. display.setCursor(60,20);
  96. display.println(therm.ambient());
  97. }
  98. void unit2()
  99. {
  100. display.setTextSize(1);
  101. display.setTextColor(WHITE);
  102. display.setCursor(100,20);
  103. display.println("F");
  104. }
  105. //Display data to Blynk
  106. void sendSensor()
  107. {
  108. Blynk.virtualWrite(V0,therm.object());
  109. Blynk.virtualWrite(V1, therm.ambient());
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement