//#include <Wire.h>
//#include <SPI.h>
//#include <Adafruit_BMP280.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 46// temperature and humidity
int moisture_sensorpin = A0; //initialised sensorpin
int led_pin = 12; //initialised ledpin
int waterpump_pin = 7; //initialised motorpin
int ldrpin1 = A1; //initialised ldrpin
int ldrpin2 = A2; //Garden light intensity
int green_led = 13; //initialised emergency led pin
int rainsensor_pin = A3; //initialised rain detection
int gassensor_pin = A15; //initialised gas detection
int trig_pin = 52; //initialised ultrasonic protection
int echo_pin = A5;
int buzzer_pin = 53;
//#define BMP_SCL 21
//#define BMP_SDA 20
//
//Adafruit_BMP280 bme;
void setup() {
pinMode(moisture_sensorpin, INPUT); //Specifying the declaration of pin to I/O
pinMode(waterpump_pin, OUTPUT);
pinMode(led_pin, OUTPUT);
pinMode(ldrpin1, INPUT);
pinMode(ldrpin2, INPUT);
pinMode(green_led, OUTPUT);
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
pinMode(rainsensor_pin, INPUT);
pinMode(gassensor_pin, INPUT);
Serial.begin(9600); //Serial communication speeds
digitalWrite(waterpump_pin, HIGH);
}
void Garduino_Protocol() {
Serial.print("Welcome to garduino the autonomous caretaker "); // Serial statements to be printed on the serial monitor for intro
Serial.println("of plants !!!");
Serial.println("");
delay(1000);
Serial.println("Today we are going to measure the following qualities for the growth of plants :");
delay(1000);
Serial.println("Temperature");
delay(1000);
Serial.println("Humidity");
delay(1000);
Serial.println("Soil moisture");
delay(1000);
Serial.println("Light intensity");
delay(1000);
Serial.println("Rain sensing");
delay(1000);
Serial.println("Gas sensing");
delay(1000);
// Serial.println("Atmospheric Pressure");
// delay(1000);
// Serial.println("Altitude");
// delay(1000);
Serial.println("There is ultrasonic sensing aswell which ensures that no one interfering with the growth of the plants");
Serial.println("");
delay(1000);
int lightvalue1 = analogRead(ldrpin1);
delay(1000);
int sensorvalue = analogRead(moisture_sensorpin);
int finalvalue = map(sensorvalue,550,0,0,100); //mapping sensor value
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature : "); //printing temperature value
Serial.println(DHT.temperature);
delay(3000);
if (DHT.temperature > 35) {
Serial.println("There is going to be a lot of sunshine, please take protective measures against it");
Serial.println("Irrigating the soil as a protective measure");
digitalWrite(waterpump_pin, LOW);
delay(4000);
digitalWrite(waterpump_pin, HIGH);
Serial.println("");
}
else {
Serial.println("There is less temperature than usual please be prepared");
Serial.println("I dont think watering the soil would make a difference with the present climate");
Serial.println("");
delay(3000);
}
Serial.print("Humidity : "); //printing humidity value
Serial.println(DHT.humidity);
delay(3000);
if (DHT.humidity > 87) {
Serial.println("There are high chance for rain please carry your umbrella with you");
Serial.println("");
delay(3000);
}
else {
Serial.println("There is less humidity take care of your skin");
Serial.println("");
delay(3000);
}
Serial.print("Moisture Content : "); //printing moisture value
Serial.print(finalvalue);
Serial.println("%");
delay(3000);
if (finalvalue > 10) {
Serial.println("The soil has good moisture content, Good to go for the day");
digitalWrite(led_pin, LOW);
digitalWrite(waterpump_pin, HIGH);
Serial.println("");
delay(3000);
}
else {
Serial.println("The soil has very less moisture content, irrigation process about to commence ");
digitalWrite(led_pin, HIGH);
digitalWrite(waterpump_pin, LOW);
delay(10000);
digitalWrite(waterpump_pin, HIGH);
digitalWrite(led_pin, LOW);
Serial.println("Irrigation process completed.");
Serial.println("");
delay(3000);
}
Serial.print("Light intensity : "); //printing light intensity value
Serial.println(lightvalue1);
Serial.println("");
delay(3000);
if (lightvalue1 < 400) {
Serial.println("Please turn on the lights to give the plants some photons for its growth");
Serial.println("");
delay(1000);
}
int rainvalue = analogRead(rainsensor_pin);
int final_rainvalue = map(rainvalue, 550, 0, 0, 100);
Serial.print("Rain sensing value :");
Serial.print(final_rainvalue);
Serial.println("%");
Serial.println("");
delay(3000);
int gasvalue = analogRead(gassensor_pin);
Serial.print("Gas Value :");
Serial.println(gasvalue);
delay(1000);
if (gasvalue < 170) {
digitalWrite(buzzer_pin, LOW);
Serial.println("Nothing to worry the air is perfectly normal and dosent contain any gas");
Serial.println("");
delay(1000);
}
else if (gasvalue > 500) {
Serial.println("There is some diffence in the air please be careful");
Serial.println("");
digitalWrite(buzzer_pin, HIGH);
delay(10000);
}
digitalWrite(trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin, LOW);
long duration = pulseIn(echo_pin, HIGH);
long distance = duration*0.034/2;
Serial.print("Distance :");
Serial.print(distance);
Serial.println("");
if (distance < 60) {
digitalWrite(buzzer_pin, HIGH);
delay(10000);
}
else {
digitalWrite(buzzer_pin, LOW);
}
// if (!bme.begin()) {
// Serial.println("Could not find a valid BMP280 sensor, check wiring!");
// while (1);
//
// }
//
// Serial.print("Pressure = ");
// Serial.print(bme.readPressure());
// Serial.println(" Pa");
// delay(3000);
// Serial.println("");
// Serial.println("");
//
// Serial.print("Approx altitude = ");
// Serial.print(bme.readAltitude(1013.25));
// Serial.println(" m");
// delay(3000);
// Serial.println("");
// Serial.println("");
//
// Serial.print("Temperature = ");
// Serial.print(bme.readTemperature());
// Serial.println(" *C");
// delay(3000);
Serial.println("");
Serial.println("");
}
void Emergency_Protocol() {
Serial.println("Welcome to Emergency_Protocol");
Serial.println("Here we control the light intensity in a room and use it to trigger emergency lights. As the light decreases the emergency lights turn on");
delay(3000);
int lightvalue2 = analogRead(ldrpin2);
delay(3000);
Serial.print("Light Intensity : ");
Serial.println(lightvalue2);
if (lightvalue2 > 700) {
Serial.println("The light intensity is perfect have a good day");
digitalWrite(green_led, LOW);
}
else if (lightvalue2 < 700){
Serial.println("The light intensity is low, switching on to emergency lights");
digitalWrite(green_led, HIGH);
}
Serial.println("");
Serial.println("");
}
void loop() {
Garduino_Protocol();
Emergency_Protocol();
}
Comments
Please log in or sign up to comment.