MeLion Growbox system with Blynk

Hi to all,
just want to share my project of using Blynk in agriculture.

/* MeLion GrowBox 0.1 */

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <WiFi.h>
#include <BlynkSimpleIntelEdisonWiFi.h>
#include <Wire.h>
#include <Digital_Light_TSL2561.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; //Set token from the Blynk app

// Your WiFi credentials
char ssid[] = "";        //Set you SSID network name
char pass[] = "";        // Set to "" for open networks

// My garden setup
  // Moisture variables
int moistureValue;
int moistureBreakpoint = 30;
bool irigationInverter = 0;
int moistureValueVirtual;
  // Temperature variables
int temperatureRealValue;
float temperatureRealValueFloat;
float temperatureResistance;
int temperatureSondeValue;
int temperatureBreakpointLow  = 20;
int temperatureBreakpointHigh = 22;
bool heatingInProgress = false;
  // Timer variables
unsigned long Timer;
unsigned long milis;

void setup()
{
  
  Wire.begin();
  Serial.begin(9600);
  delay(5000);
  Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "server.org", 8442);
  //Blynk.begin(auth, ssid, pass, server_ip, port);
  TSL2561.init();

  pinMode(2, OUTPUT); //Output for Water Pump relay connection
  pinMode(3, OUTPUT); //Output for Heater relay connection

  // Initial timer setup
  Timer = millis();

  Serial.println("done setup");
}

void loop()
{
  Blynk.run();

  // Main function that times and calls all of the other subfunctions
  growBoxMaster();
  
}

void growBoxMaster()
{
  milis = millis();
  if(milis - Timer >= 1000UL)
  {
    Serial.println("********************* Timed pseudoloop execution *********************");
    moistureMaster();
    heatingMaster();
    lightMaster();
    Timer = millis();
  }
}

void moistureMaster()
{
  Serial.println("------- moistureMaster started -------");
  
  // Getting analog value of moisture
  moistureValue = analogRead(A0);
  // Mapping moisture to 0-100 scale
  moistureValue = map(moistureValue, 0, 800, 0, 100);
  // Converting moisture to virtual and sending to Blynk
  moistureVirtual();

  // Printing important values
  Serial.print("Moisture value - ");
  Serial.println(moistureValue);
  Serial.print("moistureBreakpoint - ");
  Serial.println(moistureBreakpoint);
  
  if((moistureValue < moistureBreakpoint) && !irigationInverter)
  {
    startIrigation();
  }
  else if (((moistureValue < moistureBreakpoint) && irigationInverter))
  {
    stopIrigation();
  }
  else if((moistureValue >= moistureBreakpoint) && !irigationInverter)
  {
    stopIrigation();
  }
  else if((moistureValue >= moistureBreakpoint) && irigationInverter)
  {
    startIrigation();
  }
  
  Serial.print("irigationInverter - ");
  Serial.println(irigationInverter);
  
}

void startIrigation()
{
  digitalWrite(2, HIGH);
  Blynk.virtualWrite(25, 1023);
  Serial.println("Irigation - started");
}

void stopIrigation()
{
  digitalWrite(2, LOW);
  Blynk.virtualWrite(25, 0);
  Serial.println("Irigation - stoped");
}

void heatingMaster()
{
  Serial.println("------- heatingMaster started -------");

  getTemperature();

  if(temperatureRealValue < temperatureBreakpointLow && !heatingInProgress)
  {
    heatingInProgress = true;
    startHeating();
  }
  if(temperatureRealValue >= temperatureBreakpointHigh && heatingInProgress) 
  {
    heatingInProgress = false;
    stopHeating();
  }

  Serial.print("temperatureRealValue - ");
  Serial.println(temperatureRealValue);

  Serial.print("heatingInProgress - ");
  Serial.println(heatingInProgress);

  Serial.print("temperatureBreakpointLow - ");
  Serial.println(temperatureBreakpointLow);

  Serial.print("temperatureBreakpointHigh - ");
  Serial.println(temperatureBreakpointHigh);
}

void startHeating()
{
  digitalWrite(3, HIGH);
  Blynk.virtualWrite(24, 1023);
  Serial.println("Heating - started");
}

void stopHeating()
{
  digitalWrite(3, LOW);
  Blynk.virtualWrite(24, 0);
  Serial.println("Heating - stoped");
}

void getTemperature()
{
  temperatureSondeValue = analogRead(A3);
  temperatureResistance = (float)(1023 - temperatureSondeValue) * 10000/temperatureSondeValue; //get the resistance of the sensor;
  temperatureRealValueFloat  = 1/(log(temperatureResistance/10000)/3975+1/298.15)-273.15;//convert to temperature via datasheet&nbsp;;
  temperatureRealValue = (int)temperatureRealValueFloat;
  Blynk.virtualWrite(26, temperatureRealValue);
}

void lightMaster()
{
  Serial.println("------- lightMaster started -------");
  lightVirtual();
  Serial.print("The Light value is: ");
  
  //Serial.println(TSL2561.readVisibleLux());
}

// Getting value of irigationInverter from virtual pin 1
BLYNK_WRITE(V1)
{
  bool pinData = param.asInt();
  irigationInverter = pinData;
}

// Getting value of moistureBreakpoint from virtual pin 2
BLYNK_WRITE(V2)
{
  int pinData = param.asInt();
  moistureBreakpoint = pinData;
}

// Getting value of temperatureBreakpointLow from virtual pin 4
BLYNK_WRITE(V4)
{
  int pinData = param.asInt();
  temperatureBreakpointLow = pinData;
}

// Getting value of temperatureBreakpointHigh from virtual pin 5
BLYNK_WRITE(V5)
{
  int pinData = param.asInt();
  temperatureBreakpointHigh = pinData;
}

void moistureVirtual()
{
  Blynk.virtualWrite(23, moistureValue);
}

void lightVirtual()
{
  Blynk.virtualWrite(28, TSL2561.readVisibleLux());
}

It is Growbox system with Intel Edison that use moisture sensor, temperature sensor and light sensor to manage with 6v mini water pump, flat foil heater and led light.

If you like this project you can VOTE for my project on instructables site :slight_smile:
here is a link http://www.instructables.com/id/MeLion-Growbox-system/

4 Likes

Great! Thanks for sharing! Glad you used the sharing QR code.
This is so awesome!

Yaaaay! Nice. What can you say about Blynk itself?

Thanks alot.
I’m so glad to have app like Blynk to use it in my project.
Testing the Blynk app with Intel Edison for some time and have some problems but in the and I have finish it.
Intel Edison don’t work the SimpleTimer.h so I be forced to use my timer in the end. He don’t give me to upload the sketch tell me to have some problem with milisecondscycles or something like that, but I can tell you exactly tomorrow If you want.
Because Intel Edison can’t use DHT library I can’t use DHT11 sensor, and because of that I was forced to use analog temperature sensor with thermistor. I have problem with the digital sensor too because when he sense the light he work and when it’s dark he stops responding with my console.

All Blynk widgets work work proparly, but I have 250ms ping with your server (my country Serbia). For some projects that’s OK like with my, but on some where need fast response probably must use local servers.

If you have any questions feel free to ask me :smile:

Hey MeLion, are u interested in making a growbox controller for hydroponics with blynk and arduino mega? It would involve making arduino capable of running without blynk, but with blynk you can control every thing, (min water in res, in pots, water temp, gb tem/hum, etc), with new widgets and blynk design? =)

*edit - basically, so people can easily plug everything, and have a pro grade hydroponic box in their homes…

@Vo_Pa Please take note of time & date stamps BEFORE posting… this topic is over two years old :stuck_out_tongue: