Tuesday, March 28, 2017

Let's create 8 bit LED binary counter

Here, I am going to discuss how to create 8 bit LED binary counter using Arduino micro controller board . This binary counter  displays  decimal numbers from 0 to 255 in 8 bit binary format using 8 LEDs, where as 1 is represented by lighting only left most  (2)  LED.Number  representation will be increased from 0 to 255 automatically .
Following figure shows several lighting patterns according to the decimal value from 0 to 7.



        

Following items are needed .

  • 01 bread board
  • 08  LEDs
  • Arduino controller board (Here I used Arduino mega 2560)
  • Male to male jumper wires
  • Resistor( 270Ω) 

First let us consider  the source code.


void setup() {
//I used pins from 2 to 9 to connect LEDs’ positive polls. All LEDs’ negative polls are directly  grounded.
 int j =2;
 for(j;j<10;j++){
   pinMode(j,OUTPUT); // Define all pins as output pins
  }
}

void loop() {
//Generate corresponding signals to each LEDs
 for(int i=0;i<256;i++){
   byte a=i%2;    
   byte b=(i/2)%2;
   byte c=(i/4)%2;
   byte d=(i/8)%2;
   byte e=(i/16)%2;
   byte f=(i/32)%2;
   byte g=(i/64)%2;
   byte h=(i/128)%2;
  
// Giving signals to each pins
   digitalWrite(2,a);
   digitalWrite(3,b);
   digitalWrite(4,c);
   digitalWrite(5,d);
   digitalWrite(6,e);
   digitalWrite(7,f);
   digitalWrite(8,g);
   digitalWrite(9,h);
   delay(500);
    
 }

}

Here I used a simple mathematical equation to generate signals.

If we want to represent decimal value 6 using this binary counter, we only need to lit LED ‘2’ and ‘4’. All other LEDs should be off. So we need to set all output pins as follows.
digitalWrite(2,1)
digitalWrite(3,0)
digitalWrite(4,1)
digitalWrite(5,0)
digitalWrite(6,0)
digitalWrite(7,0)
digitalWrite(8,0)
digitalWrite(9,0)
Using above mathematical equation we can set values for each pin according to the  value that doing to represent using binary counter.
Following video shows how it is works on.

 


 If you like this post, spread by sharing it on social media. Thank you!




5 comments:

How to send Slack notification using a Python script?

 In this article,  I am focussing on sending Slack notifications periodically based on the records in the database. Suppose we have to monit...