Welcome Future Engineers!
To a student friendly blogging community. To be a part of our growing community please join our mailing list. We will keep you informed about upcoming projects and useful information.
So you want to know how to build a binary counter using an Arduino microcontroller? In this tutorial you will learn how to count up and count down using two push buttons and eight leds. *You will also need resistors to prevent the leds from burning out (shame on me for not including them in the circuits)
I will not go over every detail but the code will be provided so that you can build your own counter. I will try my best to explain the working of this circuit...here goes.
In the setup the stateChangeDetection (int state, int = i , and int = 0) is telling the program the state will either be HIGH or LOW and then whether or not to start on HIGH or LOW. It then uses this declared state throughout the remainder of the program.
The attachInterrupt syntax is as follows attachInterrupt(pin, ISR, mode) ; please read more about it at the link provided.
The i++ will increment the counter i.e 0000 0000 becomes 0000 0001 when the up button is pressed and back to 0000 0000 if the down counter is pressed. The code loop basically converts the number of button pushes, stores it as a string, gets the length of the string and then outputs it to the leds. Please note that for convenience I choose the the red led for the LSB (least significant bit).
The setup of the breadboard is as follows:
I hope that you were able to follow these steps to successfully build or modify your own circuit. Please leave a comment for question, concerns, or thank you's.
Please Visit again soon. Check out more projects before you go!