www.ElectronicSharing.com
The site which shares a electronic information


   
Binary Clock with Arduino
name : Toms Date : 07-21-2008
View : 148 Modify    Delete
File #1 :
File #2 :
File #3 : 211.197.136.102



 

Yesterday I was going to start watching a movie, when me and my friend pedro decided to give up on the movie and build a binary clock. After sometime thinking on how to program it, we made it. It works beautifully, so I decided to show here how I’ve done. It may not be the easiest way to make it work, but that’s what we’ve done.

 

Parts:
- Arduino
- 13x Leds (You choose the color)
- 13x 220Ohms Resistors
- 3x 2.2KOhms Resistos
- 2x Push-Buttons
- 1x Normal Button
- Bread Board
- Wire

Well, this is a quite simple circuit, but can be tricky for some people, so I will try to explain how it work and how to assemble.

How it works

leds1.png

binary-example.png

I think with this images you can understand how it will work. The leds which are on, you just need to sum the numbers, and it will give current time.

Assembling
To assemble the circuit, you will need to connect first the resistors and leds. To do it, just hook up leds + resistor from the pin 1 to 13. Remember that the bigger leg of the led is positive, and need to be connected to arduino output pin, and the other leg should be on the ground.

So that the code will work for the circuit, you should use the leds like this, LED 1 to PIN 1, LED 2 to PIN 2, and so on…

imagem-binario.png

For connecting the buttons, I’ve used one digital input and two analog inputs. To set change the hour/minute, you will need to use two push-buttons. And they need to be connected to the analog input pin 0 and 5. And to turn leds ON/OFF I’ve used a normal button that is connected to digital input pin 0. To make it work, you need use one leg of the buttons on a 2.2K Ohm resistor connected to the 5V output together with the analog/digital input, and the other leg going to the ground, something like this:

button1.png

If you don’t understand what I am trying to explain, you can go to the arduino website here.

Images + Video

Binary Clock II

Binary Clock I

Code
The clock code is based on the open-source-arduino-clock by Rob Faludi. I’ve made many changes, but the time counting the basically the same. So if you want to make another kind of clock, I suggest you to take a look on that website.

If the code below isn’t working, you can download it as .txt HERE.

int second=0, minute=0, hour=0; //start the time on 00:00:00
int munit,hunit,valm=0,valh=0,ledstats,i;

void setup() { //set outputs and inputs
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);
pinMode(11, OUTPUT);pinMode(12, OUTPUT);pinMode(13, OUTPUT);

pinMode(0, INPUT);
}

void loop() {

static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
// move forward one second every 1000 milliseconds

if (millis() - lastTick >= 1000) {
lastTick = millis();
second++;

}

// move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // reset seconds to zero
}

// move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // reset minutes to zero
}

if (hour >=24) {
hour=0;
minute = 0; // reset minutes to zero
}

munit = minute%10; //sets the variable munit and hunit for the unit digits
hunit = hour%10;

ledstats = digitalRead(0); // read input value, for setting leds off, but keeping count
if (ledstats == LOW) {

for(i=1;i< =13;i++){
digitalWrite(i, LOW);}

} else {

//minutes units
if(munit == 1 || munit == 3 || munit == 5 || munit == 7 || munit == 9) { digitalWrite(1, HIGH);} else { digitalWrite(1,LOW);}
if(munit == 2 || munit == 3 || munit == 6 || munit == 7) {digitalWrite(2, HIGH);} else {digitalWrite(2,LOW);}
if(munit == 4 || munit == 5 || munit == 6 || munit == 7) {digitalWrite(3, HIGH);} else {digitalWrite(3,LOW);}
if(munit == 8 || munit == 9) {digitalWrite(4, HIGH);} else {digitalWrite(4,LOW);}

//minutes
if((minute >= 10 && minute < 20) || (minute >= 30 && minute < 40) || (minute >= 50 && minute < 60)) {digitalWrite(5, HIGH);} else {digitalWrite(5,LOW);}
if(minute >= 20 && minute < 40) {digitalWrite(6, HIGH);} else {digitalWrite(6,LOW);}
if(minute >= 40 && minute < 60) {digitalWrite(7, HIGH);} else {digitalWrite(7,LOW);}

//hour units
if(hunit == 1 || hunit == 3 || hunit == 5 || hunit == 7 || hunit == 9) {digitalWrite(8, HIGH);} else {digitalWrite(8,LOW);}
if(hunit == 2 || hunit == 3 || hunit == 6 || hunit == 7) {digitalWrite(9, HIGH);} else {digitalWrite(9,LOW);}
if(hunit == 4 || hunit == 5 || hunit == 6 || hunit == 7) {digitalWrite(10, HIGH);} else {digitalWrite(10,LOW);}
if(hunit == 8 || hunit == 9) {digitalWrite(11, HIGH);} else {digitalWrite(11,LOW);}

//hour
if(hour >= 10 && hour < 20) {digitalWrite(12, HIGH);} else {digitalWrite(12,LOW);}
if(hour >= 20 && hour < 24) {digitalWrite(13, HIGH);} else {digitalWrite(13,LOW);}

}

valm = analogRead(0); // add one minute when pressed
if(valm<800) {
minute++;
second=0;
delay(250);
}

valh = analogRead(5); // add one hour when pressed
if(valh<800) {
hour++;
second=0;
delay(250);
}

}

Binary Clock III

Hope you liked, any question just ask! And if you make your own, send me pics =)


>>> All information is reserved by users. The right of posted writing is reserved by related users or companies. <<<
>>> Request for deleting related writing : jixjix@gmail.com <<<