#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Wire.h>
#include <RTClib.h>
#include <Relay.h>
//Bluetooth Connection
#define rxPin 11
#define txPin 10
SoftwareSerial bluetooth = SoftwareSerial(rxPin,txPin); //rx | tx
//SoftwareSerial bluetooth(10, 11); // RX, TX pins on Arduino
#define RELAY_ON 0
#define RELAY_OFF 1
#define RELAY_1 4
char data = 0;
// Set the LCD address (usually 0x27 or 0x3F)
#define LCD_ADDRESS 0x27
// Set the LCD dimensions (columns x rows)
#define LCD_COLUMNS 16
#define LCD_ROWS 2
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
// Set the DHT pin
#define DHTPIN 2
// Uncomment one of the following based on your DHT sensor type
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
//const int timeout = 10000;
RTC_DS3231 rtc;
int Date;
//const int timeout = 10000; //define timeout of 10 sec
//char menuOption = 0;
//long time0;
int relay = 3; // Plug the relay into Digital Pin 3
void setup() {
Serial.begin(9600);
lcd.println("start");
bluetooth.begin(9600); // Default baud rate for most HC-06 modules
// Bluetooth Connection Setup
// pinMode(keys,OUTPUT);
//digitalWrite(keys,HIGH);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
//----------------------------
//LCD
lcd.begin(LCD_COLUMNS, LCD_ROWS);
lcd.backlight(); // Uncomment this line if your LCD has a backlight
dht.begin();
rtc.begin();
if (!rtc.begin()) {
lcd.println("Couldn't find RTC");
//while (1);
}
else if (rtc.lostPower()) {
lcd.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
// Read from Bluetooth module
if (bluetooth.available()) {
char receivedChar = bluetooth.read();
bluetooth.print(receivedChar);
}
// Read from Serial Monitor and send to Bluetooth module
if (bluetooth.available()) {
char sendChar = bluetooth.read();
bluetooth.write(sendChar);
}
lcd.clear(); // Clear the LCD screen
// Print a message
lcd.setCursor(0, 0); // Set the cursor to the first column and first row
lcd.print("Hello");
//delay(2000); // Wait for 2 seconds
// Print another message
//lcd.clear();
lcd.setCursor(0, 1); // Set the cursor to the first column and second row
lcd.print("Everyone! ");
delay(2000); // Wait for 2 seconds
// delay(2000); // Wait for 2 seconds between readings
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if the reading was successful
if (!isnan(humidity) && !isnan(temperature)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humidity:");
lcd.print(humidity);
lcd.setCursor(0, 1);
lcd.print(F("Temp: "));
lcd.print((char)223);
lcd.println(temperature);
delay(5000);
}
else {
lcd.println("Failed to read from DHT sensor");}
DateTime now = rtc.now();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Date:");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Time:");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println(" ");
delay(5000);
// PC Fan 12V - Test Code
// The PC Fan will turn on for 2000ms and off for 4000ms (4 sec)
PCFan.on(); // 1. turns on
delay(2000); // 2. waits 2000 milliseconds (2 sec).
PCFan.off();// 3. turns off
delay(4000); // 4. waits 4000 milliseconds (4 sec).
}