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 ;
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
here is a link http://www.instructables.com/id/MeLion-Growbox-system/