Advertisement
pleasedontcode

**Temperature Display** rev_32

Oct 3rd, 2024
34
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 Display**
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-03 13:18:29
  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 <DHT.h> // https://github.com/adafruit/DHT-sensor-library
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs(void);
  37. void readTemperatureAndSend(void;
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t temp_DS18B20_DQ_PIN_D8 = 8;
  41. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  42.  
  43. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  44. const uint8_t display_LCD1602_RS_PIN_D2 = 2;
  45. const uint8_t display_LCD1602_E_PIN_D3 = 3;
  46. const uint8_t display_LCD1602_D4_PIN_D4 = 4;
  47. const uint8_t display_LCD1602_D5_PIN_D5 = 5;
  48. const uint8_t display_LCD1602_D6_PIN_D6 = 6;
  49. const uint8_t display_LCD1602_D7_PIN_D7 = 7;
  50.  
  51. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  52. bool display_LCD1602_RS_PIN_D2_rawData = 0;
  53. bool display_LCD1602_E_PIN_D3_rawData = 0;
  54. bool display_LCD1602_D4_PIN_D4_rawData = 0;
  55. bool display_LCD1602_D5_PIN_D5_rawData = 0;
  56. bool display_LCD1602_D6_PIN_D6_rawData = 0;
  57. bool display_LCD1602_D7_PIN_D7_rawData = 0;
  58.  
  59. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  60. float display_LCD1602_RS_PIN_D2_phyData = 0.0;
  61. float display_LCD1602_E_PIN_D3_phyData = 0.0;
  62. float display_LCD1602_D4_PIN_D4_phyData = 0.0;
  63. float display_LCD1602_D5_PIN_D5_phyData = 0.0;
  64. float display_LCD1602_D6_PIN_D6_phyData = 0.0;
  65. float display_LCD1602_D7_PIN_D7_phyData = 0.0;
  66.  
  67. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  68. // Create an instance of the LiquidCrystal library
  69. LiquidCrystal lcd(display_LCD1602_RS_PIN_D2, display_LCD1602_E_PIN_D3,
  70.                   display_LCD1602_D4_PIN_D4, display_LCD1602_D5_PIN_D5,
  71.                   display_LCD1602_D6_PIN_D6, display_LCD1602_D7_PIN_D7);
  72.  
  73. // Create an instance of the DHT sensor
  74. DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22);
  75.  
  76. // Create an instance of the DS18B20 sensor
  77. DS18B20 tempSensor;
  78.  
  79. // Setup function to initialize the components
  80. void setup(void)
  81. {
  82.     // Initialize the LCD
  83.     lcd.begin(16, 2);
  84.     lcd.clear();
  85.     lcd.print("Initializing...");
  86.  
  87.     // Initialize the DHT sensor
  88.     dht.begin();
  89.  
  90.     // Initialize the DS18B20 sensor
  91.     tempSensor.Update();
  92.  
  93.     // Set pin modes
  94.     pinMode(temp_DS18B20_DQ_PIN_D8, INPUT);
  95.     pinMode(display_LCD1602_RS_PIN_D2, OUTPUT);
  96.     pinMode(display_LCD1602_E_PIN_D3, OUTPUT);
  97.     pinMode(display_LCD1602_D4_PIN_D4, OUTPUT);
  98.     pinMode(display_LCD1602_D5_PIN_D5, OUTPUT);
  99.     pinMode(display_LCD1602_D6_PIN_D6, OUTPUT);
  100.     pinMode(display_LCD1602_D7_PIN_D7, OUTPUT);
  101. }
  102.  
  103. // Main loop function
  104. void loop(void)
  105. {
  106.     // Refresh output data
  107.     updateOutputs();
  108.     readTemperatureAndSend(); // Read temperature and send via Bluetooth
  109.     delay(2000); // Delay for readability
  110. }
  111.  
  112. // Function to update outputs
  113. void updateOutputs()
  114. {
  115.     digitalWrite(display_LCD1602_RS_PIN_D2, display_LCD1602_RS_PIN_D2_rawData);
  116.     digitalWrite(display_LCD1602_E_PIN_D3, display_LCD1602_E_PIN_D3_rawData);
  117.     digitalWrite(display_LCD1602_D4_PIN_D4, display_LCD1602_D4_PIN_D4_rawData);
  118.     digitalWrite(display_LCD1602_D5_PIN_D5, display_LCD1602_D5_PIN_D5_rawData);
  119.     digitalWrite(display_LCD1602_D6_PIN_D6, display_LCD1602_D6_PIN_D6_rawData);
  120.     digitalWrite(display_LCD1602_D7_PIN_D7, display_LCD1602_D7_PIN_D7_rawData);
  121. }
  122.  
  123. // Function to read temperature and send it via Bluetooth
  124. void readTemperatureAndSend()
  125. {
  126.     // Read temperature from DHT sensor
  127.     float temperature = dht.readTemperature();
  128.     if (isnan(temperature)) {
  129.         lcd.print("Failed to read");
  130.     } else {
  131.         lcd.clear();
  132.         lcd.print("Temp: ");
  133.         lcd.print(temperature);
  134.         lcd.print(" C");
  135.        
  136.         // Here you would send the temperature via Bluetooth
  137.         // For example: BluetoothSerial.write(temperature);
  138.     }
  139. }
  140.  
  141. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement