Hi everyone,
I'm no expert at this programming stuff and I've been cracking my head for a few days now to figure out how to incorporate a temperature and humidity controlled relay.
Here lies the problem :
Right now I have yet to put in my digital pins because I have already tried to insert then and were running with the delay of my DHT readings, turning on during the reading and instantly turns off!!! I've read about the Blink Without Delay, switch case and a lot more other options... Now I'm just not sure how to make multiple readings and different reactions for different situations...
Just some input would be great!!!
Thank you for your help
//Library for SainSmart LCD 20x4 I2C
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#define lcdAddr 0x27
LiquidCrystal_I2C lcd(lcdAddr, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//Library for DHT Sensor
#include "DHT.h"
#define DHTTYPE DHT11
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE);
//Library for Button
#include <Button.h>
//Library for Datalogger
#include <SD.h>
#include <SPI.h>
const int chipSelect = 10;
//Basic Libraries
#include <Wire.h>
void setup() {
//Setup for DHT
Serial.begin(9600);
Serial.println("DHT Readings");
dht.begin();
//Setup for Datalogging
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
//Setup for LCD Display
lcd.begin(20,4);
//Relay pins
}
void loop() {
//Loop for DHT Sensor
delay (5000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
//Loop for datalogger
String dataString = "";
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
else {
Serial.println("error opening datalog.txt");
}
//Water Level Analog Sensor
//Relay loop
//LCD Display
lcd.setBacklight(1);
lcd.home();
lcd.print("Temperature");
lcd.setCursor(0,1);
lcd.print(t);
lcd.print("*C");
lcd.setCursor(0,2);
lcd.print("Humidity");
lcd.setCursor(0,3);
lcd.print(h);
lcd.print("*%");
}
Greenhouse_Controller_v_1.ino (2.54 KB)