Hey everyone,
I made a Smart plant care System as a school project.
The main goal of this system is to respond to environmental conditions(Watering the plants and activate a light). But the system has a lot more features such as Arduino cloud communication and Displaying values(Brightness, Soil Moisture, Humidity, Temperature) in the form of an LCD Display and RGB LED.
| Part | Quantity |
|---|---|
| Uno R4 WIFI | 1 |
| 16x2 LCD | 1 |
| RGB LED | 1 |
| Light sensor | 1 |
| DHT11 sensor | 1 |
| Soil Mois. sens. | 1 |
| Relais | 1 |
| BC547 NPN | 1 |
| 5V pump | 1 |
| Capacitor 470qf | 1 |
| 0,5ohm resistor | 1 |
| LED | 1 |
| Battery | 1 |
| Jumper wires | at least 17 |
The Code:
#include "thingProperties.h"
#include <Bonezegei_DHT11.h>
#include <LiquidCrystal.h>
const int DHT11_PIN = 6;
const int LED_PIN = 7;
const int PUMP_PIN = 8;
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int rs = 13, en = 12, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int THRESHOLT_LED_OFF = 500;
const int THRESHOLT_LED_ON = 700;
const int THRESHOLT_MOISTURE = 500;
static bool LIGHT_FLAG = false;
Bonezegei_DHT11 dht(DHT11_PIN);
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
dht.begin(); //Temperature / Humidity Sensor
pinMode(LED_PIN, OUTPUT); //Plant Light
pinMode(PUMP_PIN, OUTPUT); //pump
pinMode(GREEN_LED_PIN, OUTPUT); // reen pwm status light
pinMode(RED_LED_PIN, OUTPUT); //red pwm status light
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
initProperties();
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
lcd.setCursor(0, 0);
LIGHT = analogRead(A0);
MOISTURE = analogRead(A1);
TEMPDEG = dht.getTemperature();
HUM = dht.getHumidity();
int humA = constrain(abs(HUM - 55) * 50 , 0, 1000); //analyse data and return a value of how bad the enviromental conditionas are on a scale from 0 to 1000.
int lightA = constrain(abs(LIGHT - 300) * 3.33, 0, 1000); // f(x)=(x-300)*3,33 D={0;1000}
int tempdegA = constrain(abs(TEMPDEG - 22) * 250 , 0, 1000);
int moistureA = constrain(abs(MOISTURE - 500)* 5 , 0, 1000);
val = (humA + lightA + tempdegA + moistureA) / 15.67; //adds all numbers together and returns a value between 0-255
analogWrite(GREEN_LED_PIN, val); //green
analogWrite(RED_LED_PIN , (255 - val)); //Red pwm leds which indecate if the enviromental conditions are bad(red), fine(orange), mid(yellow), good(light green), very good (green)
String x = "HumidityA:";
x += humA;
x += " LightA:";
x += lightA;
x += " TemperatureA:";
x += tempdegA;
x += " MoistureA:";
x += moistureA;
x += " Result:";
x += val;
Serial.println(x.c_str()); //string(x.c_str) can be removed after dev
dht.getData();
String up = "TEMP";
up += String(TEMPDEG).substring(0, String(TEMPDEG).indexOf(".") + 2);
up += "C|HUM";
up += HUM;
up += "%";
Serial.println(up.c_str());
lcd.print(up.c_str());
lcd.setCursor(0, 1);
String low = "LIGHT";
low += LIGHT;
low += " |MOI";
low += MOISTURE;
Serial.println(low.c_str());
lcd.print(low.c_str());
if (!LIGHT_FLAG && LIGHT> THRESHOLT_LED_ON) //turn on the lamp if it is too dark
{
digitalWrite(LED_PIN, HIGH);
Serial.println("LIGHT ON");
LIGHT_FLAG = true;
}
else if(LIGHT_FLAG && LIGHT <THRESHOLT_LED_OFF )
{
digitalWrite (LED_PIN, LOW);
LIGHT_FLAG = false;
}
if (MOISTURE > THRESHOLT_MOISTURE)// Activates the pump if the soil is too dry
{
digitalWrite(PUMP_PIN, HIGH);
Serial.println("PUMP ON");
}
else
{
digitalWrite(PUMP_PIN, LOW);
};
delay(500);
Serial.println("-------------------------------------------------------------");
}
