Advertisement
pleasedontcode

Temperature Display rev_20

Oct 2nd, 2024
53
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-02 23:10:54
  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 <Adafruit_SSD1306.h> // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
  32. #include <U8g2_for_Adafruit_GFX.h> // https://github.com/olikraus/U8g2_for_Adafruit_GFX
  33. #include <DHT.h>              // https://github.com/adafruit/DHT-sensor-library
  34. #include "BluetoothController.h" // Include the header for the LCD controller
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. void updateOutputs();
  40. void sendTemperatureViaBluetooth(float temperature);
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t temperatureSensor_DHT22_DOUT_PIN = 9; // DHT22 sensor pin
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. // Create instances of the display and U8g2 objects
  47. Adafruit_SSD1306 display(OLED_RESET); // OLED display instance
  48. U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; // U8g2 instance
  49. LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // LCD instance
  50. DHT dht(temperatureSensor_DHT22_DOUT_PIN, DHT22); // DHT sensor instance
  51.  
  52. void setup(void)
  53. {
  54.     Serial.begin(9600); // Initialize serial communication
  55.     pinMode(temperatureSensor_DHT22_DOUT_PIN, INPUT_PULLUP);
  56.  
  57.     initializeLCD(); // Initialize the LCD display
  58.     setupDS18B20(); // Setup DS18B20 sensor
  59.     dht.begin(); // Initialize the DHT sensor
  60.  
  61.     display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Initialize the OLED display
  62.     display.display(); // Clear the display
  63.     delay(2000);
  64.     display.clearDisplay();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     updateOutputs(); // Refresh output data
  70.     checkTemperature(); // Check temperature from DS18B20
  71. }
  72.  
  73. void updateOutputs()
  74. {
  75.     // Example of updating LCD display
  76.     lcd.setCursor(0, 0);
  77.     lcd.print("Temp: ");
  78.     float temperature = dht.readTemperature(); // Read temperature from DHT sensor
  79.     lcd.print(temperature);
  80.     lcd.print(" C");
  81.  
  82.     // Send temperature via Bluetooth
  83.     sendTemperatureViaBluetooth(temperature);
  84. }
  85.  
  86. void sendTemperatureViaBluetooth(float temperature)
  87. {
  88.     // Send the temperature data over Bluetooth
  89.     Serial.print("Temperature: ");
  90.     Serial.println(temperature);
  91. }
  92.  
  93. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement