Arduino Uno binary counter project

Arduino Binary Counter

This Arduino binary counter project will help you count from 0 to 7 with Arduino Uno. The project uses three LEDs to simulate the binary counter. This is a simple and cool way of learning or practicing binary with Arduino microcontrollers.

LED projects are a good way for starters to learn how to program Arduino.

You will also have fun along the way.

How the Arduino Binary Counter Works

The table shows the binary equivalent of decimal numbers from 0 to 7;

Decimal Number Binary (led3,led2,led1)
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

LED1 is the least significant bit (on the right) while LED 3 is the most significant bit (on the left).

The 1’s in the table indicate which LED turns on at a given time. Red circles show the LEDs that are on.

Arduino project 3 leds binary counter

A delay of 1s is experienced between each count.

You will require;

1 x Arduino Uno

A-B Arduino USB cable

3 x 1k ohm Resistors (You can use 330 ohms for more brightness)

Jumper wires

A mini breadboard

Instructions for Arduino Binary counter Project

Connect the circuit as shown above.

  • Fix the LEDs on the breadboard
  • Connect the resistor from the cathode of one LED to the common ground on the breadboard
  • Repeat this for the other 2 LEDs
  • Connect the LED on your right to pin 7 of Arduino
  • Connect the next LEd to pin 8
  • Next, connect the other LED, on your left, to pin 9 of Arduino
  • Finally, run a cable from GND of Arduino to the common ground on the breadboard.

Binary counter Arduino Program Code

/**************************************
 * Source: www.jitimu.com/learn-stem
 * led3,led2,led 1
 * 000,001,010,011,100,101,110,111    
 * led1 is least significant bit
 *************************************/
int led1 =7;
int led2 =8;
int led3 =9;

int ledSpeed = 1000;

void setup() {
 pinMode(led1,OUTPUT);   //Set pins as output
 pinMode(led2,OUTPUT);
 pinMode(led3,OUTPUT);
}

void loop() {
   //000 all off
   digitalWrite(led1, LOW); 
   digitalWrite(led2, LOW); 
   digitalWrite(led3, LOW);
   delay(ledSpeed);
   
   //#1 001 led1 on, led2 off, led3 off
   digitalWrite(led1, HIGH); 
   digitalWrite(led2, LOW); 
   digitalWrite(led3, LOW);
   delay(ledSpeed);

   //#2 010 led1 off, led2 on, led3 off
   digitalWrite(led1, LOW); 
   digitalWrite(led2, HIGH); 
   digitalWrite(led3, LOW);
   delay(ledSpeed);

   //#3 011 led1 on, led2 on, led3 off
   digitalWrite(led1, HIGH); 
   digitalWrite(led2, HIGH); 
   digitalWrite(led3, LOW);
   delay(ledSpeed);

   //#4 100 led1 off, led2 off, led3 on
   digitalWrite(led1, LOW); 
   digitalWrite(led2, LOW); 
   digitalWrite(led3, HIGH);
   delay(ledSpeed);

   //#5 101 led1 on, led2 off, led3 on
   digitalWrite(led1, HIGH); 
   digitalWrite(led2, LOW); 
   digitalWrite(led3, HIGH);
   delay(ledSpeed);

   //#6 110 led1 off, led2 on, led3 on
   digitalWrite(led1, LOW); 
   digitalWrite(led2, HIGH); 
   digitalWrite(led3, HIGH);
   delay(ledSpeed);

   //#7 111 led1 on, led2 on, led3 on
   digitalWrite(led1, HIGH); 
   digitalWrite(led2, HIGH); 
   digitalWrite(led3, HIGH);
   delay(ledSpeed);  
}