Multiple alarms during set period

Hey guys,

I'm pretty new to this but I'm using Arduino for my research this semester.

Basically what I need to do is set times for conditioning with the apparatus I will ultimately create (I will be releasing an odor and heating a device simultaneously).

I need this apparatus to run from 9 am to 6 pm, and I need to turn on the odor device and heaters twice an hour (so every 30 minutes roughly, but it doesn't have to be exact) and be on for 1-2 minutes. I am just not quite sure how to go about doing this. I read about using the blink without delay sketch but not sure how i would modify it to these specifics.

I already have a DS1307 RTC connected and running.

Here is what i have so far regarding this (the code before is the sparkfun code to just connect the RTC). I know it's wrong but I am not quite sure what pieces I am missing.

uint32_t min = rtc.minute();

uint32_t hour = rtc.hour();

void loop () {
  if ((hour >= 9) || (hour <= 18)) {
  // turn on apparatus
  }
  
  else ((hour < 9 || (hour > 18 )) {
  // apparatus off
  }
  
  if ((min == 0) || (min == 30)) 
  {
  // release odor, turn on heat
  }

  else ((min != 0) || (min != 30)) {
  //don't release odor, turn off heat
  }
}

rebeccathurston:
Hey guys,

I'm pretty new to this but I'm using Arduino for my research this semester.

Basically what I need to do is set times for conditioning with the apparatus I will ultimately create (I will be releasing an odor and heating a device simultaneously).

I need this apparatus to run from 9 am to 6 pm, and I need to turn on the odor device and heaters twice an hour (so every 30 minutes roughly, but it doesn't have to be exact) and be on for 1-2 minutes. I am just not quite sure how to go about doing this. I read about using the blink without delay sketch but not sure how i would modify it to these specifics.

I already have a DS1307 RTC connected and running.

any help would be greatly appreciated, thanks!!

Every time through loop(), look at the minutes of the current time. If the minutes are either exactly 0 or exactly 30, then turn the odor device on. Otherwise, turn it off.

// assuming that variable "mi" contains the number of minutes

if ((mi==0) || (mi==30)) {
  // code to turn odor device ON goes in here

}
else {
  // code to turn odor device OFF goes in here

}

To understand this, you will need to know how to use if and else.
These two links are required reading for you:

and

[/code]

If you decide that 1 minute each half hour is not enough, and want it to be 2 minutes, then change this:

if ((mi==0) || (mi==30)) {

to this:

if ((mi==0) || (mi==1) ||  (mi==30) || (mi==31)) {

(Do you understand why? If you don't understand why, then read those two links again, carefully.)

Notice that, for any of this to work, you will need to store the number of minutes in a variable. Do you know how to do that?

Notice that I have only been paying attention to the minutes. I have been ignoring the hours, so this would turn the odor device on every half-hour, 24 hours a day.

Once you have the minutes working, then making the hours work will be the next step.

odometer:
Notice that, for any of this to work, you will need to store the number of minutes in a variable. Do you know how to do that?

Notice that I have only been paying attention to the minutes. I have been ignoring the hours, so this would turn the odor device on every half-hour, 24 hours a day.

Once you have the minutes working, then making the hours work will be the next step.

I understand most of that, thank you! I do not know how to store the minutes in a variable though

Can you post your current code?

Blackfin:
Can you post your current code?

everything before this was setting up the RTC using the sparkfun library. This is just what I have so far with the if/else statements but I know it's not completely right.

uint32_t min = rtc.minute();

uint32_t hour = rtc.hour();

if ((hour >= 9) || (hour <= 18)) {
 // turn on apparatus
}

else{
 // apparatus off
}  

if ((min == 0) || (min == 30)) {
 // release odor, turn on heat
}

else {
 //don't release odor, turn on heat
}

rebeccathurston:
everything before this was setting up the RTC using the sparkfun library. This is just what I have so far with the if/else statements but I know it's not completely right.

uint32_t min = rtc.minute();

uint32_t hour = rtc.hour();

if ((hour >= 9) || (hour <= 18)) {
// turn on apparatus
}

else{
// apparatus off
}

if ((min == 0) || (min == 30)) {
// release odor, turn on heat
}

else {
//don't release odor, turn on heat
}

I am not sure whether min and hour will work as variable names.

First, I am sure that min already has another meaning:

I am not sure whether that would make trouble for you.

Also, depending on what library you are using, hour might not work.

Maybe better to change your variable names. You could call them myHour and myMinute, or h and m (as long as those letters are not in use for something else), or alice and bob (although I don't recommend doing so, as their meaning will not be clear), or hourNow and minuteNow, or... I think you get the idea by now. As for myself, I just use hh and mi, but other people will scream at you not to.

I just noticed another flaw.

rebeccathurston:

if ((hour >= 9) || (hour <= 18)) {

// turn on apparatus
}

else{
// apparatus off
}

The || symbol means "or".

You have two conditions:

  • hour is greater than or equal to 9
  • hour is less than or equal to 18
    and you are turning on your apparatus any time at least one of those conditions is met.

For example, if the hour is 2, then the second condition (i.e. hour is less than or equal to 18) is met, and the apparatus will get turned on.

If the hour is 23, then the first condition (i.e. hour is greater than or equal to 9) is met, and the apparatus will get turned on.

Try using the && symbol instead. It means "and", as in "The first condition and the second condition must both be met -- one is not enough!".

OP started a second thread, same topic:

https://forum.arduino.cc/index.php?topic=598413.0