First to go through the questions from the assignment:
Question 1: Currently you have the negative terminal of one battery connected to the negative rail,
and the positive terminal of the other battery connected to the positive rail. Is this a complete
circuit?
No, nothing is connecting the positive and negative rails so this is not a complete circuit.
Question 2: Why have we configured the battery in series and not in parallel?
When you put the batteries in parallel they only give 1.5V, and we need 3V to make our LEDs work, so we put them in series, causing their voltage to add together to give a total of 3V.
Question 3: You should have a complete circuit now! Congratulations. But, wait... does your LED
look like it just exploded? Why did this happen?
The two AA Batteries provide way more power than the LED wants and putting this much power through the LED will fry it pretty quickly. In fact, if you want to see what this looks like for real my suite-mate (turns out EEs are really helpful when you're making circuits) intentionally fried an LED, which you can take a look at on his blog jerryjzy.blogspot.com.
After getting through the simple "Blinking Red Light" assignment I decided to take one of the suggested challenges and make a row of 4 LEDs that would display a binary number. My first design was as simple as I could make it, 4 different output pins mapped to 4 different LEDs. My code was a little more complicated, every second the Arduino incremented a counter and then passed that counter into a function called 'light(int num)' that handled lighting up the LEDs. This function worked on the bits of the number passed in. It checked if the smallest bit was set, and if that bit was set it turned on the first LED. It then did a bitwise shift right on the number and checked the new smallest bit, and set the second LED based on that. It repeated this process until it had set all four LEDs. The code for the light() function is below.
void light(int num) {
int led = 4; // Counter to keep track of which LED we're setting
for(int i = 0; i < 4; i++) {
if(num%2 == 0) { // If the number is divisibile by 2 the smallest bit isn't set, so turn the LED off
digitalWrite(led, LOW);
} else { // Else the smallest bit is set, so turn the LED on
digitalWrite(led, HIGH);
}
led++; // Increment the LED counter
num = num >> 1; // Bitwise shift to the right
}
}
With that done I then decided to add a button so that instead of incrementing on a timer the counter would increment whenever the button was pressed. Surprisingly, the push button in the simulator doesn't work as a normal push button but instead changes states from on to off whenever the button is pushed, so that after the first press the button completes the circuit and continues to do so until the button is pressed again. To handle this I had my code remember the state of the button and recheck the state of the button every 1/10 of a second. I chose 1/10 of a second because I don't care if the user presses the button too fast, the Arduino simply won't register those presses. On every check it compares the saved state of the button to the new state and if there is a difference it increments the counter, calls light() and then changes the saved state of the button.
On the right of the breadboard are two projects I did to test the switch and the button, in both circuits toggling the switch/button will change the light from on to off or vice-versa. On the left is the binary counter itself, the switch in the middle of the breadboard will increment the lights. After building this circuit in the similar I decided to take it one step further and (once again taking advantage of my EE suite-mate) built this circuit in actual hardware.
![]() |
| Its Alive! |
Since the push-button I had worked like a sane button, being on when depressed and off when released, I had to update my code a little bit so that it only increments the counter on change from on-state to off-state instead of on both - my first test had the lights incrementing by 2 for every button press. Here's a quick video of the finished product. At some point I press the button too quickly and the arduino doesn't catch it in its loop, but as I said above I don't really care if it misses a button press.




