HOWTO make a binary clock using Arduino

This is a tutorial on how to make a binary clock using  Arduino .

What you’ll need :

  • 10 LEDs + 220 ohm resistors
  • Arduino Uno (Thats what i used , but any would do)
  • Wires
  • Breadboard

I’ll be showing how to  make a binary clock with hours and minutes , but if you understand the code and have enough pins on your boar you can easily modify the code for including seconds .

If you are using the Uno , then its kinda tough to fit in seconds because that will require 16 digital pins . You could manage it with the analog ones though .

If you see how binary numbers proceed , then you’ll notice that the state of the left-most bit i.e. the LSB changes for every change in state of the number as a whole .The 2nd bit from the left changes after every 2 changes of state , 3rd after every 4 etc . So if a number MOD 4 = 0 , then the state of the 3rd bit toggles .

Example :: 5 is 101 in binary .

next state is 6 . Now , 6 MOD 1 = 0 , so 1st bit will toggle .

6 MOD 2 =0 , so 2nd bit will toggle .

6 MOD 4 is not equal to 0 , hence value of 3rd bit doesn’t change .

so , 6 -> 110 in binary .

This is the logic that I have used .

int state_1=1 ,state_2=1 ,state_4=1 ,state_8=1 ,state_16=1,state_32=1 ;
int count=0 ;
int hour1=0 , hour2=0 ,hour3=0 , hour4=0 ;
int count2=0 ;
void setup()
{
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);

} ;
void loop()
{
if(count == 60 )
{
count = 0 ;
count2++;
if (count2==13)
{
count2=1 ;
}
//hour1
if (hour1==1)
{
hour1=0 ;
digitalWrite(7,LOW);
}
else
{
hour1=1 ;
digitalWrite(7,HIGH);
}
//hour2
if (count2%2==0)
{
if (hour2==1)
{
hour2=0 ;
digitalWrite(8,LOW);
}
else
{
hour2=1 ;
digitalWrite(8,HIGH);
}
}
//hour3
if (count2%4==0)
{
if (hour3==1)
{
hour3=0 ;
digitalWrite(9,LOW);
}
else
{
hour3=1 ;
digitalWrite(9,HIGH);
}
}

if (count2%8==0)
{
if (hour4==1)
{
hour4=0 ;
digitalWrite(10,LOW);
}
else
{
hour4=1 ;
digitalWrite(10,HIGH);
}
}
state_1=1 ;state_2=1 ;state_4=1 ;state_8=1 ;state_16=1;state_32=1;
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
}

//minutes

//toggle state_1
if (state_1==1)
{
state_1=0 ;
digitalWrite(1,LOW);
}
else
{
state_1=1 ;
digitalWrite(1,HIGH);
}

//toggle state_2
if (count%2==0)
{
if (state_2==1)
{
state_2=0 ;
digitalWrite(2,LOW);
}
else
{
state_2=1 ;
digitalWrite(2,HIGH);
}
}
//toggle state_4
if (count%4==0)
{
if (state_4==1)
{
state_4=0 ;
digitalWrite(3,LOW);
}
else
{
state_4=1 ;
digitalWrite(3,HIGH);
}
}
//toggle state_8
if (count%8==0)
{
if (state_8==1)
{
state_8=0 ;
digitalWrite(4,LOW);
}
else
{
state_8=1 ;
digitalWrite(4,HIGH);
}
}

//toggle state_16
if (count%16==0)
{
if (state_16==1)
{
state_16=0 ;
digitalWrite(5,LOW);
}
else
{
state_16=1 ;
digitalWrite(5,HIGH);
}
}

//toggle state_32
if (count%32==0)
{
if (state_32==1)
{
state_32=0 ;
digitalWrite(6,LOW);
}
else
{
state_32=1 ;
digitalWrite(6,HIGH);
}
}

delay(60000);
count++ ;
}

Minute bits have value till 59(111011) . So , we will require 6 LEDs to show the minutes . And I have considered the 12-hour format , so that means I’ll need 4 LEDs for hours . A 24-hour format will require 5 LEDs .

Here are 2 images showing the time as 12:11 and 12:53 !

Cheers !

Advertisements

Question papers !

2010(08)

2010(03)

2009(08)

2009(03)

Here are the papers that i found .
If anyone has got papers not included above , you can send me a mail so that i can put them up here !
Cheers !