Advertisement
pleasedontcode

**Sensor Display** rev_40

Oct 3rd, 2024
91
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: **Sensor Display**
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-03 14:45:25
  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 <DHT.h> // https://github.com/adafruit/DHT-sensor-library
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t display_LCD1602_RS_PIN_D2 = 2;
  42. const uint8_t display_LCD1602_E_PIN_D3 = 3;
  43. const uint8_t display_LCD1602_D4_PIN_D4 = 4;
  44. const uint8_t display_LCD1602_D5_PIN_D5 = 5;
  45. const uint8_t display_LCD1602_D6_PIN_D6 = 6;
  46. const uint8_t display_LCD1602_D7_PIN_D7 = 7;
  47.  
  48. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  49. bool display_LCD1602_RS_PIN_D2_rawData = 0;
  50. bool display_LCD1602_E_PIN_D3_rawData = 0;
  51. bool display_LCD1602_D4_PIN_D4_rawData = 0;
  52. bool display_LCD1602_D5_PIN_D5_rawData = 0;
  53. bool display_LCD1602_D6_PIN_D6_rawData = 0;
  54. bool display_LCD1602_D7_PIN_D7_rawData = 0;
  55.  
  56. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  57. float display_LCD1602_RS_PIN_D2_phyData = 0.0;
  58. float display_LCD1602_E_PIN_D3_phyData = 0.0;
  59. float display_LCD1602_D4_PIN_D4_phyData = 0.0;
  60. float display_LCD1602_D5_PIN_D5_phyData = 0.0;
  61. float display_LCD1602_D6_PIN_D6_phyData = 0.0;
  62. float display_LCD1602_D7_PIN_D7_phyData = 0.0;
  63.  
  64. // Create an instance of the LiquidCrystal library
  65. 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);
  66.  
  67. // Create an instance of the DHT sensor
  68. DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); // Assuming DHT22 sensor
  69.  
  70. void setup(void)
  71. {
  72.     // Initialize the LCD
  73.     lcd.begin(16, 2);
  74.     lcd.print("Initializing...");
  75.  
  76.     // Initialize the DHT sensor
  77.     dht.begin();
  78.  
  79.     // Initialize Bluetooth (Assuming you have a Bluetooth library for this)
  80.     // Bluetooth.begin(); // Uncomment and replace with actual Bluetooth initialization code
  81. }
  82.  
  83. void loop(void)
  84. {
  85.     // Read temperature and humidity
  86.     float temperature = dht.readTemperature(); // Read temperature in Celsius
  87.     float humidity = dht.readHumidity(); // Read humidity
  88.  
  89.     // Check if any reads failed and exit early (to try again).
  90.     if (isnan(temperature) || isnan(humidity)) {
  91.         lcd.clear();
  92.         lcd.print("Failed to read!");
  93.         return;
  94.     }
  95.  
  96.     // Display temperature and humidity on the LCD
  97.     lcd.clear();
  98.     lcd.setCursor(0, 0);
  99.     lcd.print("Temp: ");
  100.     lcd.print(temperature);
  101.     lcd.print(" C");
  102.     lcd.setCursor(0, 1);
  103.     lcd.print("Humidity: ");
  104.     lcd.print(humidity);
  105.     lcd.print(" %");
  106.  
  107.     // Send temperature data via Bluetooth
  108.     // Bluetooth.print("Temperature: "); // Uncomment and replace with actual Bluetooth sending code
  109.     // Bluetooth.print(temperature); // Uncomment and replace with actual Bluetooth sending code
  110.     // Bluetooth.print(" C"); // Uncomment and replace with actual Bluetooth sending code
  111.  
  112.     delay(2000); // Wait for 2 seconds before the next loop
  113. }
  114.  
  115. void updateOutputs()
  116. {
  117.     digitalWrite(display_LCD1602_RS_PIN_D2, display_LCD1602_RS_PIN_D2_rawData);
  118.     digitalWrite(display_LCD1602_E_PIN_D3, display_LCD1602_E_PIN_D3_rawData);
  119.     digitalWrite(display_LCD1602_D4_PIN_D4, display_LCD1602_D4_PIN_D4_rawData);
  120.     digitalWrite(display_LCD1602_D5_PIN_D5, display_LCD1602_D5_PIN_D5_rawData);
  121.     digitalWrite(display_LCD1602_D6_PIN_D6, display_LCD1602_D6_PIN_D6_rawData);
  122.     digitalWrite(display_LCD1602_D7_PIN_D7, display_LCD1602_D7_PIN_D7_rawData);
  123. }
  124.  
  125. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement