valnaut
Published © GPL3+

Building a LED Binary Counter

Morse Not enough, well Lets use Binary

BeginnerProtip2,513
Building a LED Binary Counter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Resistor 330 ohm
Resistor 330 ohm
×4
LED, Blue
LED, Blue
×4
9V battery (generic)
9V battery (generic)
×1
9V to Barrel Jack Connector
9V to Barrel Jack Connector
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

LedBinaryCounter

I recommended you to use a 330 ohms resistor instead of the 220 ohms one in circuit diagram.

LedBinaryCounter

I recommend you yo use a 330 ohms resistor instead of the 220 ohms one in circuit diagram.

Code

LedBinaryCounter

Arduino
int pin2 = 2; // Setting the value of variable pin2 as 2
int pin3 = 3; // Setting the value of variable pin3 as 3
int pin4 = 4; // Setting the value of variable pin4 as 4
int pin5 = 5; // Setting the value of variable pin5 as 5

void setup() {
  // put your setup code here, to run once:
pinMode (pin2,OUTPUT); //Defining pin2 as OUTPUT
pinMode (pin3,OUTPUT); //Defining pin3 as OUTPUT
pinMode (pin4,OUTPUT); //Defining pin4 as OUTPUT
pinMode (pin5,OUTPUT); //Defining pin5 as OUTPUT
}

void loop() {
  // put your main code here, to run repeatedly:
// 0000 = 0
// 0001 (1)
digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,HIGH);

delay (1000); // giving a gap of 1000 miilliseconds, 1 second =  1000 milliseconds

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);


// 0010 (2)
digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 0011 (3)
digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 0100 (4)
digitalWrite (pin2,LOW);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 0101 (5)
digitalWrite (pin2,LOW);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,LOW);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 0110 (6)
digitalWrite (pin2,LOW);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 0111 (7)
digitalWrite (pin2,LOW);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1000 (8)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1001 (9)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1010 (10)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,LOW);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1011 (11)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,LOW);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);


// 1100 (12)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1101 (13)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,LOW);
digitalWrite (pin5,HIGH);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1110 (14)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,LOW);

delay (1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (1000);

// 1111 (15)
digitalWrite (pin2,HIGH);
digitalWrite (pin3,HIGH);
digitalWrite (pin4,HIGH);
digitalWrite (pin5,HIGH);

delay(1000);

digitalWrite (pin2,LOW);
digitalWrite (pin3,LOW);
digitalWrite (pin4,LOW);
digitalWrite (pin5,LOW);

delay (2000);
}

Credits

valnaut

valnaut

2 projects • 1 follower

Comments