64 yr old newby would like some help

Hi Ray,

I have run some large (240V 12A) heating elements from Arduino using Solid State Relays like these:

DISCLAIMER: Mentioned stuff from my own shop...!

Here are 3 I have in my kiln controller, controlling separate heating elements.

Wires at the top go over to an Arduino Mega. I have run this for hours with elements cycling on and off. It is in a metal case, and the Solid State Relays are on heat sinks like these:

These relays are optically isolated and can be driven directly from Arduino.

Hi Terry,

That's what I'm looking for. Where can I get the heat sinks?

You can mount the SSRs onto an 1/8” aluminum plate, raise the plate form the subsurface by about 1/4”.
Mount vertically for air flow.

Larry,

I've spent some time now going back an forth between you example and the references you gave as well as trying to implement that into my crude code. Which does work as expected.

To get to the level of streamlining that you demonstrated I need to take some baby steps to understand as I move from 1 level to the next. I think.

Also, I can't, at this point, see where BWD will come into play with my greenhouse control. All actions will will determined sensor values.

An example:

If the inside temp of the greenhouse is below 60F and the compost pile temp is is above 120F turn the fan on.

If that isn't supplying enough heat I'll go to the water battery and get heat. I that isn't enough I'll turn on aux heat.

I don't pretend to know all that is capable here. I just know that I need to eat the elephant one bite at time.

So if you will bear with me, look at my original code, which works, and what I have added (mostly from the references) and give me some direction.

Here is the error code I getting.

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Relay_test_array:19: error: expected unqualified-id before 'for'

for(int i=0; i<8; i++) digitalWrite(pins*, HIGH);*
^
Relay_test_array:19: error: 'i' does not name a type
for(int i=0; i<8; i++) digitalWrite(pins*, HIGH);*
* ^*
Relay_test_array:19: error: 'i' does not name a type
for(int i=0; i<8; i++) digitalWrite(pins*, HIGH);*
* ^*
exit status 1
expected unqualified-id before 'for'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here is the code.
```
*const byte compost_fan      =31; //compost fan
const byte irrigation_pump  =33; //drip irrigation pump
const byte vent_fan          =35; //vent fan - high temp or humidity
const byte solor_water_pump  =37; //solar water pump
const byte solor_water_drain =39; //solar water drain solenoid - if temp to low drain
const byte radiator_solenoid =41; //solar to radiator_solenoid
const byte radiator_fan      =43; //radiator_fan
const byte Grow_lights      =45; //Grow_lights
// const byte relay9=30; //20 amp for aux heat
// const byte relay10=32; //compost diverter valve
// const byte relay11=34; //spare
// const byte relay12=36; //spare
// const byte relay13=38; //spare

const byte Relays[]            = {31, 33, 35, 37, 39, 41, 43, 45};

//int myPins[8] = {31, 33, 35, 37, 39, 41, 43, 45}; //i can not comment this and it verifys
for(int i=0; i<8; i++) digitalWrite(pins[i], HIGH);
void setup() {

//digitalWrite(compost_fan,HIGH);
//digitalWrite(irrigation_pump,HIGH);
//digitalWrite(vent_fan,HIGH);
//digitalWrite(solor_water_pump,HIGH);
//digitalWrite(solor_water_drain,HIGH);
//digitalWrite(radiator_solenoid,HIGH);
//digitalWrite(radiator_solenoid,HIGH);
//digitalWrite(radiator_solenoid,HIGH);
//digitaWrite(relay9,HIGH);
//digitaWrite(relay10,HIGH);
//digitaWrite(relay11,HIGH);
//digitaWrite(relay12,HIGH);
//digitaWrite(relay13,HIGH);

for(int i = 0; i<8; i++) pinMode(i, OUTPUT);

//pinMode(compost_fan, OUTPUT);
//pinMode(irrigation_pump, OUTPUT);
//pinMode(vent_fan, OUTPUT);
//pinMode(solor_water_pump, OUTPUT);
//pinMode(solor_water_drain, OUTPUT);
//pinMode(radiator_solenoid, OUTPUT);
//pinMode(radiator_solenoid, OUTPUT);
//pinMode(radiator_solenoid, OUTPUT);
//pinMode(relay9, OUTPUT);
//pinMode(relay10, OUTPUT);
//pinMode(relay11, OUTPUT);
//pinMode(relay12, OUTPUT);
//pinMode(relay13, OUTPUT);

}

void loop() {
  // Low = ON
  digitalWrite(compost_fan,LOW);
  delay(1000);
  digitalWrite(compost_fan,HIGH);
  delay (1000);
  digitalWrite(irrigation_pump,LOW);
  delay(1000);
  digitalWrite(irrigation_pump,HIGH);
  delay (1000);
  digitalWrite(vent_fan,LOW);
  delay(1000);
  digitalWrite(vent_fan,HIGH);
  delay (1000);
  digitalWrite(solor_water_pump,LOW);
  delay(1000);
  digitalWrite(solor_water_pump,HIGH);
  delay (1000);
  digitalWrite(solor_water_drain,LOW);
  delay(1000);
  digitalWrite(solor_water_drain,HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid,LOW);
  delay(1000);
  digitalWrite(radiator_solenoid,HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid,LOW);
  delay(1000);
  digitalWrite(radiator_solenoid,HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid,LOW);
  delay(1000);
  digitalWrite(radiator_solenoid,HIGH);
  delay (1000);

}
_```*_

Move this line inside setup()

for(int i=0; i<8; i++) digitalWrite(pins[ i ], HIGH); //pins has to be defined though

The compiler sees the for() statement is outside of a function and is throwing a fit :wink:

for() is a run time statement and has to be inside a function.

it's above "void loop()" I think it's still in the setup section.

it's above "void loop()" I think it's still in the setup section.

It has to be inside setup().
i.e. between the { and } that belongs to the setup() function.

Also, I can't, at this point, see where BWD will come into play with my greenhouse control. All actions will will determined sensor values.

Let's say you turn on a pump for 5 minutes.
Say you use this code:
digitalWrite(Pump,HIGH); //turn the pump on
delay( 5 * 60 * 1000);
digitalWrite(Pump,LOW); //turn the pump off

The delay() function freezes your sketch from running until the 5 minutes has elapsed.
During this time there may be something that happens and needs imediate attention.
Since delay() is running, nothing else can be attended to until the 5 minutes has expired :frowning:

.

Ray, where are you located???

I got THESE Heatsinks on Amazon.

I'm not getting it. Here's my latest attempt.

void setup() {
const byte compost_fan       = 31; //compost fan
const byte irrigation_pump   = 33; //drip irrigation pump
const byte vent_fan          = 35; //vent fan - high temp or humidity
const byte solor_water_pump  = 37; //solar water pump
const byte solor_water_drain = 39; //solar water drain solenoid - if temp to low drain
const byte radiator_solenoid = 41; //solar to radiator_solenoid
const byte radiator_fan      = 43; //radiator_fan
const byte Grow_lights       = 45; //Grow_lights
// const byte relay9=30; //20 amp for aux heat
// const byte relay10=32; //compost diverter valve
// const byte relay11=34; //spare
// const byte relay12=36; //spare
// const byte relay13=38; //spare

const byte Relays[]            = {31, 33, 35, 37, 39, 41, 43, 45};
  for (int i = 0; i < 8; i++) digitalWrite(pins[i], HIGH);
  for (int i = 0; i < 8; i++) pinMode(i, OUTPUT);
}

void loop() {
  // Low = ON
  digitalWrite(compost_fan, LOW);
  delay(1000);
  digitalWrite(compost_fan, HIGH);
  delay (1000);
  digitalWrite(irrigation_pump, LOW);
  delay(1000);
  digitalWrite(irrigation_pump, HIGH);
  delay (1000);
  digitalWrite(vent_fan, LOW);
  delay(1000);
  digitalWrite(vent_fan, HIGH);
  delay (1000);
  digitalWrite(solor_water_pump, LOW);
  delay(1000);
  digitalWrite(solor_water_pump, HIGH);
  delay (1000);
  digitalWrite(solor_water_drain, LOW);
  delay(1000);
  digitalWrite(solor_water_drain, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);

}

Terry,m I'm in Iowa and I have a prime membership. Thanks

const byte compost_fan       = 31; //compost fan
const byte irrigation_pump   = 33; //drip irrigation pump
const byte vent_fan          = 35; //vent fan - high temp or humidity
const byte solor_water_pump  = 37; //solar water pump
const byte solor_water_drain = 39; //solar water drain solenoid - if temp to low drain
const byte radiator_solenoid = 41; //solar to radiator_solenoid
const byte radiator_fan      = 43; //radiator_fan
const byte Grow_lights       = 45; //Grow_lights

// const byte relay9=30; //20 amp for aux heat
// const byte relay10=32; //compost diverter valve
// const byte relay11=34; //spare
// const byte relay12=36; //spare
// const byte relay13=38; //spare

const byte Relays[]            = {31, 33, 35, 37, 39, 41, 43, 45};






//************************************************************************
void setup()
{
  for (int i = 0; i < 8; i++)
  {
    digitalWrite(Relays[i], HIGH);
  }

  for (int i = 0; i < 8; i++)
  {
    pinMode(Relays[i], OUTPUT);
  }

}




//************************************************************************

void loop()
{
  // Low = ON
  digitalWrite(compost_fan, LOW);
  delay(1000);
  digitalWrite(compost_fan, HIGH);
  delay (1000);
  digitalWrite(irrigation_pump, LOW);
  delay(1000);
  digitalWrite(irrigation_pump, HIGH);
  delay (1000);
  digitalWrite(vent_fan, LOW);
  delay(1000);
  digitalWrite(vent_fan, HIGH);
  delay (1000);
  digitalWrite(solor_water_pump, LOW);
  delay(1000);
  digitalWrite(solor_water_pump, HIGH);
  delay (1000);
  digitalWrite(solor_water_drain, LOW);
  delay(1000);
  digitalWrite(solor_water_drain, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);
  digitalWrite(radiator_solenoid, LOW);
  delay(1000);
  digitalWrite(radiator_solenoid, HIGH);
  delay (1000);

}
//************************************************************************
  for (int i = 0; i < 8; i++)
  {
    digitalWrite(Relays[i], HIGH);
  }

  for (int i = 0; i < 8; i++)
  {
    pinMode(Relays[i], OUTPUT);
  }

BTW, the above can be made:

  for (int i = 0; i < 8; i++)
  {
    digitalWrite(Relays[i], HIGH);
    pinMode(Relays[i], OUTPUT);
  }

I can only hope that someday I can do this as fast as you!!!

I need to take some time to study this and go thru line by line so I understand.

Thanks

BTW, where are you at that is - 22 a day or 2 ago. If you don't mind saying. On past projects I've had help from Ireland and Serbia as well as the US. Just interesting to know.

As far as the BWD goes. We've gone thru that with using millis- so an overflow is avoided. I feel I have a pretty good handle on that or we would still be talking about it.

Calgary Stampede, it's on my bucket list.

Calgary Stampede, it's on my bucket list.

Yahoo, Yeehaw.

Here is a 'State Machine' example that might be a skeleton for you to build your control sketch on:
Lots of new stuff here but it may give you some ideas what can be done.

Keep it around as a sleeping aid.

//Simple State machine example
//LarryD
//
//Version   YY/MM/DD
//1.00      16/01/15 Running code
//1.01      16/01/30 Added Blocking LED check
//1.02      17/12/26 Added restart and timer enabled flags
//

unsigned long State1Millis; //used to calculate when
unsigned long State2Millis; //the associated machine state
unsigned long State3Millis; //code will be run next
unsigned long State4Millis;
//add more as needed

unsigned long State1WaitTime = 50UL;   //time to wait, 50ms
unsigned long State2WaitTime = 100UL;  //time to wait, 100ms
unsigned long State3WaitTime = 200UL;  //time to wait, 200ms
unsigned long State4WaitTime = 300UL;  //time to wait, 300ms
//add more as needed

boolean State1Restart = true; //repeat this sequence
boolean State2Restart = true; //
boolean State3Restart = true; //
boolean State4Restart = true; //
//add more as needed

boolean State1EnableFlag = true; //Timer is enabled/disabled
boolean State2EnableFlag = true; //
boolean State3EnableFlag = true; //
boolean State4EnableFlag = true; //
//add more as needed

//other variables
unsigned long currentMillis;
unsigned long BlockingMillis;

const byte BlockingLED = 7;
const byte FirstLED    = 6;
const byte SecondLED   = 5;
const byte ThirdLED    = 4;
const byte FourthLED   = 3;

//define the available states that we can have for this sketch
enum States
{
  //add more states as needed
  StateStart, State1, State2, State3, State4
};

States mState = StateStart;         //we start out in this machine state



//======================================================================
void setup()
{
  currentMillis = millis();

  BlockingMillis = currentMillis;   //initialize timing
  State1Millis   = currentMillis;
  State2Millis   = currentMillis;
  State3Millis   = currentMillis;
  State4Millis   = currentMillis;

  for (byte x = 3; x < 8; x++)
  {
    pinMode(x, OUTPUT);
  }

} //END of                    s e t u p ( )

//======================================================================
void loop()
{
  // keep this line of code at this location
  currentMillis = millis();

  //****************************************************************
  //Some code to check for blocking code, LED should flash at 1/2 Hertz rate
  if (CheckTime(BlockingMillis, 1000, true, true))
  {
    //Toggle the Blocking LED
    digitalWrite(BlockingLED, !digitalRead(BlockingLED));
  }

  //*********** Other non blocking loop stuff goes here ************

  //Check the state machine
  StateMachine();

} //END of                   l o o p ( )


//======================================================================
//                        F U N C T I O N S
//======================================================================

//Delay time expired function
//lastMillis = the time this "timer" was (re)started
//wait       = delay time (mS) we are looking for. You can use math 60*60*1000 for 1 hour
//restart    = do we start "this timer" again and again
//enableFlag = is "this timer" enabled/allowed to be accessed
boolean CheckTime(unsigned long &lastMillis, const unsigned long wait, boolean restart, boolean enableFlag)
{
  //has this timer expired?
  if (enableFlag == true && currentMillis - lastMillis >= wait)
  {
    //should this start again?
    if (restart == true)
    {
      lastMillis += wait;  //get ready for the next iteration
    }

    return true;
  }

  return false;

} //END of               C h e c k T i m e ( )

//======================================================================
void StateMachine()
{
  //************** State Machine section **************
  switch (mState)
  {
    //***************************
    case StateStart:
      //code for this state goes here

      //example below, how to change the machine state
      mState = State1; //now switching to State1

      break;

    //***************************
    case State1:
      //is it time to run this section of code?
      if (CheckTime(State1Millis, State1WaitTime, State1Restart, State1EnableFlag))
      {
        Task1();
        //other state code here
      }

      mState = State2;

      break;

    //***************************
    case State2:
      //is it time to run this section of code?
      if (CheckTime(State2Millis, State2WaitTime, State2Restart, State2EnableFlag))
      {
        Task2();
        //other state code here
      }

      mState = State3;

      break;

    //***************************
    case State3:
      //is it time to run this section of code?
      if (CheckTime(State3Millis, State3WaitTime, State3Restart, State3EnableFlag))
      {
        Task3();
        //other state code here
      }

      mState = State4;

      break;

    //***************************
    case State4:
      //is it time to run this section of code?
      if (CheckTime(State4Millis, State4WaitTime, State4Restart, State4EnableFlag))
      {
        Task4();
        //other state code here
      }

      mState = State1;

      break;

    //***************************
    default:
      // default code goes here
      break;

      //***************************

  } // end of switch/case

} //END of             S t a t e M a c h i n e ( )

//======================================================================
void Task1()
{
  //example code
  digitalWrite(FirstLED, !digitalRead(FirstLED));
  //Other stuff

} //END of                   T a s k 1 ( )

//======================================================================
void Task2()
{
  //example code
  digitalWrite(SecondLED, !digitalRead(SecondLED));
  //Other stuff

} //END of                   T a s k 2 ( )

//======================================================================
void Task3()
{
  //example code
  digitalWrite(ThirdLED, !digitalRead(ThirdLED));
  //Other stuff

} //END of                   T a s k 3 ( )

//======================================================================
void Task4()
{
  //example code
  digitalWrite(FourthLED, !digitalRead(FourthLED));
  //Other stuff

} //END of                   T a s k 4 ( )

//======================================================================




//======================================================================
//                             END OF CODE
//======================================================================

Edit:
Updated sketch

Yup, that's where all the cold air originates!

CrossRoads:
Yup, that's where all the cold air originates!

No way, Alaska is where it comes from!

.

No way, Alaska is where it comes from!

Well, it got over to Vermont last night: -9F according to a DS18B20 . Brought a lot of snow with it.

Gotta remember to shovel the path to the emergency plumbing...

You wouldn’t want to be in there this time of year.

OMG, what happens if Mrs. Terry was in there when the snow came down? :fearful:

I assume you have a DS18B20 in the hut. :wink: