Hi I begen a new project and i need help my first project, i have a solar woater heater and a gas woater heater and i can't control the 3 wey valve properly tis is my code :
#include <OneWire.h>
#include <DallasTemperature.h>
int tankmax = 212;
int diff = 15;
int valvemax = 212;
int flowmin = 86;
float werethere = 1.5;
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte tanktopThermometer[8] = { 0x28, 0x89, 0xFF, 0x79, 0x97, 0x15, 0x03, 0x33 };
byte collectorThermometer[8] = { 0x28, 0x6B, 0x38, 0x79, 0x97, 0x15, 0x03, 0x07 };
int pump = 12;
int valve = 11;
int pumpstate;
int valvestate;
void setup ()
{
//start serial port
Serial.begin(9600);
Serial.println ("Solar hot water Differential Controller");
// Start up the onewire library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// set the sensor resolution from 9 to 12 bit
sensors.setResolution(tanktopThermometer, 10);
sensors.setResolution(collectorThermometer, 10);
//set pins to output
pinMode (pump, OUTPUT);
pinMode (valve, OUTPUT);
}
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
float temp = (DallasTemperature::toFahrenheit(tempC));
return tempC;
}
void loop ()
{
sensors.requestTemperatures();
float tank = (sensorValue(tanktopThermometer));
float collector = (sensorValue(collectorThermometer));
Serial.print ("tank ");
Serial.println (tank);
Serial.print ("collector ");
Serial.println (collector);
Serial.print ("pump state ");
Serial.println (pumpstate);
Serial.println ("");
Serial.print ("valvestate ");
Serial.println (valvestate);
Serial.println ("");
digitalWrite (pump, HIGH);
static bool pumpOn=false;
if ( pumpOn)
{
if (((collector - werethere) < tank ) && (tank >= tankmax) )
{
digitalWrite (pump, LOW);
pumpOn =false;
}
}
else
{
if (((collector - diff) > tank ) && ( tank < tankmax ) )
{
digitalWrite (pump, HIGH);
pumpOn = true;
}
}
if ( ( tank > flowmin ) && ( tank < tankmax ) )
{digitalWrite (valve, HIGH); valvestate = 0;}
if ( ( tank < flowmin ) && (tank < tankmax ) )
{digitalWrite (valve, LOW); valvestate = 1;}
delay(1000);
}
and i need for pin 11 to be low for 30 s and den high for open and pin 10 to be low fur 30s for clouszing the valve and wen resset to put it in a nown pozision