Drive a slave clock with arduino

Hej everyone!

When I saw this slave-clock I knew i need to have it :o) So now I soldered up a h-bridge with optocoupler because the clock needs the polarity reversed every 60 seconds to act like a clock ;o) So far it works quite good, but sometimes it seems the polarity gets switched every second (as i implemented in the code to set the time) WITHOUT the switch being operated ... I already added a 2.2k resistor on the 5v-side of the switch ... any hints apprectiated!

cheers, Max

here some pics: http://img146.imageshack.us/my.php?image=imgp1910lh0.jpg

http://img223.imageshack.us/img223/4744/imgp1917qe4.jpg

/*

 * SlaveClock

 * by Maximue

 *

 * Drives a slave clock requiring reversed polarity every minute

 * with an h-bridge

*/



int pin3 = 3;                // assign pins for switching optocuplers

int pin4 = 4;                  // "

int pin5 = 5;              // "

int pin6 = 6;                // "

int timerPin = 12;          // assign pin for timer-setting (eg switch to seconds)

int val = 0;



void setup() {

  pinMode(pin3, OUTPUT);     

  pinMode(pin4, OUTPUT);

  pinMode(pin5, OUTPUT);

  pinMode(pin6, OUTPUT);

  pinMode(timerPin, INPUT);

  Serial.begin(9600);

}



void loop(){

   val = digitalRead(timerPin);

   Serial.print(val);

   if (val == 0)

   {

       digitalWrite(pin4, HIGH);    // switch  every 60 seconds so the polarity is reversed

       digitalWrite(pin6, HIGH);

       delay(500);

       digitalWrite(pin4, LOW);    // switch  every 60 seconds so the polarity is reversed

       digitalWrite(pin6, LOW);

       delay(59000);

       digitalWrite(pin3, HIGH);

       digitalWrite(pin5, HIGH);

       delay(500);

       digitalWrite(pin3, LOW);

       digitalWrite(pin5, LOW);

       delay(59000);

     } 

   else  {

   

       digitalWrite(pin4, HIGH);    

       digitalWrite(pin6, HIGH);

       delay(500);

       digitalWrite(pin4, LOW);    

       digitalWrite(pin6, LOW);

       delay(500);

       digitalWrite(pin3, HIGH);

       digitalWrite(pin5, HIGH);

       delay(500);

       digitalWrite(pin3, LOW);

       digitalWrite(pin5, LOW);

       delay(500);    

       }

}

Are more of them available? Where did you get yours?

For some time, it has seemed to me that an "electronic pendulum clock" might be fun... AFTER I'd had the idea, I saw similar in a electonics hobby magazine, so I can't be alone. The Arduino and the slave clock mechanism might be good ingredients for the project!

Try taking the serial command out.

hey thanks for the replies - I'll delete the serial command but I think the delay maybe is due to the inaccurate clock (16mhz) of the arduino? I'm sorry, I have no source for the slave watch as i bought it for 3 euros in a salvation army shop called "BAN" in Graz (Austria) ... but check on ebay, I've seen serval there!

cheers, Max