/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Temperature Display" - Source Code NOT compiled for: ESP32 DevKit V1 - Source Code created on: 2024-07-18 09:04:33 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Display temperature readings from a DS18B20 sensor */ /* on an LCD1602 I2C display using ESP32. The DS18B20 */ /* is connected to GPIO 4, and the LCD uses I2C pins */ /* SDA (GPIO 21) and SCL (GPIO 22) with address 0x27. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include // https://github.com/matmunk/DS18B20 #include // https://github.com/offcircuit/LCDIC2 /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Temp_DS18B20_DQ_PIN_D4 = 4; /***** DEFINITION OF I2C PINS *****/ const uint8_t LCD_I2C_LCD1602I2C_I2C_PIN_SDA_D21 = 21; const uint8_t LCD_I2C_LCD1602I2C_I2C_PIN_SCL_D22 = 22; const uint8_t LCD_I2C_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // Typically 0x27 for LCD1602 /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ DS18B20 ds(Temp_DS18B20_DQ_PIN_D4); // Initialize the DS18B20 sensor with the data pin LCDIC2 lcd(LCD_I2C_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize the LCD with I2C address, width, and height void setup(void) { // put your setup code here, to run once: Serial.begin(9600); // Initialize the I2C communication for the LCD Wire.begin(LCD_I2C_LCD1602I2C_I2C_PIN_SDA_D21, LCD_I2C_LCD1602I2C_I2C_PIN_SCL_D22); // Initialize the LCD lcd.begin(); lcd.print("Hello, World!"); // Check if the DS18B20 sensor is connected uint8_t address[8]; if (ds.selectNext(address)) { Serial.println("DS18B20 device found!"); } else { Serial.println("DS18B20 device not found!"); } } void loop(void) { // put your main code here, to run repeatedly: uint8_t address[8]; if (ds.selectNext(address)) { float temp = ds.getTempC(); if (!isnan(temp)) { Serial.print("Temperature: "); Serial.print(temp); Serial.println(" C"); lcd.setCursor(0, 1); // Move cursor to the second line lcd.print("Temp: "); lcd.print(temp); lcd.print(" C"); } else { Serial.println("Failed to read temperature!"); } } else { Serial.println("DS18B20 device not valid!"); } delay(10000); } /* END CODE */