Go Down

Topic: Programmer needed (Read 1 time) previous topic - next topic

48simple

#10
Jan 24, 2010, 01:53 pm Last Edit: Jan 24, 2010, 06:28 pm by 48simple Reason: 1
this is what I have come up with so far... Only think really let is getting the timer to stage fans down to work.  

Code: [Select]
/*
Controller

Arudino Duemilanove port connections:
Digital Inputs
Push button TB2 at port
Push button TEST at port

Analog Input
LM35 temperature sensors;
TempSens1 at port
TempSens2 at port

Outputs
relay1 at port
relay2 at port
relay3 at port
relay4 at port
*/

// Pin Assignments:
const int TempSens1 = 0;    // pin to which temperature sensor 1 is attached to
const int TempSens2 = 1;    // pin to which temperature sensor 2 is attached to
const int TB2 = 2;          // pin to which TB2 button is conencted
const int TEST = 3;         // pin to which TEST button is conencted
const int Relay1 = 12;        //pin to which relay 1 is conencted
const int Relay2 =11;        //pin to which relay 2 is conencted
const int Relay3 = 10;        //pin to which relay 3 is conencted
const int Relay4 = 9;        //pin to which relay 4 is conencted

const unsigned char temp1=73;  //36 degree*10mV*1024/5V
const unsigned char temp2=82;  //40 degree*10mV*1024/5V
const unsigned char temp3=90;  //44 degree*10mV*1024/5V
const unsigned char temp4=96;  //47 degree*10mV*1024/5V

// Variables:
int TempSens1_Reading= 0;         // temperature sensor 1 reading
int TempSens2_Reading= 0;         // temperature sensor 2 reading
int TB2buttonState;             // the current reading from the input pin
int TB2lastButtonState = LOW;   // the previous reading from the input pin
long TB2lastDebounceTime = 0;  // the last time the output pin was toggled
int TESTbuttonState;             // the current reading from the input pin
int TESTlastButtonState = LOW;   // the previous reading from the input pin
long TESTlastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers
long one_minute_count1=0;
long one_minute_count2=0;
long one_minute_count3=0;

int read_TB2(){
 int reading = digitalRead(TB2);
 if (reading != TB2lastButtonState) {
   TB2lastDebounceTime = millis();
 }
 if ((millis() - TB2lastDebounceTime) > debounceDelay) {
   TB2buttonState = reading;
 }
 TB2lastButtonState = reading;
 return TB2buttonState;
}
int read_TEST(){
 int reading = digitalRead(TEST);
 if (reading != TESTlastButtonState) {
   TESTlastDebounceTime = millis();
 }
 if ((millis() - TESTlastDebounceTime) > debounceDelay) {
   TESTbuttonState = reading;
 }
 TESTlastButtonState = reading;
 return TESTbuttonState;
}
void setup() {

// Assign inputs and outputs
 pinMode(TB2 , INPUT);      //set TB2 pin an input pin
 pinMode(TEST , INPUT);    //set TEST pin an input pin
 pinMode(Relay1, OUTPUT);  //set Relay1 pin an ouput pin
 pinMode(Relay2, OUTPUT);  //set Relay1 pin an ouput pin
 pinMode(Relay3, OUTPUT);  //set Relay1 pin an ouput pin
 pinMode(Relay4, OUTPUT);  //set Relay1 pin an ouput pin
 digitalWrite(Relay1, LOW);
 digitalWrite(Relay2, LOW);
 digitalWrite(Relay3, LOW);
 digitalWrite(Relay4, LOW);
}

void loop() {
 while (read_TEST()==true){
 digitalWrite(Relay1, HIGH);
 digitalWrite(Relay2, HIGH);
 digitalWrite(Relay3, HIGH);
 digitalWrite(Relay4, HIGH);
 }
 
 while (read_TEST()==false && read_TB2()==false){
 digitalWrite(Relay1, LOW);
 digitalWrite(Relay2, LOW);
 digitalWrite(Relay3, LOW);
 digitalWrite(Relay4, LOW);
 }
 while (read_TEST()==false && read_TB2()==true){
   TempSens1_Reading = analogRead(TempSens1);
   TempSens2_Reading = analogRead(TempSens2);
       
   digitalWrite(Relay1, LOW);
   digitalWrite(Relay2, LOW);
   digitalWrite(Relay3, LOW);
   digitalWrite(Relay4, LOW);
   
   if (TempSens1_Reading >=temp1 || TempSens2_Reading >=temp1){  
     digitalWrite(Relay1, HIGH);
     digitalWrite(Relay2, LOW);
     digitalWrite(Relay3, LOW);
     digitalWrite(Relay4, LOW);
   }
   if (TempSens1_Reading >=temp2 || TempSens2_Reading >=temp2){  
     one_minute_count2=0;
     digitalWrite(Relay1, HIGH);
     digitalWrite(Relay2, HIGH);
     digitalWrite(Relay3, LOW);
     digitalWrite(Relay4, LOW);
   }
   if (TempSens1_Reading >=temp3 || TempSens2_Reading >=temp3){  
     
     digitalWrite(Relay1, HIGH);
     digitalWrite(Relay2, HIGH);
     digitalWrite(Relay3, HIGH);
     digitalWrite(Relay4, LOW);
     one_minute_count1=0;
   }
   if (TempSens1_Reading >=temp4 || TempSens2_Reading >=temp4){  
     digitalWrite(Relay1, HIGH);
     digitalWrite(Relay2, HIGH);
     digitalWrite(Relay3, HIGH);
     digitalWrite(Relay4, HIGH);
   }
 }
}

PaulS

Quote
Only thing really left is getting the timer to stage fans down to work.  


Not quite. You also need to learn the rules about posting code to the forum. There is a button on the top row with a # on it. Select all of your code, and press that button. Or press the button before you paste the code.

You could (and should) go back and modify your previous post to use the # button.

Fletcher Chr

#12
Feb 05, 2010, 08:55 am Last Edit: Feb 05, 2010, 08:56 am by Fletcher_Chr Reason: 1
Hi

Maybe I just like to keep it simpel:

Code: [Select]


const byte relayNumbers = 3;
byte pinList[relayNumbers] = {2, 3, 4};
float tempList[relayNumbers] = {25, 75, 85};

unsigned long value = 0;
unsigned long myTime = 0;
unsigned long delayTime = 5000;          // ms before turning off, change to 60000 for 1 min delay

void setup() {
  for (byte i=0; i<relayNumbers; i++)
    pinMode(pinList[i], OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) value = 0;     // This part grab the serial input
                                                     // and turn it into a number
  while (Serial.available()) {          
    char ch = Serial.read();
    if(ch >= '0' and ch <= '9')
      value = value * 10 + (ch - '0');
    delay(50);                               // quite a large part of the program ;-)
  }

  for (byte i=0; i<relayNumbers; i++) {                          //  
Let's check to see if it's turn realy on time
    if (tempList[i] <= value and digitalRead(pinList[i])==LOW)  
{          // Yep, it was
      myTime = millis();
      digitalWrite(pinList[i], HIGH);
    }
    if ((value < tempList[i]) and (millis() - myTime > delayTime))
      digitalWrite(pinList[i], LOW);     // Turn off time
  }
  delay(50);
}


Only downfall compared to the original design. The fan(s) turn off delayTime after the value goes below setpoint.

-Fletcher

Go Up