Advertisement
pleasedontcode

Temperature Bluetooth rev_29

Oct 3rd, 2024
68
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 NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-03 11:25:57
  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>    // LiquidCrystal library for controlling LCDs
  30. #include <DS18B20.h>          // Library for DS18B20 temperature sensor
  31. #include <DHT.h>              // Library for DHT temperature and humidity sensors
  32. #include <BluetoothSerial.h>  // Library for Bluetooth communication
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void updateOutputs();
  38. void readTemperatureAndSend(); // Function to read temperature and send via Bluetooth
  39.  
  40. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  41. const uint8_t temp_DS18B20_DQ_PIN_D8 = 8;
  42. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t display_LCD1602_RS_PIN_D2 = 2;
  46. const uint8_t display_LCD1602_E_PIN_D3 = 3;
  47. const uint8_t display_LCD1602_D4_PIN_D4 = 4;
  48. const uint8_t display_LCD1602_D5_PIN_D5 = 5;
  49. const uint8_t display_LCD1602_D6_PIN_D6 = 6;
  50. const uint8_t display_LCD1602_D7_PIN_D7 = 7;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. 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);
  54. DS18B20 tempSensor(temp_DS18B20_DQ_PIN_D8);
  55. DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); // Assuming DHT22 sensor
  56. BluetoothSerial bluetoothSerial; // Bluetooth Serial object
  57.  
  58. void setup(void)
  59. {
  60.     // Initialize the LCD
  61.     lcd.begin(16, 2); // Set up the LCD's number of columns and rows
  62.     lcd.print("Initializing...");
  63.  
  64.     // Initialize the temperature sensors
  65.     tempSensor.begin();
  66.     dht.begin();
  67.  
  68.     // Initialize Bluetooth
  69.     bluetoothSerial.begin("ESP32_Bluetooth"); // Name of the Bluetooth device
  70.  
  71.     // Set pin modes
  72.     pinMode(temp_DS18B20_DQ_PIN_D8, INPUT);
  73.     pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP);
  74.     pinMode(display_LCD1602_RS_PIN_D2, OUTPUT);
  75.     pinMode(display_LCD1602_E_PIN_D3, OUTPUT);
  76.     pinMode(display_LCD1602_D4_PIN_D4, OUTPUT);
  77.     pinMode(display_LCD1602_D5_PIN_D5, OUTPUT);
  78.     pinMode(display_LCD1602_D6_PIN_D6, OUTPUT);
  79.     pinMode(display_LCD1602_D7_PIN_D7, OUTPUT);
  80. }
  81.  
  82. void loop(void)
  83. {
  84.     // Update outputs and read temperature
  85.     updateOutputs();
  86.     readTemperatureAndSend(); // Read temperature and send it via Bluetooth
  87.     delay(2000); // Delay for readability
  88. }
  89.  
  90. void updateOutputs()
  91. {
  92.     // Update the LCD display with a message
  93.     lcd.clear();
  94.     lcd.setCursor(0, 0);
  95.     lcd.print("BLE Data:");
  96.     // Here you would typically display received BLE data
  97. }
  98.  
  99. void readTemperatureAndSend()
  100. {
  101.     // Read temperature from DS18B20
  102.     float temperature = tempSensor.GetTemperature<float>();
  103.     // Read humidity from DHT22
  104.     float humidity = dht.readHumidity();
  105.    
  106.     // Display temperature and humidity on the LCD
  107.     lcd.setCursor(0, 1);
  108.     lcd.print("Temp: ");
  109.     lcd.print(temperature);
  110.     lcd.print("C");
  111.  
  112.     // Send temperature and humidity via Bluetooth
  113.     bluetoothSerial.print("Temperature: ");
  114.     bluetoothSerial.print(temperature);
  115.     bluetoothSerial.print("C, Humidity: ");
  116.     bluetoothSerial.print(humidity);
  117.     bluetoothSerial.println("%");
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement