Check yourself
Try to answer each question before you open its answer.
About the code
In the sketch, what is
reading?Show the answer
A variable: a named place that holds the number
analogReadgave.int reading = analogRead(A0);makes a whole-number variable calledreadingand puts the reading in it. 10What does
Serial.println(reading);do?What is the largest number
analogRead()returns on an UNO R3?
About the registers
These are about step 4. If you skipped it, you can skip them too.
With the knob at 2.5 V, what does the sketch print?
Show the answer
512. ADC = VIN × 1024 / VREF = 2.5 × 1024 / 5. 2
Why does the register version read ADCL before ADCH?
Next is Lesson 3. You’ll make an LED dim and brighten as you turn the knob.
All sources for Lesson 2
- Arduino reference: analogRead
- Microchip ATmega328P datasheet DS40002061A: §24.7 ADC conversion result (p256); Table 24-3 (p257); ADEN and ADSC (p258)
- ArduinoCore-avr, cores/arduino/wiring_analog.c
- Bedillion & Muci-Küchler, ASEE 2018: SDSM&T ME-265, 25 students
- Arduino example: AnalogReadSerial: potentiometer wiring
- Arduino reference: analogWrite: values 0 to 255
- Arduino tutorial: Analog Read Serial: what a potentiometer does; 0 V reads 0 and 5 V reads 1023
- Arduino reference: Serial.begin()
- Arduino reference: Serial.println()
- Arduino reference: int
- Arduino reference: delay
- Arduino: Using the Serial Monitor tool (Arduino IDE 2)