/* Outside transmitter * * * * Send data via RF 433MHz to receiver * * CONNECTIONS * RF 433MHz: VCC -> 5V GND -> GND Data -> D12 * Si7021: VCC -> 5V GND -> GND SCL -> SCL SDA -> SDA */ #include #include #include "SPI.h" // Is it really neaded for BMP280 SPI? #include "Adafruit_Si7021.h" #include LiquidCrystal_I2C lcd(0x3F,20,4); // Replace 0x3F with your LCD's address #include #include #include #include "RTClib.h" RTC_DS3231 rtc; #include "Adafruit_Si7021.h" Adafruit_Si7021 sensor = Adafruit_Si7021(); //Constants const int buttonPin = 5; // for connection: https://www.arduino.cc/en/Tutorial/StateChangeDetection const int led = 13; //pin for LED const int LightResistor = A3; const int minReading = 0; // min value for light resistor const int maxReading = 700; // max value for light resistor byte address = 0x00; // for the potentiometer int CS= 10; char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"}; //Variables int buttonState1 = 0; int buttonState2 = 0; int flag = 1; int Light = 0; float tempIn = 0; float humidIn = 0; float heatindexIn = 0; int16_t humidity_ = 0; int16_t temp_ = 0; int16_t heat_index_ = 0; float humidityOut = 0; float tempOut = 0; float heatindexOut = 0; float tempInMax = 10; float tempInMin = 50; float tempOutMax = -20; float tempOutMin = 50; float humidInMax = -20; float humidInMin = 100; float humidityOutMax = -20; float humidityOutMin = 100; char MsgReceived[21]; // an array to store the data that need to be sent // For state change: // Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button void setup() { Serial.begin(9600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (rtc.lostPower()) { Serial.println("RTC lost power, lets set the time!"); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2016, 12, 8, 20, 20, 0)); rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // sets the RTC to the date & time this sketch was compiled } lcd.init(); // initialize the lcd lcd.backlight(); lcd.setBacklight(200); // 0-255 http://playground.arduino.cc/Code/LCDAPI sensor.begin(); //Si7021 //Input or output? pinMode(led, OUTPUT); pinMode(buttonPin, INPUT); pinMode (CS, OUTPUT); // For the potentiometer SPI.begin(); // VirtualWire // Bits per sec vw_setup(2000); // set pin for connect receiver module vw_set_rx_pin(11); // Start the receiver PLL running vw_rx_start(); } void loop(){ DateTime now = rtc.now(); // RECEIVE VALUES from RF uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; //Taking the data from Outside if (vw_get_message(buf, &buflen)) { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); int i; // Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { // Fill Msg Char array with corresponding // chars from buffer. MsgReceived[i] = char(buf[i]); } sscanf(MsgReceived, "%d,%d",&humidity_, &temp_); // Converts a string to an array, %d: integer value for (i = 0; i < buflen; i++) { Serial.print(MsgReceived[i]); } // Calculate Max/Mix outside values if (tempOutMax < tempOut) tempOutMax = tempOut; if (now.hour() == 0 & 0 <= now.minute() <= 5) tempOutMax = -20; if (humidityOutMax < humidityOut) humidityOutMax = humidityOut; if (now.hour() == 0 & 0 <= now.minute() <= 5) humidityOutMax = -20; if (tempOutMin > (float)temp_ / 100.0) tempOutMin = (float)temp_ / 100.0; if (now.hour() == 0 & 0 <= now.minute() <= 5) tempOutMin = 50; if (humidityOutMin > (float)humidity_ / 100.0) humidityOutMin = (float)humidity_ / 100.0; if (now.hour() == 0 & 0 <= now.minute() <= 5) humidityOutMin = 100; // Convert outside values to decimals humidityOut = (float)humidity_ / 100.0; tempOut = (float)temp_ / 100.0; heatindexOut = (float)heat_index_ / 100.0; } // Take Si7021 Readings float lasttemp = tempIn; tempIn = sensor.readTemperature(); humidIn = sensor.readHumidity(); // Calculate MAX/MIN Values for the day // Calculate Max/Mix outside values if (tempInMax < tempIn) tempInMax = tempIn; if (humidInMax < humidIn) humidInMax = humidIn; if (tempInMin > tempIn) tempInMin = tempIn; if (humidInMin > humidIn) humidInMin = humidIn; Serial.println(tempOutMax); Serial.println(humidityOutMax); Serial.println(tempOutMin); Serial.println(humidityOutMin); // Button State Change see: https://www.arduino.cc/en/Tutorial/StateChangeDetection buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: flag++; lcd.init(); if (flag == 4) { flag = 1; Serial.println(flag); } } else { // if the current state is LOW then the button // wend from on to off: Serial.println("No button press"); } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; // LCD Menu choice switch (flag) { case 1: menu1(tempIn, humidIn, tempOut, humidityOut); break; case 2: menu2(tempInMax, tempInMin, humidInMax, humidInMin); break; case 3: menu3 (tempOutMax, tempOutMin, humidityOutMax, humidityOutMin); break; } // Re-initialise LCD every 3 minutes to avoid strange time numbers unsigned long startTime = 0; unsigned long interval = 180000; //3 mins } void menu1(float tIn, float hIn, float tOut, float hOut) { DateTime now = rtc.now(); lcd.setCursor(0,0); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); lcd.setCursor(4,0); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); if (now.hour()<10) { lcd.setCursor(15,0); lcd.print("0"); lcd.setCursor(16,0); lcd.print(now.hour(), DEC); } if (now.hour()>=10) { lcd.setCursor(15,0); lcd.print(now.hour(), DEC); } lcd.setCursor(17,0); lcd.print(':'); if (now.minute()<10) { lcd.setCursor(18,0); lcd.print("0"); lcd.setCursor(19,0); lcd.print(now.minute(), DEC); } if (now.minute()>=10) { lcd.setCursor(18,0); lcd.print(now.minute(), DEC); } lcd.setCursor(6,1); lcd.print("TEMP HUMI"); lcd.setCursor(0,2); lcd.print("IN :"); lcd.setCursor(0,3); lcd.print("OUT:"); lcd.setCursor(10,2); lcd.print("C"); lcd.setCursor(10,3); lcd.print("C"); lcd.setCursor(17,2); lcd.print("%"); lcd.setCursor(17,3); lcd.print("%"); lcd.setCursor(5,2); lcd.print(tIn,2); // two decimal places lcd.setCursor(12,2); lcd.print(hIn,2); lcd.setCursor(5,3); lcd.print(tOut); lcd.setCursor(12,3); lcd.print(hOut); return(tIn,hIn,tOut,hOut); delay(3000); } void menu2(float tInMax, float tInMin, float hInMax, float hInMin) { DateTime now = rtc.now(); lcd.setCursor(0,0); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); lcd.setCursor(4,0); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); //lcd.setCursor(15,0); //lcd.print(now.hour(), DEC); if (now.hour()<10) { lcd.setCursor(15,0); lcd.print("0"); lcd.setCursor(16,0); lcd.print(now.hour(), DEC); } if (now.hour()>=10) { lcd.setCursor(15,0); lcd.print(now.hour(), DEC); } lcd.setCursor(17,0); lcd.print(':'); if (now.minute()<10) { lcd.setCursor(18,0); lcd.print("0"); lcd.setCursor(19,0); lcd.print(now.minute(), DEC); } if (now.minute()>=10) { lcd.setCursor(18,0); lcd.print(now.minute(), DEC); } lcd.setCursor(1,1); lcd.print("ROOM MAX MIN"); lcd.setCursor(0,2); lcd.print("Temp: "); lcd.setCursor(0,3); lcd.print("Humi: "); lcd.setCursor(6,2); lcd.print(tInMax,2); lcd.setCursor(13,2); lcd.print(tInMin,2); lcd.setCursor(6,3); lcd.print(hInMax,2); lcd.setCursor(13,3); lcd.print(hInMin,2); return (tInMax,tInMin,hInMax,hInMin); delay(3000); } void menu3 (float tOutMax, float tOutMin, float hOutMax, float hOutMin){ DateTime now = rtc.now(); lcd.setCursor(0,0); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); lcd.setCursor(4,0); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); if (now.hour()<10) { lcd.setCursor(15,0); lcd.print("0"); lcd.setCursor(16,0); lcd.print(now.hour(), DEC); } if (now.hour()>=10) { lcd.setCursor(15,0); lcd.print(now.hour(), DEC); } lcd.setCursor(17,0); lcd.print(':'); if (now.minute()<10) { lcd.setCursor(18,0); lcd.print("0"); lcd.setCursor(19,0); lcd.print(now.minute(), DEC); } if (now.minute()>=10) { lcd.setCursor(18,0); lcd.print(now.minute(), DEC); } lcd.setCursor(1,1); lcd.print("OUT MAX MIN"); lcd.setCursor(0,2); lcd.print("Temp: "); lcd.setCursor(0,3); lcd.print("Humi: "); lcd.setCursor(6,2); lcd.print(tOutMax,2); lcd.setCursor(13,2); lcd.print(tOutMin,2); lcd.setCursor(6,3); lcd.print(hOutMax,2); lcd.setCursor(13,3); lcd.print(hOutMin,2); return (tOutMax,tOutMin,hOutMax,hOutMin); delay(3000); } void MaxValue (float Value, float MaxValue) { DateTime now = rtc.now(); if (Value>MaxValue) MaxValue = Value; if (now.hour() == 0 & now.minute() == 0) MaxValue = -20; return (Value, MaxValue); } void MinValue (float Value, float MinValue) { DateTime now = rtc.now(); if (Value