/ arduino

Binary second counter with Arduino

Just got my Arduino. Got to play around with it with my girlfriend. As our first project we decided to write a binary second counter.

The logic is simple. There are six leds. And simply count from 0 to 59 in binary using the leds. The video of it is as below;

As one can see it is a simple sample. The circuit itself is also simple. I used the pins from    8-13 for this job. And the code is as below ;

 led0 = 8;
 led1 = 9;
 led2 = 10;
 led3 = 11;
 led4 = 12;
 led5 = 13;




 setup() {



   pinMode(led0, OUTPUT);
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
   pinMode(led3, OUTPUT);
   pinMode(led4, OUTPUT);
   pinMode(led5, OUTPUT);


 }





 loop() {





   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, LOW);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, LOW);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, LOW);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);




   digitalWrite(led0, HIGH);
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);


   delay(1000);


 }

As you can see the code is quite simple and very straight forward. I really do wonder however what is the error in those delays… I will need to research that.

Hope you like what you see!

Have fun coding!

John Roach

John Roach

I am John Roach, a devops architect. Find more information here: https://johnroach.io/about/

Read More
Binary second counter with Arduino
Share this