i have build controller open , close valve when there 10 degree(celsius) colder in tank thermometer placed near heat pump, if condition true need turn on relay controls valve.
for reading temperature have 2 ds18b20's
hope out there can me because has troubled me last few days.
for reading temperature have 2 ds18b20's
hope out there can me because has troubled me last few days.
code: [select]
#include <onewire.h>
#include <dallastemperature.h>
// data wire plugged port 2 on arduino
#define one_wire_bus 2
#define temperature_precision 10
// setup onewire instance communicate onewire devices (not maxim/dallas temperature ics)
onewire onewire(one_wire_bus);
// pass our onewire reference dallas temperature.
dallastemperature sensors(&onewire);
// arrays hold device addresses
deviceaddress tankthermometer, pumpthermometer;
int relaypin = 4;
int failpin = 13;
boolean running = false;
boolean fail = false;
float tempopen;
float tempet;
float tempto;
void setup(void)
{
// start serial port
serial.begin(9600);
serial.println("dallas temperature ic control library demo");
//setting outputs led , relay
pinmode(relaypin, output);
pinmode(failpin, output);
// start library
sensors.begin();
// locate devices on 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");
// assigns first address found pumpthermometer
if (!onewire.search(pumpthermometer)) serial.println("unable find address outsidethermometer");
// assigns seconds address found tankthermometer
if (!onewire.search(tankthermometer)) serial.println("unable find address insidethermometer");
// show addresses found on bus
serial.print("device 0 address: ");
printaddress(pumpthermometer);
serial.println();
serial.print("device 1 address: ");
printaddress(tankthermometer);
serial.println();
// set resolution 12 bit
sensors.setresolution(pumpthermometer, temperature_precision);
sensors.setresolution(tankthermometer, temperature_precision);
serial.print("device 0 resolution: ");
serial.print(sensors.getresolution(pumpthermometer), dec);
serial.println();
serial.print("device 1 resolution: ");
serial.print(sensors.getresolution(tankthermometer), dec);
serial.println();
}
// function print device address
void printaddress(deviceaddress deviceaddress)
{
(uint8_t = 0; < 8; i++)
{
// 0 pad address if necessary
if (deviceaddress[i] < 16) serial.print("0");
serial.print(deviceaddress[i], hex);
}
}
// function print temperature device
void printtemperature(deviceaddress deviceaddress)
{
float tempc = sensors.gettempc(deviceaddress);
serial.print("temp c: ");
serial.print(tempc);
}
// function print device's resolution
void printresolution(deviceaddress deviceaddress)
{
serial.print("resolution: ");
serial.print(sensors.getresolution(deviceaddress));
serial.println();
}
// main function print information device
void printdata(deviceaddress deviceaddress)
{
serial.print("device address: ");
printaddress(deviceaddress);
serial.print(" ");
printtemperature(deviceaddress);
serial.println();
}
void loop(void)
{
// call sensors.requesttemperatures() issue global temperature
// request devices on bus
serial.print("requesting temperatures...");
sensors.requesttemperatures();
serial.println("done");
// print device information
printdata(tankthermometer);
printdata(pumpthermometer);
//getting temperatures
tempet = sensors.gettempc(tankthermometer);
tempto = sensors.gettempc(pumpthermometer);
//doing math
tempopen = tempet + 10;
//measuring fails
if(tempet == -127.00 || tempto == -127.00){
fail = true;
digitalwrite(failpin, high);
}
else{
fail = false;
digitalwrite(failpin, low);
}
//checking when open
if(tempopen <= tempto && running == false && fail == false){
running = true;
digitalwrite(relaypin, low);
serial.println("relay on");
}
//checking when close
if(tempet >= tempto && running == true && fail == false){
running = false;
digitalwrite(relaypin, high);
serial.println("relay off");
}
}
quote
hope out there can me because has troubled me last few days.what is troubling ?
Arduino Forum > Using Arduino > Programming Questions > Problem with controller
arduino
Comments
Post a Comment