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);
}