Arduino LED Binary Counter

Erika Noma
4 min readNov 10, 2021

--

For this week’s Creative Coding homework, I followed Paul McWhorter’s tutorial 5 and tutorial 6 and made a LED binary counter to work with Arduino. I first tried to think of ways I could do this week’s homework with aluminum foil and a chair to make a LED light on Arduino to light up when you slouch in the chair to warn you when you have a poor posture. However, I did not understand the logistics behind how Arduino works and why it does what it does even after I got the button to work during the last week’s class so I decided to follow a tutorial to understand more about what Arduino is.

I first solved what the binary counter would look like by drawing the sketch, which made the coding part much easier. (Filled circles mean that the light should be on.)

Then, I created a circuit on the board. I thought I would need four grounds for four LED lights to turn on, but I learned that if I connect one wire from the ground to the negative hole, a whole negative column becomes ground. Also while I was making this circuit, I was able to digest and understand the basics of how circuits work. In my understanding, I need one pin connected next to the Arduino Nano board to supply power, and that wire needs to be placed on the same row as one leg of the resistor, and the other leg of the resistor needs to be connected on the same row as the long leg of the LED light, because long leg means +, which needs to be on the supplier’s side and the short leg (-) needs to be on the ground side. In order to connect the short leg to the ground, I need one more wire on the same row as the short leg and connect it to the ground, which in this case, the whole negative column becomes a ground so any hole on the negative column.

Then, I started coding. I first made sure that all elements are placed in the correct way by defining pin places with variables (pin1=11), put pinMode(pin1,OUTPUT) in the setup, and put digitalWrite(pin1,HIGH) in the loop to make sure all LED lights turn on. One problem I still cannot figure out the solution to is all the lights turn on but the middle two lights are not as bright as the first and the last lights. I changed the LEDs but it seems like lower power is supplied to the two LEDs in the middle while the first and the last LED have higher power.

Lastly, I coded the binary count sketch I drew on paper by setting each digitalWrite pin1 to 4 on either low or high, and added a delay to each so the pattern is recognizable. I coded that for 15 times, uploaded it, and the binary count works!

Here is the video that shows 15 different patterns.

Although I could not figure out a more creative way to use what I learned from this homework, I was able to understand and digest how the LED circuit works in Arduino. In last week’s homework, I didn’t code at all and connected the breadboard to the power outlet and aluminum foil to make a LED turn on. But this week, I was able to learn why and how adding code works in Arduino. I’m an absolute beginner in the hardware world and I’m still trying to understand the basics of Arduino and its’ potential. It takes a lot of time for me to understand and digest how it works, but I am excited to learn new things every week and see how I can use Arduino for bigger projects.

Code:

int pin1=11;
int pin2=9;
int pin3=7;
int pin4=5;
int waitTime=1000;
void setup() {
// put your setup code here, to run once:
pinMode (pin1, OUTPUT);
pinMode (pin2, OUTPUT);
pinMode (pin3, OUTPUT);
pinMode (pin4, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
delay(waitTime);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,HIGH);
delay(waitTime);
}

--

--