Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
KarthickHarithaSindhu
Created July 29, 2017 © GPL3+

Arduino 101 Plants and Trees protector from starving

Plants and trees protector from starving during summer with Aurdino 101 and few sensors like soil temperature, soil moisture, etc.

IntermediateFull instructions provided6 hours154

Things used in this project

Story

Read more

Schematics

schematic diagram

Schematic diagram for Arduino 101 plants and trees protector from starving system.

Code

Arduino 101 plants and trees protector from starving.ino

Arduino
Arduino 101 plants and trees protector from starving measures soil moisture and air temperature. Relay is controlled using soil moisture data to water plants.
//PROJECT: Arduino 101 plants and trees protector from starving 
#include <Wire.h>
#include "rgb_lcd.h"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT DebugSerial


// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "6d59142e511842de909816f5a3dd1e99";
const int pinTemp = A0; //Tempearure sensor connect to Analog A0 pin
const int pinSoil = A1; //Soil moisture sensor connect to Analog A1 pin   
const int chipSelect = 4;
const int relayPin =  8;  // Relay is connected to pin D8
char CC;
float temperature;
float Soil;
int B=3975;                 
float resistance;
rgb_lcd lcd;
// Main program
void setup()
{
    Serial.begin(115200); 
    lcd.begin(16, 2);
    lcd.print("Temp.:");
    lcd.setCursor(0,1);
    lcd.print("S.Moist.:"); 
    pinMode(relayPin, OUTPUT);
     // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}
// Program for RGB LCD 
void breath(unsigned char color)
{

    for(int i=0; i<255; i++)
    {
        lcd.setPWM(color, i);
        delay(0.1);
    }
   delay(100);
    for(int i=1; i>=0; i--)
    {
        lcd.setPWM(color, i);   
    }
}

//Running the task continously by loop funcation
void loop()
{
    // If the Soil is DRY relay is HIGH to open solenoid valve.
    if (Soil < 30)   
    {
        digitalWrite(relayPin, HIGH);
       CC = char('D'); 
    }
    else if ( Soil > 60) 
    // If the Soil is Humid or Wet relay is LOW to close solenoid valve.  
    {
      digitalWrite(relayPin, LOW);
      CC = char('W'); 
    }
    else     
    {
      digitalWrite(relayPin, LOW);
      CC = char('H');   
    } 
     // Indicate the temperature by varying the RGB back light according to surrounding temperature  
     if (temperature >30)
     {
      breath(REG_RED);
      }
     if (temperature <30)
     {
        breath(REG_GREEN);
      } 
     if (temperature <20)
        {
          breath(REG_BLUE);
        }
//Read temperature data from anolog pin A0   
    int val = analogRead(pinTemp);                               
    resistance=(float)(1023-val)*10000/val;                      
    temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
    temperature = (temperature - 32)*0.555; 
// Display temperature on LCD    
    lcd.setCursor(6,0);
    lcd.print(temperature);
    lcd.setCursor(12,0);
    lcd.write(0b11011111);
    lcd.setCursor(13,0);
    lcd.print("C");    
//Read soil moisture data from anolog pin A1
    int vat = analogRead(pinSoil);                               
    Soil = abs(vat-1023)/10.24;
// Display Soil moistre % on LCD    
    lcd.setCursor(9,1);
    lcd.print(Soil);
    lcd.setCursor(14,1);
    lcd.print("%");
    lcd.print(CC);

      Blynk.run();
      
}
  // End of the task   

Credits

Karthick
12 projects • 13 followers
Hobbyist
Haritha
1 project • 2 followers
Sindhu
3 projects • 5 followers

Comments