Close

Planti 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:410 Comments

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

#include <VirtualWire.h>                            //Library for the Radios
#include "DHT.h"                                    //Library for the DHT11 Sensor

//-----------------------------------------------------------------------------------------------------
//                                               DEFINES
//-----------------------------------------------------------------------------------------------------

#define DHTPIN  12                                   //DHT Output on D4
#define DHTTYPE DHT11                               //DHT Type (11,21,22)
\

//-----------------------------------------------------------------------------------------------------
//                                              VARIABLES
//-----------------------------------------------------------------------------------------------------
const int led_pin = 13;                             //LED on D13
const int transmit_pin = 2;                        //Radio input on D12
//-----------------------------------------------------------------------------------------------------
//                                           DATA STRUCTURES
//-----------------------------------------------------------------------------------------------------

// If you are not familiar with Data Structures visit this link http://www.cplusplus.com/doc/tutorial/structures/

struct package                                      //Struct Type Name
{
  int temperature ;                               //Struct Member
  int humidity ;                                  //Struct Member
  int rain;
  int soil;
  
};


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

//-----------------------------------------------------------------------------------------------------
//                                            LIBRARY CALLS
//-----------------------------------------------------------------------------------------------------
DHT dht(DHTPIN, DHTTYPE);                           //Create instance of DHT called dht

//-----------------------------------------------------------------------------------------------------
//                                                SETUP
//-----------------------------------------------------------------------------------------------------
void setup()
{
    
    vw_set_tx_pin(transmit_pin);                    //initialize radio on D12
    vw_set_ptt_inverted(true);                      // Required for DR3100
    vw_setup(500);                                  // Bits per sec
    pinMode(led_pin, OUTPUT);                       //set LED for output
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
}

//-----------------------------------------------------------------------------------------------------
//                                              MAIN LOOP
//-----------------------------------------------------------------------------------------------------

void loop()
{
  digitalWrite(led_pin, HIGH);                      // Flash a light to show transmitting
  readSensor();                                     //Call readSensor function
  vw_send((uint8_t *)&data, sizeof(data));          //send data (struct array)
  vw_wait_tx();                                     // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);                       //LED off
  delay(2000);                                      //wait 2 seconds
}
//-----------------------------------------------------------------------------------------------------
//                                              FUNCTIONS
//-----------------------------------------------------------------------------------------------------
void readSensor()                                   //readSensor function
{
 dht.begin();                                       //initialize dht
 delay(1000);                                       //wait 1 second
 data.humidity = dht.readHumidity();                //get humidity & store in Struct variable data.humidity
 data.temperature = dht.readTemperature();          //get temperature & store in Struct variable data.temperature
 data.soil = analogRead(A0);
 data.rain = analogRead(A1);
 
}

Discussions