Random powerhead script

Do you have a question on how to do something.
Ask in here.
Post Reply
kahlif
Posts: 19
Joined: Mon Sep 10, 2012 4:03 pm

Random powerhead script

Post 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!
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Random powerhead script

Post 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();
}
Roberto.
kahlif
Posts: 19
Joined: Mon Sep 10, 2012 4:03 pm

Re: Random powerhead script

Post by kahlif »

So, I have 2 relay boxes, so I would use 5 and 6 on each box?

How do I specify that?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Random powerhead script

Post 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();
}
Roberto.
Post Reply