Go Down

Topic: Citrus Freeze Protection (Read 1 time) previous topic - next topic

hamman88

Hello,

I'm working to program an Arduino to control a solenoid irrigation valve to protect citrus trees from freezes.  In case your not familiar with agriculture, farmers spray water on crops in freezing temperature.  The water freezes on the plants, releasing latent heat that actually keeps the plant tissue above freezing (odd to think freezing water on a plant keeps it warm, huh?)

Currently, farmers turn sprinkler on at a predetermined temperature without regard to other important variables.  A lot of water (and I mean millions and millions of gallons) of water are wasted by turning on the sprinklers too early.  The wet-bulb temperature is the true indicator of when it is time to turn the sprinklers on. The wet-bulb temp is found using the normal dry-bulb temp and the relative humidity. The optimal time to turn the sprinklers on is when the wet-bulb temp is at or below the danger temp for the crop.

I have a DHT22 combination dry-bulb temp and relative humidity sensor.  This came with the programming to use the sensor and I need to add to it to calculate the wetbulb, display the wetbulb, and turn on the solenoid valve when the wetbulb is below the predetermined critical temp. (I'm turning on valve via relay or transistor).

This is my first taste of programming or using an arduino.  I read the first half of "Beginnning Arduino Programming", so don't think I came straight to you guys without trying it myself first.

The biggest snag I've hit is solving the equation for the wet-bulb as it requires iteration to solve. I also need help getting the humidity and temp from the sensor into the equation. Those 2 are what I would appreciate help with most of all. Plus anything else I'm missing in my code (lots certainly). I've attached the code given with the sensor and my current file so you can see what I have added.

Thanks!!

Nick Gammon

They are small enough to paste directly:

freezeprotection.ino:

Code: [Select]

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

const int critical = -3 //critcal plant freezing temp in degree C
const int relay = 5 //soleniod relay 
float wetbulb = 0

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);



void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");
pinMode(relay, OUTPUT);
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
   h*(2.71828^(15.22t/(269.3+t)))=1.404*(2.71828^(15.22*wetbulb)/(269.3+wetbulb))+.184*(t-wetbulb)*(.000038*wetbulb-1) //need to solve this iterative equation for wetbulb,
                                                                                                                        //t and h are temp and relative humidity from sensor
 
  if (wetbulb <= critical) {
  digitalWrite (relay, HIGH);   //wetbulb below critical trips relay

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
     
     Serial.print("Wetbulb");
     Serial.print(wetbulb);
     Serial.print("*C");
     Serial.print("Critical");
     Serial.print(critical);
     Serial.print(*C);
  }
}



DHTtester.ino:

Code: [Select]

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
  }
}

Nick Gammon

Apart from the syntax errors, this is the problem line, I gather:

Code: [Select]

//need to solve this iterative equation for wetbulb,
//t and h are temp and relative humidity from sensor

   h*(2.71828^(15.22t/(269.3+t)))=1.404*(2.71828^(15.22*wetbulb)/(269.3+wetbulb))+.184*(t-wetbulb)*(.000038*wetbulb-1)

Nick Gammon


Nick Gammon

What might work for you is a simple look-up table. Say you have around 20 temperatures where a decision is critical (eg. -10C to +10C) and 40 humidity values. A simple X/Y table where you enter the temperature and humidity and look up the wet-bulb temperature could do it. You only need to store a byte per entry (basically whether or not to turn the watering on).

The table could be kept in program memory, so you'd have plenty of space.

Go Up