Advertisement
pleasedontcode

Temperature Bluetooth rev_21

Oct 2nd, 2024
39
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 Bluetooth
  13.     - Source Code compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-02 23:16:55
  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 LIBRARIES CLASS INSTANCES*****/
  43. // The instances are already defined in BluetoothController.h, so we do not redefine them here.
  44.  
  45. void setup(void)
  46. {
  47.     Serial.begin(9600); // Initialize serial communication
  48.     pinMode(temperatureSensor_DHT22_DOUT_PIN, INPUT_PULLUP);
  49.  
  50.     initializeLCD(); // Initialize the LCD display
  51.     setupDS18B20(); // Setup DS18B20 sensor
  52.     dht.begin(); // Initialize the DHT sensor
  53.  
  54.     display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Initialize the OLED display
  55.     display.display(); // Clear the display
  56.     delay(2000);
  57.     display.clearDisplay();
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     updateOutputs(); // Refresh output data
  63.     checkTemperature(); // Check temperature from DS18B20
  64. }
  65.  
  66. void updateOutputs()
  67. {
  68.     // Example of updating LCD display
  69.     lcd.setCursor(0, 0);
  70.     lcd.print("Temp: ");
  71.     float temperature = dht.readTemperature(); // Read temperature from DHT sensor
  72.     lcd.print(temperature);
  73.     lcd.print(" C");
  74.  
  75.     // Send temperature via Bluetooth
  76.     sendTemperatureViaBluetooth(temperature);
  77. }
  78.  
  79. void sendTemperatureViaBluetooth(float temperature)
  80. {
  81.     // Send the temperature data over Bluetooth
  82.     Serial.print("Temperature: ");
  83.     Serial.println(temperature);
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement