Project codes

Automatic Plant Watering system( https://www.youtube.com/watch?v=DJx9yr-7Guc)-

include “dht.h”

define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

include

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
const int pump = 7;
int temp;
int hum;
int water = 9000;
const int onhour1 = 6;
const int onhour2 = 18;
int on1 = 0;
int on2 = 0;

void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}

// Initialize the rtc object
rtc.begin();
pinMode(pump, OUTPUT);
digitalWrite(pump, HIGH);

// The following lines can be uncommented to set the date and time
//rtc.setDOW(SATURDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(18, 11, 30); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(22, 3, 2020); // Set the date to January 1st, 2014
DHT.read11(dht_apin);

}

void loop()

{

Time t;
t = rtc.getTime ();
Serial.println(rtc.getTimeStr());

if (DHT.humidity>70 && DHT.humidity<90 ) {
water = water-1000;
}

else if (DHT.humidity>90) {
water = water-2000;
}
Serial.println(rtc.getTimeStr());
if (DHT.temperature<20){
water = water-1000;
}

else if (DHT.temperature>20 && DHT.temperature<30){ water = 9000; } else if (DHT.temperature>30 && DHT.temperature<40){
water = water + 1000;
}

else if (DHT.temperature>40){
water = water + 2000;
}

// Send time
Serial.println(rtc.getTimeStr());
Serial.println(t.min);
delay(1000);

if (t.hour == onhour1 && on1 == 0){
digitalWrite(pump,LOW);
Serial.println(“Pump on”);
delay(water);
digitalWrite(pump,HIGH);
Serial.println(“Pump off”);
on1 = 1;
}

if (DHT.humidity>70 && DHT.humidity<90 ) {
water = water-1000;
}

else if (DHT.humidity>90) {
water = water-2000;
}
if (DHT.temperature<20){
water = water-1000;
}

else if (DHT.temperature>20 && DHT.temperature<30){ water = 9000; } else if (DHT.temperature>30 && DHT.temperature<40){
water = water + 1000;
}

else if (DHT.temperature>40){
water = water + 2000;
}

// Send time
Serial.println(rtc.getTimeStr());
Serial.println(t.min);
delay(1000);

if (t.hour == onhour2 && on2 == 0){
digitalWrite(pump,LOW);
Serial.println(“Pump on”);
delay(water);
digitalWrite(pump,HIGH);
Serial.println(“Pump off”);
on2 = 1;
}

}

Automatic pet feeder( https://www.youtube.com/watch?v=RjjajBdbRLw )-

include <Servo.h>

include <DS3231.h>

Servo qservo;
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
const int led = 2;
const int buzz = 4;
const int onhour1 = 12;
const int onmin1 = 1;
const int onhour2 = 12;
const int onmin2 = 2;
const int onhour3 = 12;
const int onmin3 = 3;
const int onhour4 = 12;
const int onmin4 = 4;
const int onhour5 = 12;
const int onmin5 = 5;
const int onhour6 = 12;
const int onmin6 = 6;
const int onhour7 = 12;
const int onmin7 = 7;
const int onhour8 = 11;
const int onmin8 = 16;
const int onhour9 = 11;
const int onmin9 = 17;
const int onhour10 = 11;
const int onmin10 = 18;
Time t;
void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}

// Initialize the rtc object
rtc.begin();
pinMode(led, OUTPUT);
pinMode(buzz, OUTPUT);
digitalWrite(led, HIGH);
qservo.attach(6);

// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(11, 22, 0); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(16, 10, 2019); // Set the date to January 1st, 2014
}

void loop()

{
t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour1 && t.min == onmin1) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);
}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour2 && t.min == onmin2) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);
}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour3 && t.min == onmin3) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}

t = rtc.getTime ();

Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour4 && t.min == onmin4) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour5 && t.min == onmin5) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour6 && t.min == onmin6) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);
}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour7 && t.min == onmin7) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);
}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour8 && t.min == onmin8) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}

t = rtc.getTime ();

Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour9 && t.min == onmin9) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}

t = rtc.getTime ();
Serial.print(rtc.getDOWStr());
Serial.print(” “);

// Send date
Serial.print(rtc.getDateStr());
Serial.print(” — “);

// Send time
Serial.println(rtc.getTimeStr());
delay(1000);

if (t.hour = onhour10 && t.min == onmin10) {
qservo.write(-90);
delay(2000);
qservo.write(90);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(200);
digitalWrite(buzz, HIGH);
delay(200);
digitalWrite(buzz, LOW);
delay(57400);

}
digitalWrite(led, LOW);

}