/********* 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 Bluetooth
- Source Code NOT compiled for: Arduino Nano ESP32
- Source Code created on: 2024-10-03 11:25:57
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Initialize internal Bluetooth device as master, */
/* receive BLE data, and show it on a 16x2 LCD using */
/* LiquidCrystal library for Arduino. */
/****** SYSTEM REQUIREMENT 2 *****/
/* read temperature and send it via bluetooth. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include // LiquidCrystal library for controlling LCDs
#include // Library for DS18B20 temperature sensor
#include // Library for DHT temperature and humidity sensors
#include // Library for Bluetooth communication
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs();
void readTemperatureAndSend(); // Function to read temperature and send via Bluetooth
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t temp_DS18B20_DQ_PIN_D8 = 8;
const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t display_LCD1602_RS_PIN_D2 = 2;
const uint8_t display_LCD1602_E_PIN_D3 = 3;
const uint8_t display_LCD1602_D4_PIN_D4 = 4;
const uint8_t display_LCD1602_D5_PIN_D5 = 5;
const uint8_t display_LCD1602_D6_PIN_D6 = 6;
const uint8_t display_LCD1602_D7_PIN_D7 = 7;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
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);
DS18B20 tempSensor(temp_DS18B20_DQ_PIN_D8);
DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); // Assuming DHT22 sensor
BluetoothSerial bluetoothSerial; // Bluetooth Serial object
void setup(void)
{
// Initialize the LCD
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Initializing...");
// Initialize the temperature sensors
tempSensor.begin();
dht.begin();
// Initialize Bluetooth
bluetoothSerial.begin("ESP32_Bluetooth"); // Name of the Bluetooth device
// Set pin modes
pinMode(temp_DS18B20_DQ_PIN_D8, INPUT);
pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP);
pinMode(display_LCD1602_RS_PIN_D2, OUTPUT);
pinMode(display_LCD1602_E_PIN_D3, OUTPUT);
pinMode(display_LCD1602_D4_PIN_D4, OUTPUT);
pinMode(display_LCD1602_D5_PIN_D5, OUTPUT);
pinMode(display_LCD1602_D6_PIN_D6, OUTPUT);
pinMode(display_LCD1602_D7_PIN_D7, OUTPUT);
}
void loop(void)
{
// Update outputs and read temperature
updateOutputs();
readTemperatureAndSend(); // Read temperature and send it via Bluetooth
delay(2000); // Delay for readability
}
void updateOutputs()
{
// Update the LCD display with a message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("BLE Data:");
// Here you would typically display received BLE data
}
void readTemperatureAndSend()
{
// Read temperature from DS18B20
float temperature = tempSensor.GetTemperature();
// Read humidity from DHT22
float humidity = dht.readHumidity();
// Display temperature and humidity on the LCD
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print("C");
// Send temperature and humidity via Bluetooth
bluetoothSerial.print("Temperature: ");
bluetoothSerial.print(temperature);
bluetoothSerial.print("C, Humidity: ");
bluetoothSerial.print(humidity);
bluetoothSerial.println("%");
}