You can also download the test, answer sheet, and key as PDFs:
test
answer sheet
key
Feel free to contact me with any questions or comments.
- Blaise Thompson (bthompson@chem.wisc.edu)
Given Tinkercad circuits:
servo-text
servo-blocks
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.
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.
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:
servo-text-key
servo-blocks-key
For students using Tinkercad blocks, the map function can also be used to answer this question.
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:
stopwatch-text
stopwatch-blocks
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.
Fix your friends' code. Describe what you changed, and why that change fixes the problem.
Modified Tinkercad circuits:
stopwatch-text-key
stopwatch-blocks-key
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.
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.
Given Tinkercad circuits:
blink2-text
blink2-blocks
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.
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:
blink2-text-key
blink2-blocks-key
Note that there are many possible solutions to this question. In my opinion, the given solutions are the most elegant and flexible strategy.
Given Tinkercad circuits:
switch-text
switch-blocks
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.
Without changing the circuit, modify your Arduino code so that the button acts like a toggle switch. Describe your approach.
Modified Tinkercad circuits:
switch-text-key
switch-blocks-key
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.
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.
Solutions:
using analogWrite
using builtin RGB LED block
Solutions:
using blocks/serial
using text/LCD
Solutions:
using blocks
using text
Solutions:
using blocks
using text