Hello All,
The project is using the DH11 humidity/ temperature sensor to measure and display via 16x2 lcd. Separately measure soil mosture and turn on the relay for 12v pump.
This has all been tested and is working fine via two separate arduinos on a 12v power supply driven by a solar panel and charge controller.
Please help. Im trying to almalgamate two working sets of code which work fine on thier own onto one arduino. I do not wish to use two Arduinos in this project.
Code one for the temperature/ humity is as follows :
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
dht.begin();// initialize the sensor
lcd.backlight();// turn on lcd backlight
lcd.init();// initialize lcd
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);// set the cursor on the first row and column
lcd.print("H=");
lcd.print((float)dht.readHumidity());//print the humidity
lcd.print("%");
lcd.setCursor(0,1);//set the cursor on the second row and first column
lcd.print("T=");
lcd.print((float)dht.readTemperature());//print the temperature
lcd.print("c");
delay(2000);
lcd.clear();
}
The second set of code for the soil sensor/ relay combo :
int waterPump = 3;
void setup() {
Serial.begin(9600);
pinMode(waterPump, OUTPUT);
}
void loop() {
int humidityRaw = analogRead(A0);
int humidityReal = map(humidityRaw, 1023, 0, 0, 100);
Serial.println(humidityReal);
delay(100);
if (humidityReal > 20)
{
digitalWrite(waterPump, HIGH);
}else{
digitalWrite(waterPump, LOW);
}
}
My attempt at combination :
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11
#define sensorPin A0
#define RELAY_PIN 13
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
dht.begin();// initialize the sensor
lcd.backlight();// turn on lcd backlight
lcd.init();// initialize lcd
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);// set the cursor on the first row and column
lcd.print("H=");
lcd.print((float)dht.readHumidity());//print the humidity
lcd.print("%");
lcd.setCursor(0,1);//set the cursor on the second row and first column
lcd.print("T=");
lcd.print((float)dht.readTemperature());//print the temperature
lcd.print("c");
int value = analogRead(sensorPin);
if(value > 20){
digitalWrite(RELAY_PIN, HIGH);
}else{
digitalWrite(RELAY_PIN, LOW);
}
delay(1000);
lcd.clear();
Apologies in advance if I have broken any rules here Ive tried my best. Any help is greatly appreciated.
Thanks
Jim