me and my team mate tried to do a green house system project,
we separate our work to two parts
I did temperature and humidity control
he did LCD screen which showing current temp and humidity . and also an fan control
we were doing great separately.
unfortunately, when we put the codes together, it got stuck.
my idea is :use two relays to control two electrical outlet, one plug with heater, one plug with a humidifier.
and here is my code
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 7
int pinOut1 = 8;
int pinOut2 = 10;
void setup()
{
Serial.begin(9600);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
DHT11.read(DHT11PIN);
Serial.print("tempetature =");
Serial.print(DHT11.temperature);
Serial.print(" C");
Serial.print('\n');
Serial.print("humidity =");
Serial.print(DHT11.humidity);
Serial.print('\t');
Serial.println("%");
Serial.print('\n');
if (DHT11.temperature <= 20)
{
digitalWrite(pinOut1,HIGH);
}
else{
digitalWrite(pinOut1,LOW);
}
delay( 1000);
if (DHT11.humidity <= 40)
{
digitalWrite(pinOut2,HIGH);
}
else{
digitalWrite(pinOut2,LOW);
}
delay( 1000);
}
then is his code
#include <Wire.h>
#include "rgb_lcd.h"
#include "DHT.h"
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht11(DHTPIN, DHTTYPE);
rgb_lcd lcd;
int fan = 10;
void setup()
{
Serial.begin(9800);
pinMode(fan, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
dht11.begin();
}
void loop()
{
int pot = analogRead(A0);
int fan_speed = pot * (255 / 1023.0);
analogWrite(fan,fan_speed);
Serial.println(fan_speed);
delay(10);
char _buffer[14];
int humi = dht11.readHumidity() * 10;
int temp = dht11.readTemperature() * 10;
if(temp < 0)
sprintf(_buffer, "TEMP =-%02u.%1u%cC", abs(temp)/10, abs(temp) % 10, 223);
else
sprintf(_buffer, "TEMP = %02u.%1u%cC", temp/10, temp % 10, 223);
lcd.setCursor(0, 0);
lcd.print(_buffer);
Serial.println(_buffer);
sprintf(_buffer, "HUMD = %02u.%1u %%", humi/10, humi % 10);
lcd.setCursor(0, 1);
lcd.print(_buffer);
Serial.println(_buffer);
delay(2000);
}
when I tried put them together, the pin 8 and pin 9 seems doesn't work, I already tried every thing I can, please help.....
#include <Wire.h>
#include "rgb_lcd.h"
#include "DHT.h"
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht11(DHTPIN, DHTTYPE);
rgb_lcd lcd;
int fan = 9;
int pinOut1 = 8;
int pinOut2 = 10;
void setup()
{
Serial.begin(9800);
pinMode(fan, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
dht11.begin();
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
int pot = analogRead(A0);
int fan_speed = pot * (255 / 1023.0);
analogWrite(fan,fan_speed);
Serial.println(fan_speed);
delay(10);
char _buffer[14];
int humi = dht11.readHumidity() * 10;
int temp = dht11.readTemperature() * 10;
if(temp < 0)
sprintf(_buffer, "TEMP =-%02u.%1u%cC", abs(temp)/10, abs(temp) % 10, 223);
else
sprintf(_buffer, "TEMP = %02u.%1u%cC", temp/10, temp % 10, 223);
lcd.setCursor(0, 0);
lcd.print(_buffer);
Serial.println(_buffer);
sprintf(_buffer, "HUMD = %02u.%1u %%", humi/10, humi % 10);
lcd.setCursor(0, 1);
lcd.print(_buffer);
Serial.println(_buffer);
delay(2000);
if ( temp <= 20)
{
digitalWrite(pinOut1,HIGH);
}
else{
digitalWrite(pinOut1,LOW);
}
delay( 1000);
if (humi<= 40)
{
digitalWrite(pinOut2,HIGH);
}
else{
digitalWrite(pinOut2,LOW);
}
delay( 1000);
}
thanks if you can have a look