Advertisement
pleasedontcode

Temperature Monitor rev_25

Oct 3rd, 2024
56
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: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-03 10:37:09
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Initialize internal Bluetooth device as master, */
  21.     /* receive BLE data, and show it on a 16x2 LCD using */
  22.     /* LiquidCrystal library for Arduino. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* read temperature and send it via bluetooth. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LiquidCrystal.h>  //https://github.com/arduino-libraries/LiquidCrystal
  30. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  31. #include <BluetoothSerial.h> // Include Bluetooth library
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs();
  37. void readTemperatureAndSend(); // Function to read temperature and send via Bluetooth
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t temp_DS18B20_DQ_PIN_D8 = 8;
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t display_LCD1602_RS_PIN_D2 = 2;
  44. const uint8_t display_LCD1602_E_PIN_D3 = 3;
  45. const uint8_t display_LCD1602_D4_PIN_D4 = 4;
  46. const uint8_t display_LCD1602_D5_PIN_D5 = 5;
  47. const uint8_t display_LCD1602_D6_PIN_D6 = 6;
  48. const uint8_t display_LCD1602_D7_PIN_D7 = 7;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. // LCD instance
  52. LiquidCrystal lcd(display_LCD1602_RS_PIN_D2, display_LCD1602_E_PIN_D3, display_LCD1602_D4_PIN_D4, display_LCD1602_D5_PIN_D5, display_LCD1602_D6_PIN_D6, display_LCD1602_D7_PIN_D7);
  53. // DS18B20 instance
  54. DS18B20 tempSensor(temp_DS18B20_DQ_PIN_D8);
  55. // Bluetooth instance
  56. BluetoothSerial SerialBT;
  57.  
  58. void setup(void)
  59. {
  60.     // Initialize the LCD
  61.     lcd.begin(16, 2);
  62.     lcd.print("Initializing...");
  63.  
  64.     // Initialize Bluetooth
  65.     SerialBT.begin("ESP32_Bluetooth"); // Bluetooth device name
  66.     lcd.setCursor(0, 1);
  67.     lcd.print("Bluetooth Ready");
  68.  
  69.     pinMode(temp_DS18B20_DQ_PIN_D8, INPUT);
  70.     pinMode(display_LCD1602_RS_PIN_D2, OUTPUT);
  71.     pinMode(display_LCD1602_E_PIN_D3, OUTPUT);
  72.     pinMode(display_LCD1602_D4_PIN_D4, OUTPUT);
  73.     pinMode(display_LCD1602_D5_PIN_D5, OUTPUT);
  74.     pinMode(display_LCD1602_D6_PIN_D6, OUTPUT);
  75.     pinMode(display_LCD1602_D7_PIN_D7, OUTPUT);
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // Read temperature and send it via Bluetooth
  81.     readTemperatureAndSend();
  82.  
  83.     // Refresh output data
  84.     updateOutputs();
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.     // Update LCD display with temperature data
  90.     float temperature = tempSensor.getTempC(); // Get temperature in Celsius
  91.     lcd.clear();
  92.     lcd.print("Temp: ");
  93.     lcd.print(temperature);
  94.     lcd.print(" C");
  95. }
  96.  
  97. void readTemperatureAndSend()
  98. {
  99.     float temperature = tempSensor.getTempC(); // Get temperature in Celsius
  100.     SerialBT.println(temperature); // Send temperature via Bluetooth
  101. }
  102.  
  103. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement