Page 1 of 1

Random powerhead script

Posted: Mon Oct 08, 2012 12:44 pm
by kahlif
I have 4 powerheads located around my tank...

I want, for about 14 hours, to randomly run 3/4 for 20 sec. So, every 20 sec, one should go off and another should go on. The other 10 hours, I want to go down to 2/4.

Any way to do this?

Thanks!

Re: Random powerhead script

Posted: Mon Oct 08, 2012 2:27 pm
by rimai
Although possible, you will need to place powerheads on ports that are not designed for that purpose.
Port 5 and 6 have dampening components to absorb the spike that powerheads generate when they are turned off.
If you use other ports, you may or may not encounter problems.
You would need to test and see.

Code: Select all

#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

void setup()
{
  ReefAngel.Init();  
}

void loop()
{
  ReefAngel.Relay.On(Port3);
  ReefAngel.Relay.On(Port4);
  ReefAngel.Relay.On(Port5);
  ReefAngel.Relay.On(Port6);
  if (hour() >=8 && hour() <=22)
  {
    if (now()%80<20) ReefAngel.Relay.Off(Port3);
    if (now()%80>=20 && now()<40) ReefAngel.Relay.Off(Port4);
    if (now()%80>=40 && now()<60) ReefAngel.Relay.Off(Port5);
    if (now()%80>=60 && now()<80) ReefAngel.Relay.Off(Port6);
  }
  else
  {
    if (now()%80<20)
    {
      ReefAngel.Relay.Off(Port3);
      ReefAngel.Relay.Off(Port4);
    }
    if (now()%80>=20 && now()<40)
    {
      ReefAngel.Relay.Off(Port4);
      ReefAngel.Relay.Off(Port5);
    }
    if (now()%80>=40 && now()<60)
    {
      ReefAngel.Relay.Off(Port5);
      ReefAngel.Relay.Off(Port6);
    }
    if (now()%80>=60 && now()<80)
    {
      ReefAngel.Relay.Off(Port6);
      ReefAngel.Relay.Off(Port3);
    }
  }
  ReefAngel.ShowInterface();
}

Re: Random powerhead script

Posted: Sat Oct 13, 2012 9:38 pm
by kahlif
So, I have 2 relay boxes, so I would use 5 and 6 on each box?

How do I specify that?

Re: Random powerhead script

Posted: Sat Oct 13, 2012 9:47 pm
by rimai
Try this code:

Code: Select all

#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

void setup()
{
  ReefAngel.Init();  
}

void loop()
{
  ReefAngel.Relay.On(Port5);
  ReefAngel.Relay.On(Port6);
  ReefAngel.Relay.On(Box1_Port5);
  ReefAngel.Relay.On(Box1_Port6);
  if (hour() >=8 && hour() <=22)
  {
    if (now()%80<20) ReefAngel.Relay.Off(Port5);
    if (now()%80>=20 && now()<40) ReefAngel.Relay.Off(Port6);
    if (now()%80>=40 && now()<60) ReefAngel.Relay.Off(Box1_Port5);
    if (now()%80>=60 && now()<80) ReefAngel.Relay.Off(Box1_Port6);
  }
  else
  {
    if (now()%80<20)
    {
      ReefAngel.Relay.Off(Port5);
      ReefAngel.Relay.Off(Port6);
    }
    if (now()%80>=20 && now()<40)
    {
      ReefAngel.Relay.Off(Port6);
      ReefAngel.Relay.Off(Box1_Port5);
    }
    if (now()%80>=40 && now()<60)
    {
      ReefAngel.Relay.Off(Box1_Port5);
      ReefAngel.Relay.Off(Box1_Port6);
    }
    if (now()%80>=60 && now()<80)
    {
      ReefAngel.Relay.Off(Box1_Port6);
      ReefAngel.Relay.Off(Port5);
    }
  }
  ReefAngel.ShowInterface();
}