Jump to content
43oh

Swamp Cooler Automatic Purge Pump


Recommended Posts

This is the code I used for my automatic swamp cooler purge pump project. Uses a CdS cell to detect daylight so the cooler can run once at sunrise and once at sunset.

 

Not all that fancy, but didn't need to be to get the job done. These delays are setup for a 16MHz processor, delays are funny in Energia for 1MHz processors but that'll get fixed and the delays will be a non-issue for the 2231.

 

There is no sleep mode which is fine since even without it the circuit still runs less than the 317L's minimum current recommendation between the 2231 and light circuit, requiring me to add a 1K across the regulated rail. I just have it all in a control box atop the blower assembly inside the cooler.

 

Input circuit is a CdS cell between V+ and P1_6 and a 2K pull down to gnd poking out a hole at the top. Output goes to a 12v relay via 2N2222 and 1K base resistor.

 

/* This program is for a swamp cooler purge pump. The pump is activated at
  sunrise and sunset and runs for 45 seconds. This time is determined by
  the amount of time it takes for the purge pump to run without depriming
  main cooler pump. There is a minimum 12hr delay between purge cycles except
  for powerup, which will enable the pump for 30 seconds each time.
*/

const int relayOutput = P1_0, CdSInput = A5;

int dayTrigger = 0, nightTrigger = 0;
int ADCInput = 0;
unsigned int lastRunCounter = 0, runTime = 0;

const unsigned int lastRunMinimum = 43200, runTimeMax = 45, ADCInputThresh = 255;

void setup()
{
 pinMode(relayOutput, OUTPUT);
 digitalWrite(relayOutput, HIGH);
 while(runTime < 30)
 {
   delay(1000);
   runTime++;
 }
 digitalWrite(relayOutput, LOW);
 runTime = 0;
}

void loop()
{
 ADCInput = analogRead(A5);

 if(ADCInput > ADCInputThresh && lastRunCounter > lastRunMinimum && dayTrigger == 0)
 {
   digitalWrite(relayOutput, HIGH);
   while(runTime < runTimeMax)
   {
     delay(1000);
     runTime++;
   }
   digitalWrite(relayOutput, LOW);
   runTime = 0;
   dayTrigger = 1;
   nightTrigger = 0;
   lastRunCounter = 0;
 }

 if(ADCInput < ADCInputThresh && lastRunCounter > lastRunMinimum && nightTrigger == 0)
 {
   digitalWrite(relayOutput, HIGH);
   while(runTime < runTimeMax)
   {
     delay(1000);
     runTime++;
   }
   digitalWrite(relayOutput, LOW);
   runTime = 0;
   nightTrigger = 1;
   dayTrigger = 0;
   lastRunCounter = 0;
 }

 delay(1000);
 lastRunCounter++;
}

 

772 bytes total memory used. Still got over half on the 2231 left to play with!

Link to post
Share on other sites

Just thought I'd chime in and say that I ended up using a 2131 instead of the 2231(1K instead of 2K since my program is < 1K)

 

Energia doesn't seem to care that it isn't a 2231 in the target and it works fine.

 

Also, how does one go about using the WTD+ in Energia?? I doubt it's needed but since I'm dealing with inductive loads I would like for the mcu to restart itself if needed.

Link to post
Share on other sites

The Watchdog runs in interval timer mode rather than watchdog mode and is (ab)used to do the sys tick like function for delay(), micros(), mills(). Unfortunately watchdog and interval mode are mutually exclusive. Sys tick like functionality would have to be moved to a timer to free up the Watchdog. Timers are a scares resource and hence I chose to use the watchdog for the sys tick function.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...