Computers use binary, base 2 and therefore I think that it is very important that you understand what binary is and how to use it. If you understand and build the circuit that I describe here, it can help you to count in binary! Binary uses only two digits, 0 and 1. Each digit is called a bit. Any number from any number system can be represented in binary. To count in binary you start from the right, which is known as the least significant bit (LSB) and work towards your left, the most significant bit (MSB).

If there is a 0 in a column then you ignore it. If there is a 1 in a column then take note of the number above it. The decimal number is the sum of these numbers. In the diagram this would be 128 + 8 + 4 + 1 = 142.

To demonstrate this I built a binary counter with 8 outputs and 8 LEDs, which will count from 0 – 255. 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. In operation the circuit will count from 0 – 255 in binary, via the LEDs. This is an 8 bit counter. 8 bits is also known as a byte. If we expanded this circuit to use 16 LEDs, then it would be a 16 bit or 2 byte counter. This would be able to count from 0 – 65,535.

## THE HARDWARE

You can use an UNO or MEGA

You will need 8 LEDs. Or you can use an 8 digit bargraph, which is what I prefer. It’s neater and more compact.

You will need 8 220Ω resistors.

First I create an array, with the data type of int.

``int ledPins[] = {9, 8, 7, 6, 5, 4, 3, 2};``

Number to display.

``byte count;``

In the setup() I set each pin to be an OUTPUT and default to 0.

``````void setup(void) {
for (byte i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
count = 0;
}``````

In the loop() I increase, display and delay.

``````void loop(void)
{
dispBinary(count++);
delay(1000);
}``````

Show a single number

``````void dispBinary(byte n)
{
for (byte i = 0; i < 8; i++) {
digitalWrite(ledPins[i], n & 1);
n /= 2;
}
}``````