Kelsie CrossAustin MichaelChristopher Voetsch
Published

Plant/Greenhouse Monitor

A wifi enabled plant/greenhouse monitor with temperature/humidity, raindrop, and soil moisture sensors.

BeginnerWork in progress148
Plant/Greenhouse Monitor

Things used in this project

Hardware components

Argon
Particle Argon
×3
Sensor Modules Kit Including DHT11, Soil Moisture, and Raindrop Sensors
×1

Story

Read more

Schematics

Temperature/Humidity Sensor Circuit

Soil Moisture Sensor Circuit

Raindrop Sensor Circuit

Code

Soil Moisture Code

C/C++
Code uploaded to the soil moisture capturing argon
/* this code is basically tinker modified to read a value, publish, and subscribe */ 

 int temp = 0;
 int TempF = 0;

 
 
/* Function prototypes -------------------------------------------------------*/
int tinkerDigitalRead(String pin);
int tinkerDigitalWrite(String command);
int tinkerAnalogRead(String pin);
int tinkerAnalogWrite(String command);

/* This function is called once at start up ----------------------------------*/
void setup()
{
    pinMode(D7, OUTPUT);    // sets pin as output
    Particle.subscribe("TempF",temperaturefunction); //when TempF occurs in the cloud, run the temperaturefunction
    
	//Setup the Tinker application here

	//Register all the Tinker functions
	Particle.function("digitalread", tinkerDigitalRead);
	Particle.function("digitalwrite", tinkerDigitalWrite);
	Particle.function("analogread", tinkerAnalogRead);
	Particle.function("analogwrite", tinkerAnalogWrite);
}

/* This function loops forever --------------------------------------------*/
void loop()
{
    
    delay(1800000);
    
    temp = analogRead(A0);
    
    Particle.publish("Soil_Moisture", String(temp));	
	
}

void temperaturefunction() //this turns the D7 pin (has LED) on when TempF is greater than 100
{
	if (TempF > 100) {
	    (digitalWrite(D7, HIGH);
	}
}


/*******************************************************************************
 * Function Name  : tinkerDigitalRead
 * Description    : Reads the digital value of a given pin
 * Input          : Pin
 * Output         : None.
 * Return         : Value of the pin (0 or 1) in INT type
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerDigitalRead(String pin)
{
	//convert ascii to integer
	int pinNumber = pin.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(pin.startsWith("D"))
	{
		pinMode(pinNumber, INPUT_PULLDOWN);
		return digitalRead(pinNumber);
	}
	else if (pin.startsWith("A"))
	{
		pinMode(pinNumber+10, INPUT_PULLDOWN);
		return digitalRead(pinNumber+10);
	}
	return -2;
}

/*******************************************************************************
 * Function Name  : tinkerDigitalWrite
 * Description    : Sets the specified pin HIGH or LOW
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 * 
 *******************************************************************************/
int tinkerDigitalWrite(String command)
{
	bool value = 0;
	//convert ascii to integer
	int pinNumber = command.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(command.substring(3,7) == "HIGH") value = 1;
	else if(command.substring(3,6) == "LOW") value = 0;
	else return -2;

	if(command.startsWith("D"))
	{
		pinMode(pinNumber, OUTPUT);
		digitalWrite(pinNumber, value);
		return 1;
	}
	else if(command.startsWith("A"))
	{
		pinMode(pinNumber+10, OUTPUT);
		digitalWrite(pinNumber+10, value);
		return 1;
	}
	else return -3;
}

/*******************************************************************************
 * Function Name  : tinkerAnalogRead
 * Description    : Reads the analog value of a pin
 * Input          : Pin
 * Output         : None.
 * Return         : Returns the analog value in INT type (0 to 4095)
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerAnalogRead(String pin)
{
	//convert ascii to integer
	int pinNumber = pin.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(pin.startsWith("D"))
	{
		return -3;
	}
	else if (pin.startsWith("A"))
	{
		return analogRead(pinNumber+10);
	}
	return -2;
}

/*******************************************************************************
 * Function Name  : tinkerAnalogWrite
 * Description    : Writes an analog value (PWM) to the specified pin
 * Input          : Pin and Value (0 to 255)
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerAnalogWrite(String command)
{
	//convert ascii to integer
	int pinNumber = command.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	String value = command.substring(3);

	if(command.startsWith("D"))
	{
		pinMode(pinNumber, OUTPUT);
		analogWrite(pinNumber, value.toInt());
		return 1;
	}
	else if(command.startsWith("A"))
	{
		pinMode(pinNumber+10, OUTPUT);
		analogWrite(pinNumber+10, value.toInt());
		return 1;
	}
	else return -2;
}

Raindrop Sensor Code

C/C++
Code uploaded to the argon which has the raindrop sensor installed
#define DHTPIN D6

int temp = 0; /*initalizing the rain value */
int TempF = 0; /*initalizing the temperature value */
 
void setup() {
pinMode (A0, INPUT);

pinMode(D7, OUTPUT);    // sets pin (which has an LED) as output
}

void loop() {
    
    temp = analogRead(A0);
    
Particle.publish("Is it raining?", String(temp));


delay(60000);
}

void temperaturefunction() //this turns the D7 pin (has LED) on when TempF is greater than 100
{
	if (TempF > 100) {
	    (digitalWrite(D7, HIGH);
	}
}

Temperature/Humidity Sensor Code

C/C++
Code uploaded to the argon connected to the temperature/humidity sensor
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>


// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D6     // what pin we're connected to

// Here we define the type of sensor used
#define DHTTYPE DHT11        // DHT 11

DHT dht(DHTPIN, DHTTYPE);

bool humid = false;

void setup() {

 pinMode(D7, OUTPUT);
 Serial.begin(9600);
 dht.begin();


}

void loop() {
    // Wait a few seconds between measurements.
    delay(65000);

    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds
    float h = dht.getHumidity();
    // Read temperature as Celsius
    float t = dht.getTempCelcius();
    // Read temperature as Farenheit
    float f = dht.getTempFarenheit();


   
    Particle.publish("TempF", String (f));
    Particle.publish("Humidity", String (h));

  Serial.print(dht.getHumidity());
  Serial.println("h");
  Serial.print(dht.getTempFarenheit());
  Serial.println("t");

 

}

Credits

Kelsie Cross

Kelsie Cross

1 project • 0 followers
Austin Michael

Austin Michael

1 project • 0 followers
Christopher Voetsch

Christopher Voetsch

1 project • 0 followers

Comments