Badger Invitational

Hamilton Middle School

These questions were written for the Badger Invitational competition, held 2019-02-23. Now that the competition is over, this page will remain as a link to the official answer circuits.

You can also download the test, answer sheet, and key as PDFs:
answer sheet

Feel free to contact me with any questions or comments.
- Blaise Thompson (bthompson@chem.wisc.edu)

Written Test

Question 1.1 - servo

Using Tinkercad, open the "servo" circuit. You may choose to use text or blocks to program the Arduino.

Given Tinkercad circuits:

Question 1.1.1 (10 Points)

Your Arduino has been pre-programmed to remind you how to use the Servo library. As written, the code will simply move the motor from 0 to 180 degrees and then start over. Roughly how long will the motor take to accomplish one rotation? Modify the code so that the pattern repeats at 0.5 Hz.

As written, the motor will take 18 seconds to accomplish one rotation. To repeat the pattern at 0.5 Hz, change the delay from 100 ms to (5000/180)=28 ms. For a super-accurate repeat frequency, use millis() instead.

Question 1.1.2 (5 points)

The middle pin of the potentiometer is wired to pin 8 of the Arduino. Is this appropriate? If not, choose an appropriate pin and explain your reasoning.

Pin 8 is not appropriate. As the potentiometer is rotated, the middle pin will sweep from zero to five volts. An analog input pin is required to measure the analog output of the potentiometer. Pin 8 cannot be used as an analog input. Pins A0 though A5 are all appropriate choices.

Question 1.1.3 (10 points)

Modify your code such that the potentiometer can be used to control the position of the servo motor. Ensure that the dynamic range of the potentiometer (0 to 5 V) agrees with the dynamic range of the servo motor (0 to 180 degrees). Recall that the Arduino has a 10 bit analog-to-digital converter.

With the reminder that the Arduino Uno has a 10 bit analog-to-digital converter, we can calculate that the analogRead() function will return an integer between 0 and ((2^10)-1)=1023. An input of zero volts will give us integer 0, and an input of 5 volts will give integer 1023. The conversion factor, therefore, is (180/1024)=0.176.

Modified Tinkercad circuits:

For students using Tinkercad blocks, the map function can also be used to answer this question.

Question 1.2 - stopwatch

Your friend has designed a simple stopwatch using an Arduino, button, and LCD display. How clever of her! The circuit works perfectly, but the code is behaving strangely. She needs your help to debug the project. Open the stopwatch circuit in Tinkercad. You may choose to use text or blocks to program the Arduino.

(Note that the LCD display is not supported by Tinkercad blocks---in this case, we use Serial print as an alternative.)

Given Tinkercad circuits:

Question 1.2.1 (10 points)

The stopwatch starts correctly when the button is pressed for the first time. Subsequent button presses reset the stopwatch. This is not intended behavior! Your friend wants her stopwatch to pause when the button is pressed a second time.

Briefly, explain to her why your friends' code doesn't work as intended. Be sure to describe the relationship between button presses and the "running" variable.

Almost everything is correct in the given circuit. The only problem is that, after the first button press, the "running" variable is never set back to false (zero). As written, running is set to true (one) every time the button is pressed. Since running never goes false (zero), the number keeps being updated no-matter-what. Your friend should toggle the running variable, rather than just setting it to true (one) inside the if statement.

Question 1.2.2 (10 points)

Fix your friends' code. Describe what you changed, and why that change fixes the problem.

Modified Tinkercad circuits:

I changed the line setting the "running" variable. Instead of setting to true (one) each time, I set to (not running). This toggles the running variable with each button press.

Question 1.2.3 (5 points)

Why did your friend add a while loop?

The inner while loop ensures that the button is released before letting the Arduino continue. Without the while loop, the code would continue and eventually loop around to the (if button pressed) statement multiple times. This might lead to unexpected behavior where a single button press event results in the running variable being updated several times.

Question 1.3 - blink2

Using Tinkercad, open the "bink2" circuit. You may choose to use text or blocks to program the Arduino.

Given Tinkercad circuits:

Question 1.3.1 (5 points)

Blink both LEDs, such that the green LED is on when the orange LED is off and vice versa.

Simply change the HIGH to LOW and vice versa for one of the output pins.

Question 1.3.2 (20 points)

Change the frequency of the green LED such that it is blinking three times slower than the orange LED. Keep the duty cycle of both LEDs at 50%.

Modfied Tinkercad circuits:

Note that there are many possible solutions to this question. In my opinion, the given solutions are the most elegant and flexible strategy.

Question 1.4 - switch

Using Tinkercad, open the "switch" circuit. You may choose to use text or blocks to program the Arduino.

Given Tinkercad circuits:

Question 1.4.1 (10 points)

Consider the following definitions:

A toggle switch changes the state every time it is depressed. Once released, the new state (on or off) is maintained until the switch is pressed again. Example: common light-switch.

A momentary switch is on only while being pressed. Once released, the switch automatically turns off again. Example: computer keyboard key.

Is the button acting as a momentary switch or a toggle switch? Is this relationship defined by the circuit, or by the Arduino code. Explain how you know.

The button acts as a momentary switch.

The relationship is defined by both the code and the physical construction of the button. Any answer that demonstrates clear understanding of that relationship is acceptable.

Question 1.4.2 (10 points)

Without changing the circuit, modify your Arduino code so that the button acts like a toggle switch. Describe your approach.

Modified Tinkercad circuits:

Rather than just using the state of the button directly, I added a variable to keep track of internal state in the Arduino's memory. The button now toggles my variable. The LED state is updated according to the variable state.

Question 1.4.3 (5 points)

How could you change the brightness of the LED?

Change the brightness by changing the resistor. More resistance for a dimmer LED. Less resistance for brighter LED. You could also conceivably use pulse width modulation.


You will have 25 minutes to complete this portion of the exam. Complete as many of the following exercises as you can. There are 100 points possible. Some of these questions use Tinkercad, and others require the usage of real hardware. If you prefer to program using blocks, you must export your Tinkercad code and upload it using the Arduino IDE. If you have never worked with real Arduinos, we will help you get started.

Question 2.1 - traffic light (10 points)

Using the provided components, made an LED traffic light. Place three LEDs: green, yellow and red. Make them blink in a specific pattern: 1) long green, 2) short yellow, 3) long red, then repeat.


Question 2.2 - rainbow (10 points)

Using Tinkercad, make an RGB LED cycle through the rainbow (Red, Orange, Yellow, Green, Blue, Indigo, Violet) and back again.

using analogWrite
using builtin RGB LED block

Question 2.3 - dancing motor (10 points)

Using Tinkercad, turn on a motor for one second, then off for one second, then on for two seconds, the off for two seconds, then on for three seconds, and so on repeating the process to 100 seconds.


Question 2.4 - click counter (20 points)

Using Tinkercad, make a click counter. Using an LCD screen as a display, create a circuit that shows how many times a button is depressed. The circuit should count each click separately, even when the button is held down for a prolonged period.

using blocks/serial
using text/LCD

Question 2.5 - binary counter (20 points)

Using the provided components, make a three-bit binary counter. Use three LEDs. Count from zero to seven, then repeat. Spend roughly one second on each number.

using blocks
using text

Question 2.6 - 7-segment (30 points)

You will be given an Arduino with a pre-wired seven segment display. Each segment is wired to a separate pin (see documentation). Program the Arduino to count from zero to nine, spending around one second on each number.


using blocks
using text