Advertisement
pleasedontcode

Temperature Display rev_02

Dec 9th, 2023
79
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 compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-09 14:43:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* At the transmitter arduino side nrf24l01 module */
  21.     /* with DS18B20 waterproof transmitter should send */
  22.     /* data to the Receiver side with lcd display */
  23.     /* Receiver should receive and display it on LCD */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <Wire.h>
  29. #include <DS18B20.h>
  30. #include <LiquidCrystal_I2C.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup();
  34. void loop();
  35. void printTemperature();
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t DS18B20_DQ_PIN = 2;
  39.  
  40. /***** DEFINITION OF I2C PINS *****/
  41. const uint8_t LCD_I2C_PIN_SDA = A4;
  42. const uint8_t LCD_I2C_PIN_SCL = A5;
  43. const uint8_t LCD_I2C_SLAVE_ADDRESS = 0x27;
  44.  
  45. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  46. DS18B20 ds(DS18B20_DQ_PIN);
  47. LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 16, 2);
  48.  
  49. void setup()
  50. {
  51.   // Initialize the digital input pin for DS18B20
  52.   pinMode(DS18B20_DQ_PIN, INPUT);
  53.  
  54.   // Initialize the I2C communication
  55.   Wire.begin();
  56.  
  57.   // Initialize the LCD display
  58.   lcd.begin(16, 2);
  59.   lcd.backlight();
  60.  
  61.   // Print initial message on LCD
  62.   lcd.print("Receiver - NRF24L01");
  63.   lcd.setCursor(0, 1);
  64.   lcd.print("Waiting for data...");
  65. }
  66.  
  67. void loop()
  68. {
  69.   // Read temperature from DS18B20
  70.   float temperature = ds.getTempC();
  71.  
  72.   // Display temperature on LCD
  73.   lcd.clear();
  74.   lcd.setCursor(0, 0);
  75.   lcd.print("Temperature: ");
  76.   lcd.print(temperature);
  77.   lcd.print(" C");
  78.  
  79.   delay(2000);
  80. }
  81.  
  82. void printTemperature()
  83. {
  84.   // Read temperature from DS18B20
  85.   float temperature = ds.getTempC();
  86.  
  87.   // Print temperature via serial
  88.   Serial.print("Temperature: ");
  89.   Serial.print(temperature);
  90.   Serial.println(" C");
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement