Need help with code; Calling Arduino programmers - The Planted Tank Forum
 
LinkBack Thread Tools Display Modes
post #1 of 7 (permalink) Old 05-23-2015, 02:50 AM Thread Starter
Planted Tank Enthusiast
 
sumer's Avatar
 
PTrader: (27/97%)
Join Date: Feb 2010
Location: FoCo, CO
Posts: 799
Need help with code; Calling Arduino programmers

Hey all,

This will probably sound like a very small problem to you all but I am finding it real hard.
So, I have a 2 ch solid state relay, and an arduino nano.

Here is what I want to do: I want to keep the relay off (pin "low") for 10 minutes and on (pin "High") for 20 seconds.

I have downloaded this library: http://playground.arduino.cc/Code/Timer
But I am not understanding how would I do what I want.

"Oscillate" is not working as I want it to.
Can anyone help me with the code?
here's what I have:

Code:
#include "Timer.h"                     //http://github.com/JChristensen/Timer

const int LED1 = 8;                    //connect one LED to this pin (with appropriate current-limiting resistor of course)
const int LED2 = 9;                    //connect another LED to this pin (don't forget the resistor)
const unsigned long PERIOD1 = 1000;    //one second
const unsigned long PERIOD2 = 10000;   //ten seconds
Timer t;                               //instantiate the timer object

void setup(void)
{
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    
    t.oscillate(LED1, PERIOD1, HIGH);
    t.oscillate(LED2, PERIOD2, HIGH);
}

void loop(void)
{
    t.update();
}

||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

sumer is offline  
Sponsored Links
Advertisement
 
post #2 of 7 (permalink) Old 05-23-2015, 02:57 AM
Planted Tank Obsessed
 
PTrader: (0/0%)
Join Date: Jan 2014
Location: Denver, CO
Posts: 400
Code:
int pin = 8;

void setup()
{
  pinMode(pin, OUTPUT);
  digitalWrite(pin, HIGH);
}

void loop()
{
  digitalWrite(pin, HIGH);
  delay(600000); // 10mins
  digitalWrite(pin, LOW);
  delay(20000); // 20s
}


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

5 Gal Tropic Nano w/SunSun 603b,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by nayr; 05-23-2015 at 03:10 AM. Reason: code
nayr is offline  
post #3 of 7 (permalink) Old 05-23-2015, 03:00 AM Thread Starter
Planted Tank Enthusiast
 
sumer's Avatar
 
PTrader: (27/97%)
Join Date: Feb 2010
Location: FoCo, CO
Posts: 799
Is delay the ONLY option?
Isn't there any other way to do this?

||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Last edited by sumer; 05-23-2015 at 03:13 AM. Reason: options
sumer is offline  
 
post #4 of 7 (permalink) Old 05-23-2015, 03:13 AM
Planted Tank Obsessed
 
PTrader: (0/0%)
Join Date: Jan 2014
Location: Denver, CO
Posts: 400
oscillation implies it will be equal time between high/low.. so its inappropriate for your need.

delay accomplishes what you want, what is the issue with it?


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

5 Gal Tropic Nano w/SunSun 603b,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
nayr is offline  
post #5 of 7 (permalink) Old 05-23-2015, 03:16 AM Thread Starter
Planted Tank Enthusiast
 
sumer's Avatar
 
PTrader: (27/97%)
Join Date: Feb 2010
Location: FoCo, CO
Posts: 799
That's true. Well, Seems like delay is what I will have to use.
I will go with it. Next thing is to make it work with a 4 way Rotary Switch so that I can predefine 4 time intervals.
Thanks very much, Nayr.
Do you happen to come to CAS meetings? Have we met there?

||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

sumer is offline  
post #6 of 7 (permalink) Old 05-23-2015, 03:28 AM
Planted Tank Obsessed
 
PTrader: (0/0%)
Join Date: Jan 2014
Location: Denver, CO
Posts: 400
Well there are multiple ways to skin a cat, or so I hear..

this one is using elapsedMills.h and keeps slamming through the loop over and over instead of waiting for the next action.. The interval could be easily be determined by inputs.

Code:
#include <elapsedMillis.h>
int pin = 13;  

elapsedMillis timer0;
#define interval 620000  // 10mins and 20s
// the interval in mS 

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(pin, OUTPUT);
  digitalWrite(pin, HIGH);
  timer0 = 0; // clear the timer at the end of startup
}

void loop() {
  if (timer0 <= 600000) { // Off for 10mins
    digitalWrite(pin, HIGH);
  } else if (timer0 > interval){
    timer0 -= interval; // Reset Timer
  } else {
    digitalWrite(pin, LOW); // On for 20s
}
I havent been to any local meetings..


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

5 Gal Tropic Nano w/SunSun 603b,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
nayr is offline  
post #7 of 7 (permalink) Old 05-23-2015, 01:02 PM
Children Boogie
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 16,743
You can use the TimeAlarms library to create a schedule

http://www.pjrc.com/teensy/td_libs_TimeAlarms.html

Also for accurate time, you'll need the Time.h library and an RTC or a Time Server update.
mistergreen is offline  
Reply

Tags
None

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome