Go Down

Topic: Clock (Hours and Mins) Project (Read 760 times) previous topic - next topic

Jackaroo

Thank you very much for pointing me in the right direction, so I'd need 24 of them? And I only just got the relays, they were listed at 4.2V-6V, but didn't mention current and I haven't had a chance to test them... I found some on a website and they said they'd work with Arduino boards though :)

dc42

If you have a multimeter, measure the resistance of a relay coil, then you can work out the current @ 5V (Ohms's Law). If it's less than 40mA then you can drive it directly from an Arduino pin - although you must connect a diode in parallel with the coil to absorb the back emf when you turn it off.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

CrossRoads

I've got my clock code fixed. It actually tracks time correctly now - was 6 hours off this morning! Finally realized I reset the hours when time rolled over at 30:00 instead of 24:00 - oops!

Running again now, made it past midnight okay. Running in sync since I reset it around 7:00pm.
Code: [Select]

unsigned long currentmicros = 0;
unsigned long nextmicros = 0;
unsigned long interval = 10000;

byte tens_hours = 1;
byte ones_hours = 8;
byte tens_minutes = 5;
byte ones_minutes = 4;
byte tens_seconds = 3;
byte ones_seconds = 0;
byte tenths = 0;
byte hundredths= 0;

byte prior_seconds = 0;

void setup()

{
  Serial.begin(57600);
  nextmicros = micros();
}

void loop()

{

  currentmicros = micros(); // read the time.

  if ((currentmicros - nextmicros) >= interval) // 10 milliseconds have gone by

  {

    hundredths = hundredths +1;

    if (hundredths == 10){
      hundredths = 0;
      tenths = tenths +1;
    }

    if (tenths == 10){
      tenths = 0;
      ones_seconds = ones_seconds +1;
    }

    if (ones_seconds == 10){
      ones_seconds = 0;
      tens_seconds = tens_seconds +1;
    }

    if (tens_seconds == 6){
      tens_seconds = 0;
      ones_minutes = ones_minutes +1;
    }

    if (ones_minutes == 10){
      ones_minutes = 0;
      tens_minutes = tens_minutes +1;
    }

    if (tens_minutes == 6){
      tens_minutes = 0;
      ones_hours = ones_hours +1;
    }

    if (ones_hours == 10){
      ones_hours = 0;
      tens_hours = tens_hours +1;
    }
    if ((tens_hours == 2) && (ones_hours == 4)){
      ones_hours = 0;
      tens_hours = 0;
    }

    nextmicros = nextmicros + interval; // update for the next comparison

  }  // end time interval check

  // counters are all updated now, send to display

  if (prior_seconds != ones_seconds){

    Serial.print (tens_hours, DEC);
    Serial.print (" ");
    Serial.print (ones_hours, DEC);
    Serial.print (" : ");
    Serial.print (tens_minutes, DEC);
    Serial.print (" ");
    Serial.print (ones_minutes, DEC);
    Serial.print (" : ");
    Serial.print (tens_seconds, DEC);
    Serial.print (" ");
    Serial.println (ones_seconds, DEC);

    prior_seconds = ones_seconds;   // show time update once/second
  }  // end one second passing check
 
  // do other stuff in the meantime ...

} // end void loop
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Jackaroo

Sorry for the slow reply, been away and didn't have an internet connection...


If you have a multimeter, measure the resistance of a relay coil


Tried it and got a value of 1, which can't be right... So I'm not sure what to do about that. Should I be checking while it's switching? Or is just putting a multimeter across it okay? Sorry for my poor knowledge on this...

Thanks again CrossRoads, I am trying my hardest to understand what is going on, fear I may have jumped in at the deep end...

I understand all the if's apart from the last two

if (ones_hours == 10){
      ones_hours = 0;
      tens_hours = tens_hours +1;

why can't it equal 12? And then for turning all my relays on would I just write something like, 

if  10< x <15 turn led10 on...


I know that's not how you'd code it but is that what replace the serial.print?

Thanks again :)

retrolefty

Quote
Tried it and got a value of 1, which can't be right... So I'm not sure what to do about that. Should I be checking while it's switching? Or is just putting a multimeter across it okay? Sorry for my poor knowledge on this...


You have to measure the relay coil resistance 'out of circuit', meaning no other wires (or diode) attached to the relay coil, just the multimeter leads across the relay coil terminals.

Lefty

CrossRoads

I didn't test for 12 because I track the value of each digit seperately so they can be each be displayed on their own 7-segment display.
You will have a digit for 10, 11, and 12? Then test for those and rollover when you hit 13.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up