Advertisement
pleasedontcode

Temperature Monitor rev_01

Sep 20th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Temperature Monitor
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-20 09:58:11
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* afficher la température sur un tft LCD 3.5" ainsi */
  21.     /* qu'un curseur pour générer une alarme température */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <DS18B20.h>    // https://github.com/matmunk/DS18B20
  26. #include <TFT_eSPI.h>  // TFT library for 3.5" LCD
  27. #include <SPI.h>       // SPI library for communication with TFT
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t DS18B20_DQ_PIN = 4;  // Changed the variable name to a valid identifier
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Create an instance of the DS18B20 class, passing the digital pin number as a parameter
  38. DS18B20 ds(DS18B20_DQ_PIN);
  39.  
  40. // Create an instance of the TFT display
  41. TFT_eSPI tft = TFT_eSPI(); // Invoke library
  42.  
  43. /****** ALARM THRESHOLDS *****/
  44. #define LOW_ALARM 20
  45. #define HIGH_ALARM 25
  46.  
  47. void setup(void)
  48. {
  49.     // Initialize serial communication for debugging
  50.     Serial.begin(9600);
  51.    
  52.     // Set the pin mode for the DS18B20 data pin
  53.     pinMode(DS18B20_DQ_PIN, INPUT);
  54.    
  55.     // Initialize the TFT display
  56.     tft.init();
  57.     tft.setRotation(1); // Set the rotation of the display
  58.     tft.fillScreen(TFT_BLACK); // Clear the screen with black color
  59.     tft.setTextColor(TFT_WHITE); // Set text color to white
  60.     tft.setTextSize(2); // Set text size
  61.  
  62.     // Define the address of the DS18B20 sensor (replace with your actual sensor address)
  63.     uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
  64.    
  65.     // Select the DS18B20 sensor using its address
  66.     if (ds.select(address)) {
  67.         // Set the alarm thresholds for the temperature
  68.         ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  69.     } else {
  70.         Serial.println("Device not found!");
  71.     }
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // Define the address of the DS18B20 sensor (should match the address used in setup)
  77.     uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
  78.    
  79.     // Check if the DS18B20 sensor is selected
  80.     if (ds.select(address)) {
  81.         // Get the current temperature
  82.         float temperature = ds.getTempC();
  83.        
  84.         // Display the temperature on the TFT
  85.         tft.fillRect(0, 0, 240, 40, TFT_BLACK); // Clear previous temperature display
  86.         tft.setCursor(10, 10); // Set cursor position
  87.         tft.print("Temperature: ");
  88.         tft.print(temperature);
  89.         tft.println(" C");
  90.        
  91.         // Check if the temperature alarm has been triggered
  92.         if (ds.hasAlarm()) {
  93.             // Print a warning message with the current temperature
  94.             Serial.print("Warning! Temperature is ");
  95.             Serial.print(temperature);
  96.             Serial.println(" C");
  97.            
  98.             // Display alarm message on the TFT
  99.             tft.setTextColor(TFT_RED); // Set text color to red for alarm
  100.             tft.setCursor(10, 30); // Set cursor position for alarm message
  101.             tft.print("ALARM! Temp: ");
  102.             tft.print(temperature);
  103.             tft.println(" C");
  104.         }
  105.     } else {
  106.         Serial.println("Device not found!");
  107.     }
  108.  
  109.     // Wait for 10 seconds before the next loop iteration
  110.     delay(10000);
  111. }
  112.  
  113. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement