Go Down

### Topic: How to tell when 5 mins have gone by with Real Time Clock Module (Read 1 time)previous topic - next topic

#### mlandergan

##### Apr 04, 2013, 02:01 am
So my after school group at my high school is competing in an autonomous sail boat competition and one of the challenges is to have your boat stay in this given area for 5 mins then drive out of the box. Our sail boat will have an arduino uno accompanied with a gps/compass and wind sensor. I know the arduino can't tell time alone so I found the Real Time Clock Module from sparkfun. https://www.sparkfun.com/products/99 I want to know if its possible to create a program that can tell when 5 minutes has gone by?

Any help much appreciated I have experimented with arduino's a good amount just never with a timing circuit.

#### Retroplayer

#1
##### Apr 04, 2013, 02:49 amLast Edit: Apr 04, 2013, 02:53 am by Retroplayer Reason: 1
Actually, for this purpose it is capable...

Just use millis(). This will count the number of milliseconds since the last reset. Capture the current count at the point your boat enters the box and then keep checking it until it reaches 300000 + captured millis() or, you could count millis() and increment another counter every 1000 for 1 second, then another counter for 60 seconds for 1 minute. etc... some interrupts and while() loops may interfere with millis() so if your boat is expected to simply sit there and do nothing, turn off interrupts when you begin counting.

Code: [Select]
`void loop(){...   If(inside box){     count();   }}void count(){startmillis = millis();stopmillis = startmillis + 300000;while(millis() < stopmillis){}return;`

#### pylon

#2
##### Apr 04, 2013, 06:36 pm
Quote
some interrupts and while() loops may interfere with millis() so if your boat is expected to simply sit there and do nothing, turn off interrupts when you begin counting.

That's a bad idea because the millis() functionality is driven by a timer interrupt. If you turn off interrupts millis() will never increase.

#### wildbill

#3
##### Apr 04, 2013, 07:14 pm
You probably don't need the RTC at all; you can use millis to time five minutes for you as already mentioned or you can get the time from the GPS. I imagine you'll be parsing the  NMEA \$GPGGA sentence to get position information - it has the time in it too.

#### mlandergan

#4
##### Apr 04, 2013, 09:30 pm
How would I be able to tell when 5 mins have gone by with the gps? I have been able to get readings from it

#### Retroplayer

#5
##### Apr 04, 2013, 09:40 pm
Same method... you record the time at the beginning of the event, add 5 minutes to it, and then test for the current time to match the projected time within a loop.

#### AlxDroidDev

#6
##### Apr 04, 2013, 09:46 pm
What does the GPS have to do with the time keeping? The Arduino will keep time and when 5 mins have elapsed it will do something with the GPS.

If you insist on using the RTC (since you already bought it), some of them have programmable interrupts. For example, the DS1337+ can be programmed to generate a HIGH signal in a digital pin (your interrupt int) in 300 seconds. Therefore you don't have to worry about timekeeping in your code. You choose a pin that will receive the interrupt signal from the RTC, define how the interrupt should work (enable HIGH or LOW) and what function is to be called when the event happens.

If you got the DS1307 breakout board from Sparkfun, I don't think it has an Interrupt signal (that is why I prefer the DS1337+ over the DS1307 anytime).
Some of my projects:
Shield for DS1337+, DS1624 and AT24C1024B (RTC, temp & mem): http://forum.arduino.cc/index.php/topic,126197.0.html
CHDK Camera remote shutter (BT, IR, USB): http://forum.arduino.cc/index.php?topic=295377.0

#### mlandergan

#7
##### Apr 05, 2013, 12:09 am
I haven't bought the RTC because I wanted to make sure that is what I needed, now I am not going to get it and just use millis Thanks for the help everyone much appreciated

#### Retroplayer

#8
##### Apr 05, 2013, 12:19 am
BTW, there is an example in the playground on this site for getting the time from your GPS module. Unfortunately, I can't link to it because I can't get the playground section to open. It is located in the time section of the playground.

Go Up

Please enter a valid email to subscribe