Seeking guidance for an automated greenhouse misting system

Hello

I am looking to create an automated system or misting my greenhouse. Although I am new to arduino, it appears that this will be the most versatile approach to doing so, as no off the shelf products can offer what I need of them.

My project will be a misting system controlled by a solenoid valve, which will be intermittently activated upon three parameters: daylight, outside temperature and outside humidity. Rain sensing is not required as it is under cover.

I have seen projects similar to this but they function like a thermostat, activating the solenoid continuously until a threshold is reached.

I intend for the misting system to activate only intermittently for a set duration of 5 seconds, but with the rate variable - increased when temperature increases, and decrease when the humidity increases, and stop when a light is not detected (at night), vice versa.

Ideally this would result in the mister being activated very frequently in hot dry conditions, and minimally when the conditions are cold and wet - but still for only 5 second bursts at a time.

Ultimately I am asking if anyone is aware of projects that use multiple inputs to determine the frequency of solenoid/output activation.

I imagine this would require some mathematical equation to combine the effect of temperature and humidity to create the interval for solenoid activation - but I have not seen this before in any projects I have browsed.

I do not have extensive knowledge of arduino so far, but plan to invest time and learn along the way and consider myself capable to do so.

If anybody could point me in the right direction in terms of existing projects that may be of use, please do so.

Hello
Do you have a schematic and a program flow chart?

So the code for activation of the mister is going to be fairly simple. Assuming it's connected to a digital pin, set it High, delay 5 seconds, set it low.

As for often you run that that code think about the parameters. First one is the light sensors, is it day or night? Look at the values the light sensor will give you and decide which of these constitutes day and night. Evaluate that first, because essentially in your case its binary, its either day or its night and if its night there is no point looking at the other values.

Then for the other two evaluate in turn. What causes and activation? Let's say if humidity is less than 40% and temp greater than 10c. So ready the values and if they are both true, activate the solenoid. Whilst it's running you don't want to be evaluating the parameters any more so think how you can pause the main loop whilst it runs, while loop, delay etc.

Last thing you want to think about is how often you want to check the variables, and configure a timer or delay to only check them on that interval.

Last thing I would say is hot and humid environments is not the first choice for a circuit board so look for an IP67 or even 68 rated project box to keep it in

1 Like

You should be able to find plenty of projects that read temperature and humidity and light level. Plenty of others that trigger a solenoid.

I suggest that you get the appropriate parts for those and write a little program for each component. Once you can control your hardware combine them one by one.

Then make a system that mists every fifteen minutes. After that you can figure out how to vary the fifteen minutes. It'll be a learning experience I suspect, so there's not much need to nail it down at the beginning.

One thing to consider is whether the misting will cause your sensor readings to be off for a while afterwards. You may want to ignore all of them for some time once misting is over.

I think I have attempted to ask for too much at once - i will start by testing myself by coding and creating each part of the system in isolation before being so ambitious.

For now I wish to create a system that turns a LED on for 5 seconds every x amount of time, which is dependant on temperature

as the system will seldom be edited, i think the easiest approach would be to have set parameters for every 1 degree temperature range.

e.g. if temperature = 20-21c the interval will be 10 minutes
if 21-22 interval of 9.5 minutes
etc..

I will for now work on my coding ability and return.

Thank you all for the help in guiding me so far

Good idea. Knowing your ultimate goal is important, but getting there in small chunks is often a very effective strategy.

for what it is worth i have since learned some coding and produced the following to automate a relay that activates a solenoid water valve

the temperature and humidity are read by a DHT22 sensor
an equation that relates temperature and humidity is used to define the delays between misting cycles, that can be adjusted using a potentiometer
the misting duration is set via code by can be adjusted from 1-10seconds with a potentiometer
If the temperature drops below 20c the solenoid is not activated and no misting will occur
I am in the process of adding the day/night sensor to the code and will do so in time

This is yet to be tested as I am waiting for some parts to arrive, i will report back when they do

//Libraries
#include <DHT.h>

//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht = DHT(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino

//Variables for potentiometers
int pot1Pin = A0; // the pin that reads potentiometer 1 (controlling duration of relay activation)
int pot1Input; // variable that stores the output of the potentiometer
int pot1; // pot1 percent value
int pot2Pin = A1; // the pin that reads potentiometer 2 (controlling duration of delay after relay activation)
int pot2Input; // variable that stores the output of the potentiometer
int pot2; // pot2 percent value

//Variables for DHT22 temperature + humidity sensor
int chk; //i dont know what this is for? - left it in as it was found in all DHT22 code online but cannot see it referenced to below
int temp; //Stores humidity value as integer
int humi; //Stores temperature value as integer

// Variables for the calculated delays
int maxtemp; //temperature where maximal relay activation is met
int mintemp; //temperature where relay activation = 0
int relayon;
int relayoff;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //sets the baud rate

//output to relay
pinMode(11,OUTPUT);
}

void loop() {
delay(2000); //Delay to read data and store it to variables - DHT22 can take up to 2 sec to do this - ,this might not be necessary probably delete it

//Potentiometers
pot1Input = analogRead(A0); // sets the variable to equal the input of the specified pin
pot1 = (float)pot1Input / 1023; // convert analog value to fraction
pot1 = pot1 * 100; //convert fraction to percentage
Serial.println("Mist level: ");
Serial.println(pot1 / 10);

pot2Input = analogRead(A1); // sets the variable to equal the input of the specified pin
pot2 = (float)pot2Input / 1023; // convert analog value to fraction
pot2 = pot2 * 100; //convert fraction to percentage
Serial.println("Interval level: ");
Serial.println(pot2 / 10);

//DHT22 temperature + humidity sensor
temp = dht.readTemperature();
humi = dht.readHumidity();
Serial.println("Current temperature: ");
Serial.println(temp);
Serial.println("Current humidity: ");
Serial.println(humi);

//calculate the delays
maxtemp = 50;
mintemp = 20;
if (temp < mintemp) {
relayon = 0;
}
else if (temp >= mintemp) {
relayon = pot1 * 100; //relay on duration = pot1 percent value * 100msec = range from 0-10 seconds duration
}
relayoff = (maxtemp * maxtemp) - (temp * temp); // formula for relayoff = ((maxtempmaxtemp)-(temptemp)/humi)*(pot2/10)
relayoff = relayoff / humi;
relayoff = relayoff * (pot2 / 10); //pot2 value changes duration from 0-10x the value of the above formula, average weather conditions of 21c and 57%RH = 36.12sec duration, range = 0-361 sec depending on pot2 value
Serial.println("Mist duration: ");
Serial.println(relayon);
Serial.println("Interval duration: ");
Serial.println(relayoff);

//activate relay
digitalWrite(11,HIGH);
delay(relayon);
digitalWrite(11,LOW);
delay(relayoff);

}

Please edit your post to add code tags.

The first post of every forum shows how to post code in a format condusive to reading.

pencil your post
Then highlight the code
Then hit </>

Here is the completed project for anybody interested. Worth noting is that the relay I purchased interpreted backwards, such that setting the output to LOW = on and HIGH = off, and the code reflects this as the values are reversed.

I am considering adding a clock and LDR to make it turn off at night time.

Thank you to all kind posters for their input.

//Libraries
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display
const int relayPin = 6;
const int pot1min = 0; //minimum reading from 1-1024
const int pot1max = 1010; //maximum reading from 1-1024
const int pot2min = 0; //minimum reading from 1-1023
const int pot2max = 1010; //maximum reading from 1-1024
const int pot3min = 0; //minimum reading from 1-1024
const int pot3max = 1010; //maximum reading from 1-1024

//variables
long onDuration = 1000;// OFF time for relay
long offDuration = 5000;// ON time for relay
int relayState =LOW;// initial state of relay
unsigned long rememberTime=0;// this is used by the code
int pot1; // controls relayontime (misting duration)
int pot2; // controls relayofftime (interval duration)
int pot3; // controls mintemp
float temp = 0.0;
float hum = 0.0;


void setup() {
  Serial.begin(9600); //set baud rate
  pinMode(relayPin,OUTPUT);// define relayPin as output
  digitalWrite(relayPin,relayState);// set initial state
  lcd.init(); //initialise LCD                 
  lcd.backlight(); //LCD backlight on
  dht.begin(); //initialise temperature/humidity sensor
}

void loop() {
  //temp + humidity sensor
  temp = dht.readTemperature();
  hum = dht.readHumidity();
  Serial.println("Current temperature:");
  Serial.print(temp);
  Serial.println("°C");
  Serial.println("Current humidity: ");
  Serial.print(hum);
  Serial.println("% RH");
 
  //potentiometers
  pot3 = 20;
  pot1 = analogRead(A0);
  pot1 = map(pot1, pot1min, pot1max, 1, 100); // multiplier for adjusting relayontime
  pot2 = analogRead(A1);
  pot2 = map(pot2, pot2min, pot2max, 1, 100); //multiplier for adjusting relayofftime
  //pot3 = analogRead(A2);
  //pot3 = map(pot3, pot3min, pot3max, 0, 30); //sets the minimum temperature from 0-30 degrees
  Serial.println("Potentiometer 1 (mist duration): ");
  Serial.println(pot1);
  Serial.println("Potentiometer 2 (interval duration): ");
  Serial.println(pot2);
  Serial.println("Potentiometer 3 (minimum temperature): ");
  Serial.println(pot3);

  //calculate the relay times //
  onDuration = pot1 * 100;  //relay on duration = pot1 percent value * 100msec = range from 0-10 seconds duration
  offDuration = (float)pow(0.5, (((int)temp / 10))) * (int)hum * pot2 *200;  //formula relating temp, humidity, potentiometer2 to misting interval
  
  Serial.println("Mist duration: ");
  Serial.println(onDuration/1000); 
  Serial.println("Interval duration: ");
  Serial.println(offDuration/1000);

  //LCD display
  //lcd.clear(); // clear previous values from screen
  //row 1
  lcd.setCursor (0,0);
  lcd.print(temp,1);
  lcd.print((char)223);
  lcd.print ("C ");
  lcd.print (hum, 1);
  lcd.print ("%RH");

  //row 2
  lcd.setCursor (0,1);
  lcd.print ("1. Temp off: ");
  lcd.print (pot3);
  lcd.print ((char)223);
  lcd.print ("C");

  //row3
  lcd.setCursor (0,2);
  lcd.print ("2. On: ");
  lcd.print (((float)onDuration / 1000),1);
  lcd.print ("sec ");
  lcd.print (pot1);
  lcd.print ("%   ");

  //row4
  lcd.setCursor (0,3);
  lcd.print ("3. Off: ");
  lcd.print (offDuration / 1000);
  lcd.print ("sec ");
  lcd.print (pot2);
  lcd.print ("% ");

  if( temp < pot3 )
  {
    relayState = LOW;// change the state of LED
    rememberTime=millis();// remember Current millis() time
  }
  if( relayState ==HIGH )
  {
    if( (millis()- rememberTime) >= onDuration){   
    relayState = LOW;// change the state of LED
    rememberTime=millis();// remember Current millis() time
    }
  }
  else
  {   
    if( (millis()- rememberTime) >= offDuration)
    {     
    relayState =HIGH;// change the state of LED
    rememberTime=millis();// remember Current millis() time
    }
  }
  
  digitalWrite(relayPin,relayState);// turn the relay ON or OFF

}

The solenoid is either normally open (NO) without power or normally closed (NC) without power.

The most common output from an arduino is to bring the pin LOW to turn a thing ON.

i would expect a NC solenoid and a low to energize.

And a big THANK YOU for posting your final sketch.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.