Copy the below code if you need to change the plant's environment:
#include < dht.h>
#define dht_apin A3
int Light_OUT_Pin = A2;
#define SensorPin A4
float moistureValue = 0;
boolean humidityFine = false;
const int lightGreen = 13;
const int lightOrange = 12;
float light;
dht DHT;
void setup() {
Serial.begin(9600);
pinMode(lightGreen, OUTPUT);
pinMode(lightOrange, OUTPUT);
delay(1500);
}
void loop() {
light = analogRead(Light_OUT_Pin);
if(light < 900){
digitalWrite(lightGreen, HIGH);
digitalWrite(lightOrange, HIGH);
}
else{
digitalWrite(lightGreen, LOW);
digitalWrite(lightOrange, LOW);
}
Serial.print("light = ");
Serial.println(light);
DHT.read11(dht_apin);
for (int i = 0; i <= 100; i++)
{
moistureValue = moistureValue + analogRead(SensorPin);
delay(1);
} moistureValue = moistureValue / 100.0;
moistureValue=moistureValue*100/1023;
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.println("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("°C ");
Serial.print("Moisture = ");
Serial.print(moistureValue);
Serial.println("%");
delay(30);
delay(3000);
if (DHT.humidity >= 50 && DHT.humidity <= 60) //change 50 and 60 to be whatever value humidity should be{
humidityFine = true;
}
else {
humidityFine = false;
}
if (humidityFine) {
Serial.println("Humidity is perfect to grow plants!");
}
else {
Serial.println("Humidity is not right to grow plants.");
}
}
Contact us:
australiabarns@gmail.com
Lady Musgrave Dr,
Mountain Creek QLD 4557