me and my teammate try to make a project of greens house system
we debug for several day and there is one more question left
we set fan motor to PIN 10, adding condition when temperature is >=26 ,the fan will be on.
it actually work, however, the fan run only about 5 second, when the void loop repeat, it stop.
i guess it might be the time of whole loop too short,.
can someone help me to fix this problem, let the fan stop, when only the temperature reach the degree we set, here is our 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;
int pinOut1 = 8;
int pinOut2 = 9;
void setup()
{
Serial.begin(9800);
pinMode(fan, OUTPUT);
Serial.begin(9600);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
lcd.begin(16, 2);
dht11.begin();
}
void loop()
{
int pot = analogRead(A1);
int fan_speed = pot * (255 / 1023.0);
analogWrite(fan,fan_speed);
Serial.println(fan_speed);
delay(101 );
char _buffer[14];
int humi = dht11.readHumidity() * 10;
int temp = dht11.readTemperature() * 10;
int humidity = dht11.readHumidity() ;
int temperature = dht11.readTemperature() ;
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 (temperature <= 25 )
{
digitalWrite(pinOut1,HIGH);
}
else{
digitalWrite(pinOut1,LOW);
}
delay( 1000);
if (humidity <= 70)
{
digitalWrite(pinOut2,HIGH);
}
else{
digitalWrite(pinOut2,LOW);
}
delay( 1000);
if (temperature >= 25 )
{
digitalWrite(fan,HIGH);
}
else{
digitalWrite(fan,LOW);
}
delay( 1000);
}
and thanks for your hel[, we really appreciated