#include "Wire.h" #include #include // you need to download and install this dht DHT; #define DHT11_PIN 7 #define DS1307_I2C_ADDRESS 0x68 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int zx ; int zy; char tx[20]; int txcounter; byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setup() { Serial.begin(9600); byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; Wire.begin(); // AMEND IF YOUR USING A DIFFERENT LCD SCREEN // lcd.begin(16, 2); lcd.print("hello, world!"); delay(500); } void loop() { byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; String s, m, d, mth, h; int chk = DHT.read11(DHT11_PIN); getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); if (second < 10) { s = "0" + String(second); } else { s = String(second); } if (minute < 10) { m = "0" + String(minute); } else { m = String(minute); } h = String(hour); if (dayOfMonth < 10) { d = "0" + String(dayOfMonth); } else { d = String(dayOfMonth); } if (month < 10) { mth = "0" + String(month); } else { mth = String(month); } char* days[] = { "NA", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; lcd.clear(); // JUMP TO CENTER ON A 16X2 SCREEN // lcd.setCursor(4,0); // CHANGE THE FOLLOWING TO SET THE DATE IN TO YOUR PREFERED ORDER // lcd.print(h + ":" + m + ":" + s); // NEXT LINE, 1 SPACE IN FROM THE LEFT // lcd.setCursor(0,1); // PREFIX THE 20 AS THE RTC CHIP ONLY USES 2 DIGITS FOR THE YEAR // if(zy++ > 1){ zy = 0; zx++; if(zx>2)zx =0; } // zx = 1; if( zx == 0) lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year); if( zx == 1){ lcd.print("Temp = "+ String(DHT.temperature) + "." ); } if( zx == 2){ lcd.print("Humidity= "+ String(DHT.humidity)); } while(Serial.available()){ char c = Serial.read(); tx[txcounter++] = c; if(txcounter > 18)txcounter = 0; if(c == 't'){ lcd.clear(); lcd.setCursor(0,0); lcd.print("Got t"); txcounter = 0; } if(c == '*'){ tx[txcounter] = 0; // terminate sting lcd.clear(); lcd.setCursor(0,0); lcd.print(String(tx)); int i = 0; Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.write(((tx[0]&15)<<4)+(tx[1]& 15) ); //(decToBcd(second)); Wire.write(((tx[2]&15)<<4)+(tx[3]& 15)); //(decToBcd(minute)); Wire.write(((tx[4]&15)<<4)+(tx[5]& 15)); //(decToBcd(hour)); Wire.write(((tx[6]&15)<<4)+(tx[7]& 15)); //(decToBcd(dayOfWeek)); Wire.write(((tx[8]&15)<<4)+(tx[9]& 15)); //(decToBcd(dayOfMonth)); Wire.write(((tx[10]&15)<<4)+(tx[11]& 15)); //(decToBcd(month)); Wire.write(((tx[12]&15)<<4)+(tx[13]& 15)); //(decToBcd(year)); Wire.endTransmission(); // example string t00160203080616* } } delay(1000); // Wait 1 second }