The Final Product + Code

include <Wire.h>

include <RTClib.h>

include <Adafruit_Sensor.h>

include “Adafruit_BME680.h”

include <PCD8544.h>

// LCD

static PCD8544 lcd;

// Pump

define RELAY 12

// Vent

define VENT 9

Adafruit_BME680 bme; // I2C

// Moisture sensor

define START 2

define MEASURE A0

int sensorValue = 0;

//LED

define LED 8

//Tid

RTC_DS1307 RTC;

DateTime now;

void Tid() {

now = RTC.now();

Serial.print(now.year(), DEC);

Serial.print(‘/’);

Serial.print(now.month(), DEC);

Serial.print(‘/’);

Serial.print(now.day(), DEC);

Serial.print(‘ ‘);

Serial.print(now.hour(), DEC);

Serial.print(‘:’);

Serial.print(now.minute(), DEC);

Serial.print(‘:’);

Serial.print(now.second(), DEC);

Serial.println();

delay(1000);

}

void setup() {

Serial.begin(115200);

Wire.begin();

RTC.begin();

// Moisture

pinMode(START, OUTPUT);

// LCD

lcd.begin(84, 48);

// Pumpe

pinMode(RELAY, OUTPUT);

// Vent

pinMode(VENT, OUTPUT);

//LED

pinMode(LED, OUTPUT);

// Tid

RTC.adjust(DateTime(DATE, TIME));

Vand();

}

void loop() {

// Temp & Hum

!bme.begin();

bme.beginReading();

delay (5000);

bme.endReading();

Tid();

if (now.hour() > 7 && now.hour() < 20 && now.minute() > 58) {

Vand();

}

// Pumpe

if (sensorValue < 100) {

Pump();

// Lad vandet synke ned

delay(10000);


// Mål igen

Vand();

}

// Vent

if (bme.temperature > 22) {

digitalWrite(VENT, HIGH);

} else {

digitalWrite(VENT, LOW);

}

//LED

if (now.hour()>7 && now.hour()<20) {

digitalWrite(LED, HIGH);

} else {

digitalWrite(LED, LOW);

}

LCD1();

LCD2();

LCD3();

LCD4();

}

void Vand() {

digitalWrite(START, HIGH);

delay(500);

sensorValue = analogRead(MEASURE);

delay(5000);

digitalWrite(START, LOW);

}

void Pump() {

digitalWrite(RELAY, HIGH);

delay(10000);

digitalWrite(RELAY, LOW);

}

void LCD1() {

lcd.setCursor(0, 0);

lcd.print(F(“LT = “));

lcd.print(bme.temperature);

lcd.println(F(” C”));

Serial.print(F(“LT = “));

Serial.print(bme.temperature);

Serial.println(F(” C”));

}

void LCD2() {

lcd.setCursor(0, 1);

lcd.print(F(“LF = “));

lcd.print(bme.humidity);

lcd.println(F(“%”));

Serial.print(F(“LF = “));

Serial.print(bme.humidity);

Serial.println(F(“%”));

}

void LCD3() {

lcd.setCursor(0, 2);

lcd.print(“VN = ” );

lcd.println(sensorValue);

Serial.print(“VN = ” );

Serial.println(sensorValue);

}

void LCD4() {

Tid();

// Plotting af tid

lcd.setCursor(0, 3);

lcd.print(“TID = ” );

lcd.print(now.hour(), DEC);

lcd.print(‘.’);

lcd.print(now.minute(), DEC);

lcd.print(‘.’);

lcd.print(now.second(), DEC);

lcd.println();

}


Comments

Your AI Matches

To navigate
Press Enter to select