Skip to content

Instantly share code, notes, and snippets.

@alexanderscott
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save alexanderscott/e24d3bfacde56fa863a2 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderscott/e24d3bfacde56fa863a2 to your computer and use it in GitHub Desktop.

Revisions

  1. alexanderscott revised this gist Mar 18, 2015. 1 changed file with 63 additions and 24 deletions.
    87 changes: 63 additions & 24 deletions iGrow.ino
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    #include <LiquidCrystal.h>
    #include "DHT.h"
    #include <MemoryFree.h>
    #include <SerialReceiver.h>

    #define DHTTYPE DHT11

    @@ -77,6 +78,7 @@ void setup() {
    pinMode(PUMP_PIN_1, OUTPUT);

    Serial.begin(SERIAL_PORT);
    IncomingCommand::reset();

    delay(500);
    }
    @@ -95,24 +97,55 @@ void loop() {

    checkPumpButtons();

    delay(READ_DELAY);
    readSerialEvents();

    readSerialEvents();
    }

    void readSerialEvents() {
    IncomingCommand::reset();
    unsigned long beginTime = millis();
    while ((millis() - beginTime) < READ_DELAY) {
    if (Serial.available()) {
    char inChar = (char) Serial.read();
    IncomingCommand::append(inChar);
    if (IncomingCommand::isReady) {
    executeSerialCommand(IncomingCommand::command, IncomingCommand::payload);
    IncomingCommand::reset();
    }
    }
    delay(50);
    }
    }

    void executeSerialCommand(String cmd, String payload) {
    Serial << "Command: " << cmd << ", payload: " << payload << "\r\n";
    if (cmd == "WATER_0") {
    int waterTime = payload.toInt();
    pumpWater0(waterTime);
    } else if (cmd == "WATER_1") {
    int waterTime = payload.toInt();
    pumpWater1(waterTime);
    } else if(cmd == "WATER") {
    int waterTime = payload.toInt();
    pumpWater0(waterTime);
    delay(10000);
    pumpWater1(waterTime);
    }
    }

    void checkPumpButtons()
    {
    void checkPumpButtons() {
    pumpBtnState0 = digitalRead(PUMP_BTN_PIN_0);
    pumpBtnState1 = digitalRead(PUMP_BTN_PIN_1);

    if (pumpBtnState0 == LOW)
    {
    if (pumpBtnState0 == LOW) {
    Serial.println("Pump0 button press");
    pumpWater0();
    pumpWater0(PUMP_WATER_TIME);
    }

    if (pumpBtnState1 == LOW)
    {
    if (pumpBtnState1 == LOW) {
    Serial.println("Pump1 button press");
    pumpWater1();
    pumpWater1(PUMP_WATER_TIME);
    }
    }

    @@ -194,35 +227,41 @@ void computeTemp() {
    }
    }

    void pumpWater0() {
    lcd.noDisplay();
    delay(200);
    void pumpWater0(int waterTime) {
    //lcd.noDisplay();
    //delay(200);
    Serial.println("Activating pump0");

    digitalWrite(PUMP_PIN_0, HIGH);
    analogWrite(PUMP_PIN_0, 255);
    //digitalWrite(PUMP_PIN_0, HIGH);

    delay(PUMP_WATER_TIME);
    delay(waterTime);

    Serial.println("Deactivating pump0");
    digitalWrite(PUMP_PIN_0, LOW);

    lcd.display();
    analogWrite(PUMP_PIN_0, 0);
    //digitalWrite(PUMP_PIN_0, LOW);

    //lcd.display();
    delay(1000);
    }

    void pumpWater1() {
    lcd.noDisplay();
    delay(200);
    void pumpWater1(int waterTime) {
    //lcd.noDisplay();
    //delay(200);
    Serial.println("Activating pump1");

    digitalWrite(PUMP_PIN_1, HIGH);
    analogWrite(PUMP_PIN_1, 255);
    //digitalWrite(PUMP_PIN_1, HIGH);

    delay(PUMP_WATER_TIME);
    delay(waterTime);

    Serial.println("Deactivating pump0");
    digitalWrite(PUMP_PIN_1, LOW);
    Serial.println("Deactivating pump1");

    analogWrite(PUMP_PIN_1, 0);
    //digitalWrite(PUMP_PIN_1, LOW);

    lcd.display();
    //lcd.display();
    delay(1000);
    }

  2. alexanderscott revised this gist Mar 12, 2015. 1 changed file with 21 additions and 65 deletions.
    86 changes: 21 additions & 65 deletions iGrow.ino
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@

    #define DHTTYPE DHT11

    template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }

    /* Pin Setup */
    const int DHT_PIN_0 = 6;
    const int DHT_PIN_1 = 7;
    @@ -62,9 +64,8 @@ void setup() {
    delay(2000); //allow lcd to wake up.

    lcd.begin(20, 4);
    lcd.print("== iGrow ==");
    lcd.setCursor(0, 2);
    lcd.print("Initializing sensors...");
    lcd << "=== iGrow ===" << "\r\n";
    lcd << "Initializing sensors..." << "\r\n";

    dht0.begin();
    dht1.begin();
    @@ -232,34 +233,24 @@ void pumpWater1() {
    */
    void printSerial() {
    // print how much RAM is available.
    //Serial.print("Free RAM: ");
    //Serial.println(freeMemory(), DEC);
    Serial.print("Free RAM: ");
    Serial.println(freeMemory(), DEC);

    Serial.print("light_0,");
    Serial.println(lightValue0);
    Serial << "light_0," << lightValue0 << "\r\n";

    Serial.print("moisture_0," );
    Serial.println(moistureValue0);
    Serial << "moisture_0," << moistureValue0 << "\r\n";
    Serial << "moisture_1," << moistureValue1 << "\r\n";

    if (dht0operational == true) {
    Serial.print("humidity_0,");
    Serial.println(humidityValue0);
    Serial.print("temperature_0,");
    Serial.println(tempFahrValue0);
    Serial.print("heat_0,");
    Serial.println(heatValue0);
    Serial << "humidity_0," << humidityValue0 << "\r\n";
    Serial << "temperature_0," << tempFahrValue0 << "\r\n";
    Serial << "heat_0," << heatValue0 << "\r\n";
    }

    Serial.print("moisture_1,");
    Serial.println(moistureValue1);

    if (dht1operational == true) {
    Serial.print("humidity_1,");
    Serial.println(humidityValue1);
    Serial.print("temperature_1,");
    Serial.println(tempFahrValue1);
    Serial.print("heat_1,");
    Serial.println(heatValue1);
    Serial << "humidity_1," << humidityValue1 << "\r\n";
    Serial << "temperature_1," << tempFahrValue1 << "\r\n";
    Serial << "heat_1," << heatValue1 << "\r\n";
    }
    }

    @@ -274,53 +265,18 @@ void printLCD() {

    lcd.clear();
    delay(200);

    lcd.setCursor(0, 0);
    lcd.print("M0: ");
    lcd.print(moistureValue0);
    lcd.print(", ");
    lcd.print("M1: ");
    lcd.print(moistureValue1);
    lcd << "M0: " << moistureValue0 << " M1: " << moistureValue1;

    lcd.setCursor(0, 1);
    if (dht0operational == true) {
    lcd.print("T0: ");
    lcd.print(t0);
    lcd.print("*F, ");
    }
    if (dht1operational == true) {
    lcd.print("T1: ");
    lcd.print(t1);
    lcd.print("*F");
    }

    lcd << "T0: " << t0 << "*F T1: " << t1 << "*F";

    lcd.setCursor(0, 2);
    if (dht0operational == true) {
    lcd.print("HU0: ");
    lcd.print(hu0);
    lcd.print("%, ");
    }
    if (dht1operational == true) {
    lcd.print("HU1: ");
    lcd.print(hu1);
    lcd.print("%");
    }
    lcd << "HU0: " << hu0 << "% H01: " << hu1 << "%";

    lcd.setCursor(0, 3);
    lcd.print("L: ");
    lcd.print(l0);

    if (dht0operational == true) {
    lcd.print(", ");
    lcd.print("H0: ");
    lcd.print(he0);
    }
    if (dht1operational == true) {
    lcd.print(", ");
    lcd.print("H1: ");
    lcd.print(he1);
    }

    lcd << "L1: " << l0;
    }

    float voltageToLux(float photocellReading) {
  3. alexanderscott revised this gist Mar 11, 2015. 1 changed file with 39 additions and 25 deletions.
    64 changes: 39 additions & 25 deletions iGrow.ino
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,17 @@
    /* Imports & Definitions */
    #include <LiquidCrystal.h>
    #include "DHT.h"
    #include <MemoryFree.h>

    #define DHTTYPE DHT11


    /* Pin Setup */
    const int DHT_PIN_0 = 6;
    const int DHT_PIN_1 = 7;

    const int PUMP_PIN_0 = 9;
    const int PUMP_PIN_1 = 10;

    const int MOISTURE_PIN_0 = A0;
    const int MOISTURE_PIN_1 = A1;
    const int LIGHT_PIN_0 = A2;
    @@ -32,13 +34,13 @@ long int moistureSum0 = 0;
    int moistureValue1 = 0;
    long int moistureSum1 = 0;

    bool dht0operational = 1;
    bool dht0operational = true;
    float humidityValue0 = 0;
    float tempValue0 = 0;
    float tempFahrValue0 = 0;
    float heatValue0 = 0;

    bool dht1operational = 1;
    bool dht1operational = true;
    float humidityValue1 = 0;
    float tempValue1 = 0;
    float tempFahrValue1 = 0;
    @@ -50,8 +52,8 @@ int pumpBtnState1 = 0;
    /* Constants / Configuration */
    const int READ_DELAY = 10000;
    const int SAMPLES_PER_READ = 30;
    const int PUMP_WATER_TIME = 5000;
    const long int PUMP_WATER_WAIT_TIME = 86400000;
    const int PUMP_WATER_TIME = 10000;
    //const long int PUMP_WATER_WAIT_TIME = 86400000;
    const int SERIAL_PORT = 9600;


    @@ -95,20 +97,26 @@ void loop() {
    delay(READ_DELAY);
    }

    void checkPumpButtons() {
    void checkPumpButtons()
    {
    pumpBtnState0 = digitalRead(PUMP_BTN_PIN_0);
    pumpBtnState1 = digitalRead(PUMP_BTN_PIN_1);
    if (pumpBtnState0 == LOW){

    if (pumpBtnState0 == LOW)
    {
    Serial.println("Pump0 button press");
    //pumpWater0();
    pumpWater0();
    }
    if (pumpBtnState1 == LOW){

    if (pumpBtnState1 == LOW)
    {
    Serial.println("Pump1 button press");
    //pumpWater1();
    pumpWater1();
    }
    }



    // Reset readings back to 0 for next loop
    void resetReadings() {
    moistureValue0 = 0;
    @@ -185,34 +193,35 @@ void computeTemp() {
    }
    }


    void pumpWater0() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ACTIVATING PUMP0");
    analogWrite(PUMP_PIN_0, 255);
    lcd.noDisplay();
    delay(200);
    Serial.println("Activating pump0");

    digitalWrite(PUMP_PIN_0, HIGH);

    delay(PUMP_WATER_TIME);

    lcd.clear();
    lcd.print("DEACTIVATING PUMP0");
    analogWrite(PUMP_PIN_0, 0);
    Serial.println("Deactivating pump0");
    digitalWrite(PUMP_PIN_0, LOW);

    lcd.display();
    delay(1000);
    }

    void pumpWater1() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ACTIVATING PUMP1");
    analogWrite(PUMP_PIN_1, 255);
    lcd.noDisplay();
    delay(200);
    Serial.println("Activating pump1");

    digitalWrite(PUMP_PIN_1, HIGH);

    delay(PUMP_WATER_TIME);

    lcd.clear();
    lcd.print("DEACTIVATING PUMP1");
    analogWrite(PUMP_PIN_1, 0);
    Serial.println("Deactivating pump0");
    digitalWrite(PUMP_PIN_1, LOW);

    lcd.display();
    delay(1000);
    }

    @@ -222,6 +231,10 @@ void pumpWater1() {
    Display Functions
    */
    void printSerial() {
    // print how much RAM is available.
    //Serial.print("Free RAM: ");
    //Serial.println(freeMemory(), DEC);

    Serial.print("light_0,");
    Serial.println(lightValue0);

    @@ -327,3 +340,4 @@ float voltageToLux(float photocellReading) {
    }



  4. alexanderscott revised this gist Mar 8, 2015. 1 changed file with 92 additions and 63 deletions.
    155 changes: 92 additions & 63 deletions iGrow.ino
    Original file line number Diff line number Diff line change
    @@ -32,16 +32,20 @@ long int moistureSum0 = 0;
    int moistureValue1 = 0;
    long int moistureSum1 = 0;

    bool dht0operational = 1;
    float humidityValue0 = 0;
    float tempValue0 = 0;
    float tempFahrValue0 = 0;
    float heatValue0 = 0;

    bool dht1operational = 1;
    float humidityValue1 = 0;
    float tempValue1 = 0;
    float tempFahrValue1 = 0;
    float heatValue1 = 0;

    int pumpBtnState0 = 0;
    int pumpBtnState1 = 0;

    /* Constants / Configuration */
    const int READ_DELAY = 10000;
    @@ -92,13 +96,15 @@ void loop() {
    }

    void checkPumpButtons() {
    int pumpBtnState0 = digitalRead(PUMP_BTN_PIN_0);
    int pumpBtnState1 = digitalRead(PUMP_BTN_PIN_1);
    if (pumpBtnState0 == HIGH){
    pumpWater0();
    pumpBtnState0 = digitalRead(PUMP_BTN_PIN_0);
    pumpBtnState1 = digitalRead(PUMP_BTN_PIN_1);
    if (pumpBtnState0 == LOW){
    Serial.println("Pump0 button press");
    //pumpWater0();
    }
    if (pumpBtnState1 == HIGH){
    pumpWater1();
    if (pumpBtnState1 == LOW){
    Serial.println("Pump1 button press");
    //pumpWater1();
    }
    }

    @@ -122,6 +128,9 @@ void resetReadings() {

    lightValue0 = 0;
    lightSum0 = 0;

    pumpBtnState0 = 0;
    pumpBtnState1 = 0;
    }


    @@ -135,18 +144,14 @@ void computeLightMoisture() {

    // Read light
    lightSum0 = lightSum0 + analogRead(LIGHT_PIN_0);
    //int lightValueTmp0 = analogRead(LIGHT_PIN_0);
    //lightValueTmp0 = map(lightValueTmp0, 0, 1023, 0, 255);
    //lightValueTmp0 = constrain(lightValueTmp0, 0, 255);
    //lightSum0 = lightSum0 + lightValueTmp0;

    delay(100);
    }

    moistureValue0 = moistureSum0 / SAMPLES_PER_READ;
    moistureValue1 = moistureSum1 / SAMPLES_PER_READ;

    int lightValue0Tmp = lightSum0 / SAMPLES_PER_READ;
    float lightValue0Tmp = lightSum0 / SAMPLES_PER_READ;
    lightValue0 = voltageToLux(lightValue0Tmp);
    }

    @@ -165,14 +170,18 @@ void computeTemp() {
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidityValue0) || isnan(tempValue0) || isnan(tempFahrValue0)) {
    Serial.println("Failed to read from DHT0 sensor!");
    dht0operational = false;
    } else {
    heatValue0 = dht0.computeHeatIndex(tempFahrValue0, humidityValue0);
    dht0operational = true;
    }

    if (isnan(humidityValue1) || isnan(tempValue1) || isnan(tempFahrValue1)) {
    Serial.println("Failed to read from DHT1 sensor!");
    dht1operational = false;
    } else {
    heatValue1 = dht1.computeHeatIndex(tempFahrValue1, humidityValue1);
    dht1operational = true;
    }
    }

    @@ -213,37 +222,43 @@ void pumpWater1() {
    Display Functions
    */
    void printSerial() {
    Serial.print("0,light,");
    Serial.print("light_0,");
    Serial.println(lightValue0);

    Serial.print("0,moisture," );
    Serial.print("moisture_0," );
    Serial.println(moistureValue0);

    Serial.print("0,humidity,");
    Serial.println(humidityValue0);

    Serial.print("0,temperature,");
    Serial.println(tempFahrValue0);

    Serial.print("0,heat,");
    Serial.println(heatValue0);
    if (dht0operational == true) {
    Serial.print("humidity_0,");
    Serial.println(humidityValue0);
    Serial.print("temperature_0,");
    Serial.println(tempFahrValue0);
    Serial.print("heat_0,");
    Serial.println(heatValue0);
    }

    Serial.print("1,moisture,");
    Serial.print("moisture_1,");
    Serial.println(moistureValue1);

    Serial.print("1,humidity,");
    Serial.println(humidityValue1);

    Serial.print("1,temperature,");
    Serial.println(tempFahrValue1);

    Serial.print("1,heat,");
    Serial.println(heatValue1);

    Serial.println();
    if (dht1operational == true) {
    Serial.print("humidity_1,");
    Serial.println(humidityValue1);
    Serial.print("temperature_1,");
    Serial.println(tempFahrValue1);
    Serial.print("heat_1,");
    Serial.println(heatValue1);
    }
    }

    void printLCD() {
    int hu0 = (int) humidityValue0;
    int hu1 = (int) humidityValue1;
    int t0 = (int) tempFahrValue0;
    int t1 = (int) tempFahrValue1;
    int l0 = (int) lightValue0;
    int he0 = (int) heatValue0;
    int he1 = (int) heatValue1;

    lcd.clear();
    delay(200);

    @@ -255,46 +270,60 @@ void printLCD() {
    lcd.print(moistureValue1);

    lcd.setCursor(0, 1);
    lcd.print("T0: ");
    lcd.print(tempFahrValue0);
    lcd.print(" *F, ");
    lcd.print("T1: ");
    lcd.print(tempFahrValue1);
    lcd.print(" *F");
    if (dht0operational == true) {
    lcd.print("T0: ");
    lcd.print(t0);
    lcd.print("*F, ");
    }
    if (dht1operational == true) {
    lcd.print("T1: ");
    lcd.print(t1);
    lcd.print("*F");
    }

    lcd.setCursor(0, 2);
    lcd.print("HU0: ");
    lcd.print(humidityValue0);
    lcd.print("%, HU1: ");
    lcd.print(humidityValue1);
    lcd.print("%");
    if (dht0operational == true) {
    lcd.print("HU0: ");
    lcd.print(hu0);
    lcd.print("%, ");
    }
    if (dht1operational == true) {
    lcd.print("HU1: ");
    lcd.print(hu1);
    lcd.print("%");
    }

    lcd.setCursor(0, 3);
    lcd.print("L0: ");
    lcd.print(lightValue0);
    //lcd.print(", ");
    //lcd.print(lightValue1);
    //lcd.print("Heat: ");
    //lcd.print(heat);
    lcd.print("L: ");
    lcd.print(l0);

    if (dht0operational == true) {
    lcd.print(", ");
    lcd.print("H0: ");
    lcd.print(he0);
    }
    if (dht1operational == true) {
    lcd.print(", ");
    lcd.print("H1: ");
    lcd.print(he1);
    }

    }

    float voltageToLux(float photocellReading) {
    // Calculating the voltage in the input of the ADC
    float voltage = 5.0 * (photocellReading / 1024.0);

    // Calculating the resistance of the photoresistor
    // in the voltage divider
    float resistance = (10.0 * 5.0) / voltage - 10.0;

    /*
    Helper Functions
    */
    void send_float (float arg) {
    // get access to the float as a byte-array:
    byte * data = (byte *) &arg;
    // Calculating the intensity of light in lux
    float illuminance = 255.84 * pow(resistance, -10/9);

    // write the data to the serial
    Serial.write (data, sizeof (arg));
    // Converting the intensity of light to text
    //sprintf(text, "%0.1f lux ", illuminance);
    return illuminance;
    }


    float voltageToLux(int photocellReading) {
    float photocellResistance = 10.0;
    float vOut = photocellReading * 0.0048828125; // calculate the voltage
    float lux = 500/(photocellResistance*((5-vOut)/vOut)); // calculate the Lux
    return lux;
    }
  5. alexanderscott created this gist Mar 4, 2015.
    300 changes: 300 additions & 0 deletions iGrow.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,300 @@
    /* Imports & Definitions */
    #include <LiquidCrystal.h>
    #include "DHT.h"

    #define DHTTYPE DHT11


    /* Pin Setup */
    const int DHT_PIN_0 = 6;
    const int DHT_PIN_1 = 7;
    const int PUMP_PIN_0 = 9;
    const int PUMP_PIN_1 = 10;
    const int MOISTURE_PIN_0 = A0;
    const int MOISTURE_PIN_1 = A1;
    const int LIGHT_PIN_0 = A2;
    const int PUMP_BTN_PIN_0 = A4;
    const int PUMP_BTN_PIN_1 = A5;


    /* Library Initialization */
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    DHT dht0(DHT_PIN_0, DHTTYPE);
    DHT dht1(DHT_PIN_1, DHTTYPE);


    /* Variable Measurements */
    float lightValue0 = 0;
    long int lightSum0 = 0;

    int moistureValue0 = 0;
    long int moistureSum0 = 0;
    int moistureValue1 = 0;
    long int moistureSum1 = 0;

    float humidityValue0 = 0;
    float tempValue0 = 0;
    float tempFahrValue0 = 0;
    float heatValue0 = 0;

    float humidityValue1 = 0;
    float tempValue1 = 0;
    float tempFahrValue1 = 0;
    float heatValue1 = 0;


    /* Constants / Configuration */
    const int READ_DELAY = 10000;
    const int SAMPLES_PER_READ = 30;
    const int PUMP_WATER_TIME = 5000;
    const long int PUMP_WATER_WAIT_TIME = 86400000;
    const int SERIAL_PORT = 9600;


    void setup() {

    delay(2000); //allow lcd to wake up.

    lcd.begin(20, 4);
    lcd.print("== iGrow ==");
    lcd.setCursor(0, 2);
    lcd.print("Initializing sensors...");

    dht0.begin();
    dht1.begin();

    pinMode(LIGHT_PIN_0, INPUT);
    pinMode(PUMP_BTN_PIN_0, INPUT);
    pinMode(PUMP_BTN_PIN_1, INPUT);
    pinMode(PUMP_PIN_0, OUTPUT);
    pinMode(PUMP_PIN_1, OUTPUT);

    Serial.begin(SERIAL_PORT);

    delay(500);
    }


    void loop() {
    resetReadings();

    computeLightMoisture();

    computeTemp();

    printSerial();

    printLCD();

    checkPumpButtons();

    delay(READ_DELAY);
    }

    void checkPumpButtons() {
    int pumpBtnState0 = digitalRead(PUMP_BTN_PIN_0);
    int pumpBtnState1 = digitalRead(PUMP_BTN_PIN_1);
    if (pumpBtnState0 == HIGH){
    pumpWater0();
    }
    if (pumpBtnState1 == HIGH){
    pumpWater1();
    }
    }


    // Reset readings back to 0 for next loop
    void resetReadings() {
    moistureValue0 = 0;
    moistureSum0 = 0;
    moistureValue1 = 0;
    moistureSum1 = 0;

    humidityValue0 = 0;
    tempValue0 = 0;
    tempFahrValue0 = 0;
    heatValue0 = 0;

    humidityValue1 = 0;
    tempValue1= 0;
    tempFahrValue1 = 0;
    heatValue1 = 0;

    lightValue0 = 0;
    lightSum0 = 0;
    }


    // Calculate light & moisture readings from sample avg
    void computeLightMoisture() {
    for(int i = 0; i < SAMPLES_PER_READ; i++) {

    // Read moisture
    moistureSum0 = moistureSum0 + analogRead(MOISTURE_PIN_0);
    moistureSum1 = moistureSum1 + analogRead(MOISTURE_PIN_1);

    // Read light
    lightSum0 = lightSum0 + analogRead(LIGHT_PIN_0);
    //int lightValueTmp0 = analogRead(LIGHT_PIN_0);
    //lightValueTmp0 = map(lightValueTmp0, 0, 1023, 0, 255);
    //lightValueTmp0 = constrain(lightValueTmp0, 0, 255);
    //lightSum0 = lightSum0 + lightValueTmp0;

    delay(100);
    }

    moistureValue0 = moistureSum0 / SAMPLES_PER_READ;
    moistureValue1 = moistureSum1 / SAMPLES_PER_READ;

    int lightValue0Tmp = lightSum0 / SAMPLES_PER_READ;
    lightValue0 = voltageToLux(lightValue0Tmp);
    }


    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    void computeTemp() {
    humidityValue0 = dht0.readHumidity();
    tempValue0 = dht0.readTemperature();
    tempFahrValue0 = dht0.readTemperature(true); // Read temperature as Fahrenheit

    humidityValue1 = dht1.readHumidity();
    tempValue1 = dht1.readTemperature();
    tempFahrValue1 = dht1.readTemperature(true); // Read temperature as Fahrenheit

    // Check if any reads failed and exit early (to try again).
    if (isnan(humidityValue0) || isnan(tempValue0) || isnan(tempFahrValue0)) {
    Serial.println("Failed to read from DHT0 sensor!");
    } else {
    heatValue0 = dht0.computeHeatIndex(tempFahrValue0, humidityValue0);
    }

    if (isnan(humidityValue1) || isnan(tempValue1) || isnan(tempFahrValue1)) {
    Serial.println("Failed to read from DHT1 sensor!");
    } else {
    heatValue1 = dht1.computeHeatIndex(tempFahrValue1, humidityValue1);
    }
    }


    void pumpWater0() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ACTIVATING PUMP0");
    analogWrite(PUMP_PIN_0, 255);

    delay(PUMP_WATER_TIME);

    lcd.clear();
    lcd.print("DEACTIVATING PUMP0");
    analogWrite(PUMP_PIN_0, 0);

    delay(1000);
    }

    void pumpWater1() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ACTIVATING PUMP1");
    analogWrite(PUMP_PIN_1, 255);

    delay(PUMP_WATER_TIME);

    lcd.clear();
    lcd.print("DEACTIVATING PUMP1");
    analogWrite(PUMP_PIN_1, 0);

    delay(1000);
    }



    /*
    Display Functions
    */
    void printSerial() {
    Serial.print("0,light,");
    Serial.println(lightValue0);

    Serial.print("0,moisture," );
    Serial.println(moistureValue0);

    Serial.print("0,humidity,");
    Serial.println(humidityValue0);

    Serial.print("0,temperature,");
    Serial.println(tempFahrValue0);

    Serial.print("0,heat,");
    Serial.println(heatValue0);

    Serial.print("1,moisture,");
    Serial.println(moistureValue1);

    Serial.print("1,humidity,");
    Serial.println(humidityValue1);

    Serial.print("1,temperature,");
    Serial.println(tempFahrValue1);

    Serial.print("1,heat,");
    Serial.println(heatValue1);

    Serial.println();
    }

    void printLCD() {
    lcd.clear();
    delay(200);

    lcd.setCursor(0, 0);
    lcd.print("M0: ");
    lcd.print(moistureValue0);
    lcd.print(", ");
    lcd.print("M1: ");
    lcd.print(moistureValue1);

    lcd.setCursor(0, 1);
    lcd.print("T0: ");
    lcd.print(tempFahrValue0);
    lcd.print(" *F, ");
    lcd.print("T1: ");
    lcd.print(tempFahrValue1);
    lcd.print(" *F");

    lcd.setCursor(0, 2);
    lcd.print("HU0: ");
    lcd.print(humidityValue0);
    lcd.print("%, HU1: ");
    lcd.print(humidityValue1);
    lcd.print("%");

    lcd.setCursor(0, 3);
    lcd.print("L0: ");
    lcd.print(lightValue0);
    //lcd.print(", ");
    //lcd.print(lightValue1);
    //lcd.print("Heat: ");
    //lcd.print(heat);
    }



    /*
    Helper Functions
    */
    void send_float (float arg) {
    // get access to the float as a byte-array:
    byte * data = (byte *) &arg;

    // write the data to the serial
    Serial.write (data, sizeof (arg));
    }


    float voltageToLux(int photocellReading) {
    float photocellResistance = 10.0;
    float vOut = photocellReading * 0.0048828125; // calculate the voltage
    float lux = 500/(photocellResistance*((5-vOut)/vOut)); // calculate the Lux
    return lux;
    }