Turning on Digital pins w/ timer

So I'm new to Arduino. I've been referencing many sources but can't see to figure out how to turn on two different digital pins with a timer. I want Pin 2 & 4 to come on for 10 seconds on alternate days.

day 1 - noon - pin 2
day 2 - noon - pin 4
day 3 - noon - pin 2
day 3 - noon - pin 4
and so on....

I tried using milli seconds...but that doesn's seem to work.

Can someone help me with the code?

cmtittiger:
So I’m new to Arduino. I’ve been referencing many sources but can’t see to figure out how to turn on two different digital pins with a timer. I want Pin 2 & 4 to come on for 10 seconds on alternate days.

day 1 - noon - pin 2
day 2 - noon - pin 4
day 3 - noon - pin 2
day 3 - noon - pin 4
and so on…

I tried using milli seconds…but that doesn’s seem to work.

Can someone help me with the code?

Maybe.

Code for using which hardware?

“Ethernet Shield” and getting time by NTP from a NTP time server, maybe?

Or getting time from a RTC /(realtime clock module?

You will need to have some kind of “time source”, for finding out when it is “noon”.

Dang forum!! Used to be that if someone posted while you were typing, you'd be warned to check your post. Now it just dumps your post with no warning!

Ok, will try again:

unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedTime;
// Initial time to start, 00:00:00 with 0 years, 0 days. 
// adjust as needed.
// Get this working, then more display code if needed
byte hundredths;
byte tenths;
byte secondsOnes = 0;
byte oldsecondsOnes;
byte secondsTens = 0;
byte secondsTOtal;    // added for alarm check
byte minutesOnes = 0;
byte minutesTens = 0;
byte minutesTotal;    // added for alarm check
byte hoursOnes= 0;
byte hoursTens = 0;
byte hoursTotal;    // added for alarm check
int days = 0; //
byte years = 0;

void setup(){
Serial.begin(115200); // make serial monitor match
Serial.println ("Setup Done");
}
void loop(){
currentMicros = micros();
// how long's it been?
elapsedTime = currentMicros - previousMicros;
if ( elapsedTime >=10000UL){  // 0.01 second passed? Update the timers
previousMicros  = previousMicros + 10000UL;
hundredths = hundredths+1;
if (hundredths == 10){
    hundredths = 0;
    tenths = tenths +1;
    if (tenths == 10){
        tenths = 0;
        secondsOnes = secondsOnes + 1;
        if (secondsOnes == 10){
            secondsOnes = 0;
            secondsTens = secondsTens +1;
            if (secondsTens == 6){ 
                secondsTens = 0;
                minutesOnes =  minutesOnes + 1;
                if (minutesOnes == 10){
                    minutesOnes = 0;
                    minutesTens = minutesTens +1;
                    if (minutesTens == 6){
                        minutesTens = 0;
                        hoursOnes = hoursOns + 1;
                          if (hoursOnes == 10){
                              hoursOnes = 0;
                              hoursTens = hoursTens +1;
                                if ( (hoursTens == 2) && (hoursOnes == 4){
                                      hoursOnes = 0;
                                      hoursTens = 0;
                                      if (days>1){
                                          days = days-1;
                                           }
                                      else {
                                         days = 365;
                                         years = years - 1;
                                         }
                                    
                                      } // 24 hr rollover check
                                   } //hoursTens rollover check
                              } // hoursOnes rollover check
                        } // minutesTens rollover check
                     } // minutesOnes rollover check
                 } // secondsTens rollover check
              } // secondsOnes rollover check
          } // tenths rollover check
       } // hundredths rollover check
} // hundredths passing check

if (oldSecondsOnes != secondsOnes){  // show the elapsed time
oldSecondsOnes = secondsOnes;
Serial.print (years);
Serial.print(":");
Serial.print(days);
Serial.print(":");
Serial.print(hoursTens);
Serial.print(hoursOnes);
Serial.print(":");
Serial.print(minutesTens);
Serial.print(minutesOnes);
Serial.print(":");
Serial.print(secondsTens);
Serial.println(secondsOnes);

} // end one second check
// add alarm check
if ( (hoursTotat == 12) && (minutesTotal == 0) && ( (secondsTotal >= 0) && (secondsTotal <=10) ){ //12:00:00 to 12:00:10
if ( (days & 0b00000001) == 1) { // 1 = odd days, 0 = even days
digitalWrite (2,  HIGH); // odd day turn on
}
else {
digitalWrite (4, HIGH); // even day turn on
}
else {
digitalWrite (2, LOW); // outside of time window turn both off
digitalWrite (4, LOW);
}

} // end loop

Uno 101

cmtittiger:
Uno 101

What's that?

I know about "Arduino UNO" and "Arduino 101".

"Arduino 101" seems to be using the Wiznet W5500 Ethernet chip.

The default "Ethernet" library which comes with the Arduino IDE only supports Wiznet W5100.

You will need a different/updated Ethernet library for using the W5500 Ethernet chip.

After installing such a library, the Ethernet example sketches should work, which come with the IDE.

In case you are referring to "Arduino 101" board, install a suitable Ethernet library for W5500.

Then, from the IDE, open ecample sketch:

  • File-Examples-Ethernet-UdpNtpClient

Give it a try and do a test, if you are able to get current time from a NTP time server!