Hello
Im trying to combine 2 codes for more than few days and still cant figure it out.
Here are this 2 codes. One is for RTC and other is for temperature and moisture. I would like to change what is on display like:
Temp: 30
Mosture: 30%
and after 3 sec it would change to:
Clock
Date
I guess its not hard but im new at this and i would ask for help
Thanks!
Temp_moisture:
//We'll start by adding our libraries
#include <LiquidCrystal.h>
#include <SimpleDHT.h>
//Declaring digital pin no 6 as the dht11 data pin
int pinDHT11 = 7;
SimpleDHT11 dht11;
//Declaring the lcd pins
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// Don't forget to choose 9600 at the port screen
Serial.begin(9600);
//Telling our lcd to start up
lcd.begin(16, 2);
}
void loop() {
//These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface
Serial.println("=================================");
Serial.println("DHT11 readings...");
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
//This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("No reading , err="); Serial.println(err);delay(1000);
return;
}
Serial.print("Readings: ");
Serial.print((int)temperature); Serial.print(" Celcius, ");
Serial.print((int)humidity); Serial.println(" %");
//Telling our lcd to refresh itself every 0.75 seconds
lcd.clear();
//Choosing the first line and row
lcd.setCursor(0,0);
//Typing Temp: to the first line starting from the first row
lcd.print("Temp: ");
//Typing the temperature readings after "Temp: "
lcd.print((int)temperature);
//Choosing the second line and first row
lcd.setCursor(0,1);
//Typing Humidity(%): to the second line starting from the first row
lcd.print("Vlaga: ");
//Typing the humidity readings after "Humidity(%): "
lcd.print((int)humidity);
lcd.print("%");
delay(750);
}
RTC:
#include "Wire.h"
#include <LiquidCrystal.h>
#define PCF8563address 0x51
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
byte bcdToDec(byte value)
{
return ((value / 16) * 10 + value % 16);
}
byte decToBcd(byte value){
return (value / 10 * 16 + value % 10);
}
void setPCF8563()
// this sets the time and date to the PCF8563
{
Wire.beginTransmission(PCF8563address);
Wire.write(0x02);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
void readPCF8563()
// this gets the time and date from the PCF8563
{
Wire.beginTransmission(PCF8563address);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(PCF8563address, 7);
second = bcdToDec(Wire.read() & B01111111); // remove VL error bit
minute = bcdToDec(Wire.read() & B01111111); // remove unwanted bits from MSB
hour = bcdToDec(Wire.read() & B00111111);
dayOfMonth = bcdToDec(Wire.read() & B00111111);
dayOfWeek = bcdToDec(Wire.read() & B00000111);
month = bcdToDec(Wire.read() & B00011111); // remove century bit, 1999 is over
year = bcdToDec(Wire.read());
}
void setup()
{
Wire.begin();
Serial.begin(9600);
// change the following to set your initial time
second = 0;
minute = 28;
hour = 9;
dayOfWeek = 2;
dayOfMonth = 13;
month = 8;
year = 13;
// comment out the next line and upload again to set and keep the time from resetting every reset
setPCF8563();
}
void loop()
{
readPCF8563();
lcd.print(days[dayOfWeek]);
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/20");
lcd.print(year, DEC);
lcd.print(" - ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute < 10)
{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10)
{
Serial.print("0");
}
Serial.println(second, DEC);
delay(1000);
}
and this is what i was working on and its not working...
#include <LiquidCrystal.h>
#include "Wire.h"
#define PCF8563address 0x51
#include <SimpleDHT.h>
//Declaring digital pin no 6 as the dht11 data pin
int pinDHT11 = 7;
SimpleDHT11 dht11;
//Declaring the lcd pins
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
byte bcdToDec(byte value)
{
return ((value / 16) * 10 + value % 16);
}
byte decToBcd(byte value){
return (value / 10 * 16 + value % 10);
}
///////////////////////////////////////////////////////////////////////////////
void setPCF8563()
// this sets the time and date to the PCF8563
{
Wire.beginTransmission(PCF8563address);
Wire.write(0x02);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
void readPCF8563()
// this gets the time and date from the PCF8563
{
Wire.beginTransmission(PCF8563address);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(PCF8563address, 7);
second = bcdToDec(Wire.read() & B01111111); // remove VL error bit
minute = bcdToDec(Wire.read() & B01111111); // remove unwanted bits from MSB
hour = bcdToDec(Wire.read() & B00111111);
dayOfMonth = bcdToDec(Wire.read() & B00111111);
dayOfWeek = bcdToDec(Wire.read() & B00000111);
month = bcdToDec(Wire.read() & B00011111); // remove century bit, 1999 is over
year = bcdToDec(Wire.read());
}
////////////////////////////////////////////////////////////////////////////////////
void cas(){
readPCF8563();
lcd.clear();
lcd.print(days[dayOfWeek]);
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print(".");
lcd.print(month, DEC);
lcd.print(".20");
lcd.print(year, DEC);
lcd.print(" - ");
lcd.print(hour, DEC);
lcd.print(":");
}
void setup()
{
lcd.begin(16, 2);
Wire.begin();
Serial.begin(9600);
// change the following to set your initial time
second = 0;
minute = 28;
hour = 9;
dayOfWeek = 2;
dayOfMonth = 13;
month = 8;
year = 13;
// comment out the next line and upload again to set and keep the time from resetting every reset
setPCF8563();
}
void loop() {
//These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface
Serial.println("=================================");
Serial.println("DHT11 readings...");
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
//This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("No reading , err="); Serial.println(err);delay(1000);
return;
}
Serial.print("Readings: ");
Serial.print((int)temperature); Serial.print(" Celcius, ");
Serial.print((int)humidity); Serial.println(" %");
//Telling our lcd to refresh itself every 0.75 seconds
lcd.clear();
//Choosing the first line and row
lcd.setCursor(0,0);
//Typing Temp: to the first line starting from the first row
lcd.print("Temp: ");
//Typing the temperature readings after "Temp: "
lcd.print((int)temperature);
//Choosing the second line and first row
lcd.setCursor(0,1);
//Typing Humidity(%): to the second line starting from the first row
lcd.print("Vlaga: ");
//Typing the humidity readings after "Humidity(%): "
lcd.print((int)humidity);
lcd.print("%");
cas();
delay(750);
}