Little help with Arduino timed relays, Thank you!

Hello,

I'm new with programming and never did any programming. I need to make an automated radio message relay.

For this I am considering Arduino, I've ordered an arduino Uno and a 4 relay module, the relay's will act like button pushers for a radio transmitter and an mp3 player.

Relay 1: Activates the radio transmitter
Relay 2: Acts as a Key press for Play button on the Mp3 Player
Relay 3: Acts as a Key press for Stop button on the Mp3 Player
Relay 4: Activates a Standby LED

This is the code I've managed to write and since my Arduino has not arrived yet, I have no way to test the code and I don't know how to formulate a delay until milliseconds count reaches a certain value:

/*

Automated Radio Relay

*/

void setup() {
pinMode(13, OUTPUT); //radio
pinMode(12, OUTPUT); //play
pinMode(11, OUTPUT); //stop
pinMode(10, OUTPUT); //led
}

void loop() {

timer0_overflow_count=0; //reset millis to 0 at top of each loop so no overflow issues

digitalWrite(13, HIGH); //Activates Transmitter
digitalWrite(12, HIGH); //Activates Play Button on Mp3 Player
delay(500); //0.5 Seconds Delay
digitalwrite(12, LOW); //Deactivates Play Button on Mp3 Player
digitalWrite(11, LOW); //No action on the Stop Button
digitalWrite(10, LOW); //Deactivates the Standby LED
delay(38000); //Delays any action until transmision message ends

digitalWrite(13, LOW); //Deactivates the Transmitter
digitalWrite(12, LOW); //No action on the Play Button
digitalWrite(11, HIGH); //Activates the Stop Button
delay(500); //0.5 Seconds Delay
digitalWrite(11, LOW); //Deactivates the Stop Button
digitalWrite(10, HIGH); //Activates the Standby LED

delay(until millis equals:1500000); //here is my problem how do I formulate this?
}

Sorry to be negative but I think that you are going about this in the wrong way. Looking at your code it seems that the system can be in one of several states. During each state actions take place until a certain time has passed. This would lend itself to implementing a finite state machine (FSM). It sound scary but isn't.

Give each state a number starting at zero. Write down what happens when the system is in that state, what causes it to leave that state and the state number that it moves to.

Something like
state 0: turn on transmitter. start mp3 player. wait 500ms. move to state 1
state 1: turn off mp3 player. turn off LED. wait 38 seconds. move to state 2
etc, etc

Now you can write some code. The first thing to do is to give the pins names that you can refer to later
const int playButton = 12; etc

Set state to 0 initially and startedStateTime = millis() then
start of loop
if state equals zero
  if millis() - startedStateTime > 500  //time's up
    set state to 1
    set startedStateTime = millis() 
  end of if

  if state equals 1
    //do stuff in state 1 until time is up
    set state to 2
    set startedStateTime = millis() 
  end if

//and so on
end of loop

Thank you for that, as I was saying I've never, ever done any programming, so that code was my first attempt at it.

So to make me understand, the code that I have is not going to work? The code you just presented me far exceeds my knowledge when it comes to coding.

From the examples I've found over the internet my code should work fine until the last line

delay(until millis equals:1500000);

That part eludes me, I need the loop to wait for ~30 minutes before starting again.

If I give this command

digitalWrite(13, HIGH);

Then pin 13 remains HIGH until it's given a command to set it to LOW right?

If I knew any advanced or even beginner programming I would do it like you instructed me, but I can't really understand what you just showed me.

I don't need this to be precise, it can have minutes in delay and still work fine for me. As long as the message gets sent over the radio at some intervals of time it's great.

Thank you.

You already have instances of delays in your program.

  delay(500);               //0.5 Seconds Delay
  delay(38000);             //Delays any action until transmision message ends - actually 38,000 milliseconds

So, can you guess what
delay(1500000);Might do ?

It is an ugly way to do it, but if it does what you want .....

To reassure you, the parameter for delay() can be up to 4,294,967,295 milliseconds which is about 41 days.

Thank you, that is what I wanted to know, I was certain that it was an ugly way to do it, but until I get my codding knowledge updated it will have to do.

I am waiting for my Arduino to be delivered and I will test it then.

Thank you very much.

My Arduino finally arrived and tested the code, it works great with one exception

This part is not written right, can you help me with it?

timer0_overflow_count=0;  //reset millis to 0 at top of each loop so no overflow issues

Thank you!

Why are you obsessed with setting millis() back to zero ?
If you use millis() correctly

if (millis() -  startTime >= interval)
  {
     //do stuff after the interval has elapsed
     startTime =millis();
  }

Then there is no need to reset millis(). The millis() value will overflow after about 41 days but the test will still work if all the variables used in the calculation are defined as unsigned long.