
What you’ll make
In this lesson, a knob sets how bright a light is1. The light is an LED on pin 9.
The knob is the one from Lesson 2. The board reads it as a number from 0 to 10236. Your code turns that number into a brightness.
See it first
Press Run to start the code on the on-screen board. Then move the knob and watch the LED get brighter or dimmer.
What you need
For the on-screen board, you need nothing. It runs in this page. For a real board, you need these:
- Arduino UNO R3
- USB cable
- An LED and a resistor
- The knob from Lesson 2
- Jumper wires
Next, you’ll read the code one line at a time.
Sources for this page
- Arduino reference: analogWrite
- Arduino reference: analogRead: values 0 to 1023 on the UNO R3