hi all,
i am currently developing a automated watering solution for my plants containing (at the moment) a soil humidity sensor(which right now is a dht11 sensor) and a DC motor based pump, besides that i have a arduino uno and a motor shield which i have hooked up these things to.
the basic principle is that when the humidity is below for eg 10% start the pump for X seconds.
i get my sensor working and i get my motor working BUT NOT TOGETHER!!!
can anyone please help me on what i am doing wrong.
the code i have started with is two example codes that i have merged together and commented out bits i dont want. i dont have enought knowlege to write the code from scratch yet!
the code lookes like this:
#include <dht11.h> //Import needed libraries
dht11 DHT11; //Declare objects
#define DHT11PIN 2 //Declare Pin Numbers
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
//motor setup
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
//Setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel A pin
pinMode(8, OUTPUT); //Initiates Brake Channel A pin
//min mo
}
void loop()
{
Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
if ((DHT11.humidity) > 46); {
// do stuff if the condition is truee
Serial.print("Fuktighet hög");
//Motor A forward @ full speed
// digitalWrite(12, HIGH); //Establishes forward direction of Channel A
// digitalWrite(9, LOW); //Disengage the Brake for Channel A
//analogWrite(3, 255); //Spins the motor on Channel A at full speed
//Motor B backward @ half speed
// digitalWrite(13, LOW); //Establishes backward direction of Channel B
// digitalWrite(8, LOW); //Disengage the Brake for Channel B
//analogWrite(11, 123); //Spins the motor on Channel B at half speed
delay(3000);
// digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B
delay(1000);
//Motor A forward @ full speed
// digitalWrite(12, LOW); //Establishes backward direction of Channel A
//digitalWrite(9, LOW); //Disengage the Brake for Channel A
//analogWrite(3, 123); //Spins the motor on Channel A at half speed
//Motor B forward @ full speed
digitalWrite(13, HIGH); //Establishes forward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
analogWrite(11, 255); //Spins the motor on Channel B at full speed
delay(3000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
delay(2000);
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
//Sebastian