candicebobo7
Published

DIY Smart Plant

Take care of your plant automatically

IntermediateWork in progress1,360
DIY Smart Plant

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Gravity: Analog Soil Moisture Sensor For Arduino
DFRobot Gravity: Analog Soil Moisture Sensor For Arduino
×1
Pump 12V
×1
Water level sensor
×1
LED Strip, 10 "
LED Strip, 10 "
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Buzzer
Buzzer
×1
Photo resistor
Photo resistor
×1
Resistor 100 ohm
Resistor 100 ohm
×2

Hand tools and fabrication machines

Plant pot

Story

Read more

Schematics

Schematics

Code

Smart_plant

C/C++
//import librairies
#define FASTLED_INTERNAL 
#include <FastLED.h>
#include <DHT.h>

//define pins
#define PHOTO_PIN     A7  //analog pin photoresistor
#define WATER_PIN     A0  //analog pin water sensor
#define BUZZ_PIN      10    //digital pin buzzer
#define DHTPIN        9  // Digital pin connected to the DHT sensor
#define LED_PIN       11  //digital pin led
#define NUM_LEDS      10 //number of led of the strip
#define DHTTYPE       DHT11 // model od dht
#define MOISTURE_PIN  A4 //analog soil moisture pin
#define RELAY_PIN     A5  // analog IN pin of relay


DHT dht(DHTPIN, DHTTYPE);
CRGB leds[NUM_LEDS];

int water_value; //value of the water sensor
int photo_value; // store the value from photoresistor (0-1023)
int moisture_value; //store the value from the soil moisture

void setup() {
  
  Serial.begin(9600); //sets data rate to 115200 bps
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Serial.println("DHT test");
  dht.begin();
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  pinMode(PHOTO_PIN,INPUT);
  pinMode(WATER_PIN,INPUT);
  pinMode(BUZZ_PIN,OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
  delay(1000);
  
}

void loop() {
  //read the value of the moisture sensor
  moisture_value= analogRead(MOISTURE_PIN);
  moisture_value = map(moisture_value,0,1023,0,100);
  Serial.print("Moisture : ");
  Serial.print(moisture_value);
  Serial.println("%");
  
  //If the soil is dry the relay is on 
  if (moisture_value >= 37){
      digitalWrite(RELAY_PIN, LOW); // turn on the pump 
      Serial.print("Pump On");
      Serial.print(RELAY_PIN);
    }
   else{
      digitalWrite(RELAY_PIN, HIGH); // turn off the pump 
      Serial.print("Pump Off");
      Serial.print(RELAY_PIN);
    }
  //read photoresistor value
  int analog_value = analogRead(PHOTO_PIN);
  int photo_value = map(analog_value, 0, 1023, 0, 100);// read value’s current range to value’s target range
  while (photo_value > 50){ // while is daylight do the project otherwise nothing is activated
     
    Serial.print("photoresistor = "); 
    Serial.print(photo_value);
    Serial.print("  ");  Serial.print("\n");

  //Read Water Value
    water_value = analogRead(WATER_PIN);
  
    if (water_value < 3050 && water_value > 0){ //the buzzer makes sound if the level of water is too low
    //read buzz sensor
      digitalWrite(BUZZ_PIN,HIGH); 
      delay(100);
      digitalWrite(BUZZ_PIN,LOW);
      delay(100);
      
      Serial.print("Water box low");
      Serial.print(" | ");
      }
  else if (water_value == 0){
      Serial.print("Water box empty !!!!!");
      Serial.print(" | ");
      }
  else{
      Serial.print("Water box level OK");
      Serial.print("\n");
      Serial.print("  ");
      }
  //turn on the led strip
  for (int i = 0; i < water_value; ++i) {
       leds[i] = CRGB(255, 255, 0);
       FastLED.show();
       //delay(500);
  }
//turn off the led strip
  for (int i = water_value; i > 0; --i) {
        leds[i] = CRGB(0, 0, 0);
        FastLED.show();
  }
//read temperature + humidity sensor
  float h = dht.readHumidity();
  float t = dht.readTemperature();//as celsius

  if(isnan(h) || isnan(t)){
    Serial.println("Failed to read DHT sensor");
    Serial.println("");
    return;
    }
    
  //Display message
  Serial.print("Humidity :");
  Serial.print(h);
  Serial.print("%");
  Serial.print("  |  ");
  Serial.print("Temperature :");
  Serial.print(t);
  Serial.print("°C");
  Serial.print("\n");
  Serial.print("\n");
  Serial.print("Level Water = ");
  Serial.print(water_value);
  Serial.print("\n");
  Serial.print("  ");
  delay(500);
  }
}

Credits

candicebobo7

candicebobo7

0 projects • 0 followers

Comments