Close

Tapo circuit COMPLETED! + Tested + Programmed

A project log for AutoWats - A Plant in Every Home!

The PRACTICAL Solution to Global Warming

Siddhant ChoyalSiddhant Choyal 06/12/2017 at 10:470 Comments

//-----------------------------------------------------------------------------------------------------
//                                            LIBRARIES
//-----------------------------------------------------------------------------------------------------

#include <VirtualWire.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

//-----------------------------------------------------------------------------------------------------
//                                            VARIABLES
//-----------------------------------------------------------------------------------------------------
const int led=13;
const int receive_pin = 2;
char temperatureChar[10];
char humidityChar[10];

//-----------------------------------------------------------------------------------------------------
//                                          DATA STRUCTURE
//-----------------------------------------------------------------------------------------------------
struct package                                      //Struct Type Name
{
  int temperature = 0;                          //Struct Member                        
  int humidity = 0;                             //Struct Member
  int soil =0;
};
int SV = 40;
int WT = 22;
int smVal = 0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   //LCD Structure

typedef struct package Package;                     //Define name of
Package data;                                       //Object name


//-----------------------------------------------------------------------------------------------------
//                                              Signs
//-----------------------------------------------------------------------------------------------------

byte droplet[8] = //icon for droplet
{
  B00100,
  B00100,
  B01010,
  B01010,
  B10001,
  B10001,
  B10001,
  B01110,
};

byte thermometer[8] = //icon for thermometer
{
  B00100,
  B01010,
  B01010,
  B01110,
  B01110,
  B11111,
  B11111,
  B01110
};

byte WTermo[8] = {
  B11111,
  B10001,
  B10001,
  B11111,
  B11111,
  B00100,
  B00100,
  B00100
};

//-----------------------------------------------------------------------------------------------------
//                                              SETUP
//-----------------------------------------------------------------------------------------------------

void setup()
{
    
Serial.begin(9600);                                 //start serial comms for output
    
    pinMode(led,OUTPUT);                            //LED set for output
    pinMode(SV, OUTPUT);
    pinMode(WT,INPUT);
    vw_set_rx_pin(receive_pin);                     //initialize receiver on pin D12
    vw_setup(500);                                  // Bits per sec
    vw_rx_start();                                  // Start the receiver PLL running

  lcd.begin(16,2);
  lcd.backlight(); // finish with backlight on  
  lcd.createChar(1, thermometer);
  lcd.createChar(2, droplet);
  lcd.createChar(3, WTermo);
  lcd.clear(); // clear the screen

}


//-----------------------------------------------------------------------------------------------------
//                                            MAIN LOOP
//-----------------------------------------------------------------------------------------------------
void loop()
{
    uint8_t buf[sizeof(data)];                      //unsigned int 8 bit called buf with size specified in Struct member data
    uint8_t buflen = sizeof(data);                  //unsigned int 8 bit called buflen with size specified in Struct member data

if (vw_have_message())                              //Check for activity 
  {
    smVal = map(data.soil, 0, 1023, 0, 255);
    int WTemp = digitalRead(WT);
    int WWTemp = map(WTemp, 0, 1023, 0, 255);
    digitalWrite(led,HIGH);                         //flash LED
    vw_get_message(buf, &buflen);                   //get the data, store in variable buf with length of bufflen
    memcpy(&data,&buf,buflen);                      //memcpy ( void * destination, const void * source, size_t num );

    Serial.print((int)(data.temperature*1.8)+32);
    Serial.print("|");
    Serial.print((int)data.humidity);
    Serial.print("|");
    Serial.println((int)smVal);
    Serial.print("|");
    Serial.println((int)WTemp);
    Serial.print("|");


    if (smVal <= 89)
    { 
      Serial.print("Done Watering!");
      Serial.print("|");
          }

    else if (smVal > 89)
 {
      Serial.print("Watering Now..");
      Serial.print("|");
    }
    
    lcd.clear();
    lcd.print("TEMP");
    lcd.setCursor(6, 0);
    lcd.write(1);
    lcd.setCursor(8, 0);
    lcd.print((data.temperature*1.8)+32);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("HUMI");
    lcd.setCursor(6, 1);
    lcd.write(2);
    lcd.setCursor(8, 1);
    lcd.print(data.humidity);
    lcd.print("%");
    delay(2000);
    

    
        if (smVal <= 89)
    { 
     
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("WATER TEMP");
    lcd.setCursor(11, 0);
    lcd.write(3);
    lcd.setCursor(13, 0);
    lcd.print(WTemp);
    lcd.write(0b11011111);
    lcd.print("C");
      lcd.setCursor(0,1);
      lcd.print("Watering now :)");
if ((WTem*1.8)+32) > 74)
{
      digitalWrite(SV, HIGH); //Valve Close
      delay(10000);
      }
else if ((WTem*1.8)+32) < 61)
{
digitalWrite(SV, HIGH); //Valve Close delay(10000); } else { digitalWrite(SV, LOW); //Valve Open
      delay(3000);
}
else if (smVal > 89) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Water Temp"); lcd.setCursor(12, 0); lcd.write(3); lcd.setCursor(14, 0); lcd.print(WTemp); lcd.write(0b11011111); lcd.print("C"); lcd.setCursor(0,1); lcd.print("Done Watering"); digitalWrite(SV, HIGH); //Valve close delay(2000); } } }

Discussions