Alicia ChuahNARENDRANDani ZakyVladislav CherskoyAli Zahid
Published

Automated Vertical Farming

A system using light, soil moisture and humidity sensors to control the water, light and humidity needed by the vertical farm.

IntermediateFull instructions provided24 hours1,584
Automated Vertical Farming

Things used in this project

Hardware components

Arduino Uno Rev3
Seeed Studio Arduino Uno Rev3
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DHT22 temperature-humidity sensor
Adafruit DHT22 temperature-humidity sensor
×1
Micro Submersible Water Pump DC 3V-5V
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Digital Light Intensity BH1750FVI Sensor Module
×2
3V-5V 0.2A Cooling Fan for RPi with Screws
×2
Single Channel 5V Relay Breakout Board
×1
2 Channel 5V Active Low Relay Module
×1
4xAA battery holder
4xAA battery holder
×3
Battery Holder, AA x 3
Battery Holder, AA x 3
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Code

Final Assignment Code

Arduino
#define BLYNK_TEMPLATE_ID           "TMPL6BtHcHcBz"
#define BLYNK_TEMPLATE_NAME         "gui"
#define BLYNK_AUTH_TOKEN            "7lbErGB2plF-rZW2XY3q5YqAkH2NdUbt"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <DHT.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Wire.h>
#include <BH1750.h>
BH1750 GY30_1;
BH1750 GY30_2;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "D-20-09";
char pass[] = "0189718976";
#define DHTPIN 4            // Defines pin number of humidity sensor
#define DHTTYPE DHT22       // Define DHT Type
DHT dht(DHTPIN, DHTTYPE);   // Create DHT Object
#define FAN_PIN_1 6 // Relay channel pin to fan1
#define FAN_PIN_2 7 // Relay channel pin to fan2
#define light_relay_pin1  9 // Relay channel pin to light2 (Connections are reversed)
#define light_relay_pin2  8 // Relay channel pin to light1 (Connection are reversed)
#define pump_relay 13 
#define SoilMoisturePin A3   // Soil moisture sensor data input
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
BlynkTimer timer;


float humidity;
float temperature;
float moisture_percentage;
int sensor_analog1;
float lux1;
float lux2;



void moisture_sensor()
{
  
  sensor_analog1 = analogRead(SoilMoisturePin);
  moisture_percentage = ( 100 - ( (sensor_analog1/1023.00) * 100 ) );
  Blynk.virtualWrite(V4, moisture_percentage);
  Serial.print(" moisture_percentage = ");
  Serial.println(moisture_percentage);
}
void pump_control()
{
  if (moisture_percentage <= 78 )
  {
    digitalWrite(pump_relay, LOW);
  }
  else 
  {
    digitalWrite(pump_relay, HIGH);
  }
}
void HumiditySensor()
{
  humidity = dht.readHumidity();
  Serial.print("Humidity = ");
  Serial.print(humidity);
  Serial.println(" % ");
  Serial.println(""); 

  if (isnan(humidity))
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, humidity);
}
void TempSensor()
{
  temperature = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.print(" ");
  Serial.print("C | ");
  Serial.print((temperature * 9.0) / 5.0 + 32.0);//print the temperature in Fahrenheit


  if (isnan(temperature)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V1, temperature);
}
void fan_control_1()
{
  if (humidity >= 80)
  {
    digitalWrite(FAN_PIN_1, LOW);
  }

  else 
  {
    digitalWrite(FAN_PIN_1, HIGH);
  }
}
void fan_control_2()
{
  if (humidity >= 80)
  {
    digitalWrite(FAN_PIN_2, LOW);
  }

  else 
  {
    digitalWrite(FAN_PIN_2, HIGH);
  }
}
void light_sensor1() 
{

  lux1 = GY30_1.readLightLevel();
  Serial.print ("lux reading 1: ");
  Serial.print (lux1);
  Blynk.virtualWrite(V2, lux1);
  delay(1000);
}
void light_sensor2() 
{
  lux2 = GY30_2.readLightLevel();
  Serial.print ("| lux reading 2: ");
  Serial.println (lux2);
  Blynk.virtualWrite(V3, lux2);
  delay(1000);
}
void light_control1()
{
  if (lux1 <= 50)
  {
    digitalWrite(light_relay_pin1, LOW);
  }

  else 
  {
    digitalWrite(light_relay_pin1, HIGH);
  }
}
void light_control2()
{
  if (lux2 <= 50)
  {
    digitalWrite(light_relay_pin2, LOW);
  }

  else 
  {
    digitalWrite(light_relay_pin2, HIGH);
  }
}


void myTimerEvent(){
  HumiditySensor();
  TempSensor();
  light_sensor1();
  light_sensor2();
  moisture_sensor();
  fan_control_1();
  fan_control_2();
  light_control1();
  light_control2();
  pump_control();}
void setup(){
  Serial.begin(9600);
  digitalWrite(FAN_PIN_1, HIGH);
  digitalWrite(FAN_PIN_2, HIGH);
  pinMode(FAN_PIN_2, OUTPUT);
  pinMode(FAN_PIN_1, OUTPUT);
  digitalWrite(pump_relay, HIGH);
  pinMode(pump_relay, OUTPUT);
  digitalWrite(light_relay_pin1, HIGH);
  digitalWrite(light_relay_pin2, HIGH);
  pinMode(light_relay_pin1, OUTPUT);
  pinMode(light_relay_pin2, OUTPUT);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
  dht.begin();
  Wire.begin();
  GY30_1.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23);
  GY30_2.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x5C);
  timer.setInterval(5000L, myTimerEvent); }
void loop(){
  Blynk.run();
  timer.run();}

Credits

Alicia Chuah

Alicia Chuah

1 project • 3 followers
NARENDRAN

NARENDRAN

20 projects • 22 followers
Dani Zaky

Dani Zaky

0 projects • 1 follower
Bachelor of Mechatronic Engineering, APU
Vladislav Cherskoy

Vladislav Cherskoy

0 projects • 1 follower
Ali Zahid

Ali Zahid

0 projects • 1 follower

Comments