Module 6 · Practice
Practice questions
Three difficulty levels.
Section A — Easy
Name the two main functions in every Arduino sketch and say when each runs.
Match the function to its purpose:
pinMode
(b) digitalWrite
(c) digitalRead
(d) delay
What range of values does analogRead return on a standard Arduino Uno?
What does PWM stand for and what is it used for?
Section B — Medium
Write a sketch that flashes an LED on pin 9 every half a second.
Why do you usually add a small delay after detecting a button press in a latch program?
Write the code to read the value from a sensor on A0 and print it to the Serial Monitor every second.
Why can't you connect a small motor directly to a digital output pin? What would you use instead?
Section C — Hard
Write a sketch that turns an LED on pin 13 on when the LDR reading on A0 is below 300, and off otherwise.
Write a subroutine called flash(pin, times, ms) that flashes any pin a given number of times with a chosen delay. Show how you'd call it to flash pin 9 four times with 200ms gaps.
Design a "smart desk lamp": an LED's brightness should follow a potentiometer. Describe the wiring (in words) and write the loop().