Check yourself

Try to answer each question before you open its answer.

About the code

  1. In the sketch, what is reading?

    Show the answer

    A variable: a named place that holds the number analogRead gave. int reading = analogRead(A0); makes a whole-⁠number variable called reading and puts the reading in it. 10

  2. What does Serial.println(reading); do?

    Show the answer

    It sends the number to the computer as text, then starts a new line. println prints the value, then a carriage return and a newline. The serial link carries it to the computer. 7, 9

  3. What is the largest number analogRead() returns on an UNO R3?

    Show the answer

    1023. The UNO R3’s ADC is 10-⁠bit, so it gives 0 to 1023. In one college engineering course, the most common answer was 255. That is the top for analogWrite. 1, 4, 6

About the registers

These are about step 4. If you skipped it, you can skip them too.

  1. 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

  2. Why does the register version read ADCL before ADCH?

    Show the answer

    The datasheet says ADCL must be read first, then ADCH. Arduino’s own analogRead reads ADCL first too. 2, 3

Next is Lesson 3. You’ll make an LED dim and brighten as you turn the knob.

All sources for Lesson 2

  1. Arduino reference: analogRead
  2. Microchip ATmega328P datasheet DS40002061A: §24.7 ADC conversion result (p256); Table 24-3 (p257); ADEN and ADSC (p258)
  3. ArduinoCore-⁠avr, cores/arduino/wiring_analog.c
  4. Bedillion & Muci-Küchler, ASEE 2018: SDSM&T ME-265, 25 students
  5. Arduino example: AnalogReadSerial: potentiometer wiring
  6. Arduino reference: analogWrite: values 0 to 255
  7. Arduino tutorial: Analog Read Serial: what a potentiometer does; 0 V reads 0 and 5 V reads 1023
  8. Arduino reference: Serial.begin()
  9. Arduino reference: Serial.println()
  10. Arduino reference: int
  11. Arduino reference: delay
  12. Arduino: Using the Serial Monitor tool (Arduino IDE 2)