i want a helping in looping my program for a particular time interval

i have been trying to create a project based on traffic light where the red signal goes in for 5 sec and at that particular interval the Force sensing Resistors that will be used to check the movement of cars should be activated.while green and yellow FSR should not be taking any values an anyone help me in this programming .... please

Try formulating the problem in clear steps.

Imagine that we don’t know anything about your problem or your hardware ('cos we don’t)

Get back to us.

Hint: take the delay() out of your code. No, haven't seen you code.

Paul

i have an arduino uno ,three leds a red a green and a yellow as a traffic light has and an white led which gives an alarm if any vehicle moves while the traffic light is red.... an FSR that sense the movement this are all the components... the FSR should provide values only when the signal goes red

Have a look at how millis() is used to manage timing without blocking in Several things at a time.

And see Using millis() for timing. A beginners guide if you need more explanation.

If you need more help then please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R

the code for the fsr to work is given below i have to keep this loop for 5 sec and then stop it 7 sec after which it will again continue for 5 sec and so on

TLPS_test1.ino (1.3 KB)

Please read the how to use this forum sticky post. It will tell you how to post code correctly so we can all see it. Mobile devices can’t cope with .ino files.

When is this assignment due to be handed in?

vishal_07_:
the code for the fsr to work is given below i have to keep this loop for 5 sec and then stop it 7 sec after which it will again continue for 5 sec and so on

And what actually happens when you run that program?

Also, it is much easier to help if you include short programs in your Post so people don't have to download them. Use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum

...R

vishal_07_:
the FSR should provide values only when the signal goes red

Then you should only read and process the force data while the red led is on.

There are 2 Arduino time-return functions, micros() and millis(). Your traffic light does not need micros timing.

Reference > Language > Functions > Time > Millis
millis()
[Time]
Description
Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

Syntax
time = millis()

Parameters
None

Returns
Number of milliseconds passed since the program started. Data type: unsigned long.

So if I make unsigned long variables to track time the always correct formula to tell how long between any start and end less than 49.71-some days apart is:

end_time - start_time = elapsed time between start and end

If my code saves a start time and I want to know when 1 second has passed since then, I might do one of these;

if ( millis() - start_time >= 1000 ) // >= because with == you have a chance to miss the one exact match
{
// this runs when interval is over
}

but not one after the other in the same sketch,

if ( millis() - start_time < 1000 )
{
// this runs until interval is over
}

i have to keep this loop for 5 sec and then stop it 7 sec

You may know what you want but you don’t know how to do it without one part blocking the others for whole seconds at a time. You would benefit greatly by following the link in Reply #4.