Hello! I’ve been trying to accomplish this project using open source information, so after building the hole hardware part i started looking and found the MeLion grow box project here. The hardware specs are a little different, instead of an intel edison i use parcel photon, instead of a grove moisture sensor and custom temp sensor i am using a DHT11 to sense the temperature and humidity to control the extraction fan and heating. I’ve been trying to compile a code but ran into some errors, im not much of a coder so i tend to alter other projects code to my project.
code:
// This #include statement was automatically added by the Particle IDE.
#include "PietteTech_DHT/PietteTech_DHT.h"
This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
// system defines
#define DHTTYPE DHT11 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 2 // Digital pin for communications
#define DHT_SAMPLE_INTERVAL 600 // Sample every minute
//declaration
void dht_wrapper(); // must be declared before the lib initialization
// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; //Set token from the Blynk app
char VERSION[64] = "0.04";
#define READ_INTERVAL 60000
// My garden setup
// DHT11 Variables
unsigned int DHTnextSampleTime; // Next time we want to start sample
bool bDHTstarted; // flag to indicate we started acquisition
int n; // counter
// Moisture variables
int humid1;
int moistureBreakpoint = 30;
bool extractionInverter = 0;
// Temperature variables
int temperatureBreakpointLow = 20;
int temperatureBreakpointHigh = 22;
bool heatingInProgress = false;
// Timer variables
unsigned long Timer;
unsigned long milis;
void setup()
{
Serial.begin(9600);
delay(5000);
Blynk.begin(auth);
// Or specify server using one of those commands:
//Blynk.begin(auth, ssid, pass, "server.org", 8442);
//Blynk.begin(auth, ssid, pass, server_ip, port);
pinMode(D1, OUTPUT); //Output for Water Pump relay connection
pinMode(D2, OUTPUT); //Output for Heater relay connection
pinMode(D3, OUTPUT); //Output for Extraction relay connection
// Initial timer setup
Timer = millis();
DHTnextSampleTime = 0; // Start the first sample immediately
}
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
DHT.isrCallback();
}
Serial.println("done setup");
}
void loop()
{
Blynk.run();
// Main function that times and calls all of the other subfunctions
growBoxMaster();
}
void growBoxMaster()
{
// Check if we need to start the next sample
if (millis() > DHTnextSampleTime) {
if (!bDHTstarted) { // start the sample
DHT.acquire();
bDHTstarted = true;
}
if (!DHT.acquiring()) { // has sample completed?
milis = millis();
if(milis - Timer >= 1000UL)
{
Serial.println("********************* Timed pseudoloop execution *********************");
moistureMaster();
heatingMaster();
lightMaster();
Timer = millis();
}
}
void moistureMaster()
{
Serial.println("------- moistureMaster started -------");
float humid = (float)DHT.getHumidity();
int humid1 = (humid - (int)humid) * 100;
char humidInChar[32];
sprintf(humidInChar,"%0d.%d", (int)humid, humid1);
// Converting moisture to virtual and sending to Blynk
moistureVirtual();
// Printing important values
Serial.print("Moisture value - ");
Serial.println(humid1);
Serial.print("moistureBreakpoint - ");
Serial.println(moistureBreakpoint);
if((humid1 < moistureBreakpoint) && !extractionInverter)
{
startExtraction();
}
else if (((humid1 < moistureBreakpoint) && extractionInverter))
{
stopExtraction();
}
else if((humid1 >= moistureBreakpoint) && !extractionInverter)
{
stopExtraction();
}
else if((humid1 >= moistureBreakpoint) && extractionInverter)
{
startExtraction();
}
Serial.print("extractionInverter - ");
Serial.println(extractionInverter);
}
void startExtraction()
{
digitalWrite(2, HIGH);
Blynk.virtualWrite(25, 1023);
Serial.println("Extraction - started");
}
void stopExtraction()
{
digitalWrite(2, LOW);
Blynk.virtualWrite(25, 0);
Serial.println("Extraction - stoped");
}
void heatingMaster()
{
Serial.println("------- heatingMaster started -------");
getTemperature();
if(temp1 < temperatureBreakpointLow && !heatingInProgress)
{
heatingInProgress = true;
startHeating();
}
if(temp1 >= 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()
{
float temp = (float)DHT.getCelsius();
int temp1 = (temp - (int)temp) * 100;
char tempInChar[32];
sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
Blynk.virtualWrite(26, tempInChar);
}
// Getting value of irigationInverter from virtual pin 1
BLYNK_WRITE(V1)
{
bool pinData = param.asInt();
extractionInverter = 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(2, humidInChar);
}
n++; // increment counter
bDHTstarted = false; // reset the sample flag so we can take another
DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL; // set the time for next sample
}
errors:
In file included from blynk/BlynkParticle.h:14:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from blynkt.cpp:5:
blynk/BlynkApiParticle.h:90:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
blynkt.cpp:73:13: error: expected constructor, destructor, or type conversion before '.' token
Timer = millis();
^
blynkt.cpp:74:5: error: expected declaration before '}' token
^
make[1]: *** [../build/target/user/platform-6blynkt.o] Error 1
make: *** [user] Error 2
if any one could help it worth be great! many thanks!
cheers
EDIT:
this is my first complex project and the code is just adapted so there might be syntax and functioning errors