Teach Remote lab lessons

Teach lesson

Visual programming with a real Arduino (3/4): inputs and decisions

Students use visual blocks to read an input, make a decision with a threshold, and verify LED behavior on a real Arduino board.

  • Arduino Board (visual)
  • 55 min
  • Secondary (ages 14–15)
  • English
  • Embedded systems

Sign in with an educator account to prepare a class session. Students join with a class code.

Visual block diagram: inside Arduino loop forever there is an if condition reading analog pin A0 greater than or equal to 500; in do, set built-in LED to HIGH; in else, set built-in LED to LOW; then wait 100 milliseconds.
Arduino Board (visual) · Lab details

Learning Outcomes

  • Read an input and confirm it changes before deciding an output.

  • Use an if / else condition with a comparison and a threshold.

  • Distinguish digital and analog input using a real example.

Student activity preview

Activity Content

Preview only. In a class session, students can fill in responses and submit their work to the teacher.

1

Input, threshold and decision

10 min

An input is information the board reads from the outside world. There are two types:

  • Digital input: only two states, like a button pressed / not pressed (or HIGH / LOW).
  • Analog input: many possible values. On an Arduino Uno board, an analog reading gives a number from 0 to 1023 (for example, the position of a potentiometer, which is a knob you turn).

A sensor is a component that produces one of those readings. A threshold is the cut-off value you use to turn an analog reading (many numbers) into a yes/no decision. Example: "if the reading is greater than or equal to 500, switch the LED on; otherwise, switch it off." 500 is the threshold.

Remember the editor structure: Arduino run first runs once at the beginning; Arduino loop forever repeats without stopping. The input reading and decision go in the loop forever so the board checks the value many times.

What does it mean to use a threshold of 500 on an analog reading that ranges from 0 to 1023?

Write one difference between a digital input and an analog input.

2

Read and check the input

16 min

Use a visible LED decision to check the input before filling the table.

  1. Open the Arduino visual board lab. Use the first on-screen potentiometer, connected to A0; leave the other inputs fixed.

  2. Build the LED decision before collecting data. Inside Arduino loop forever: if read analog pin# A0 >= 500, set the built-in LED HIGH; else set it LOW; then wait 100 ms.

  3. Optional serial: keep Setup serial 9600 bps in the workspace and add a print of read analog pin# A0 inside the loop. The LED route works without serial.

  4. Verify/compile, upload into the device, then program it when prompted. Move the first potentiometer through minimum, middle and maximum. Record the LED state and, if available, the serial value at each position.

  5. The ADC scale is 0–1023, but the remotely controlled potentiometer need not span it all. Use your observed endpoints; a 3.3 V input on a 5 V reference gives roughly 675 at its upper end. This is an estimate, not a required reading.

  6. If neither the reading nor LED changes, confirm A0, the first potentiometer and the uploaded program. Do not search random pins. If the observed range does not cross 500, change the threshold to lie within that range and retest.

Fill the table with one row for each input position you test. Use at least three rows: low, middle, and high; leave the extra rows empty. In each row, record the input position, the pin used, the reading or visible effect, and whether it changed when you moved the input.

Input position / state Pin used Reading or observed effect Changed when you moved the input?
3

Make a decision

22 min

Now add an if / else condition (Logic category) that uses your reading and a threshold to switch the built-in LED on or off.

  1. Keep the A0 LED program you already tested. Use the code and diagram below to check its structure. Choose a threshold that separates two observed potentiometer positions, upload the change and retest both positions. If serial is unavailable, record LED on/off and your tested threshold; numeric ADC readings are optional.

Your program should look roughly like this:

Visual block diagram: inside Arduino loop forever there is an if condition reading analog pin A0 greater than or equal to 500; in do, set built-in LED to HIGH; in else, set built-in LED to LOW; then wait 100 milliseconds.

Reference diagram for the decision. The A0 reading is compared with the threshold, and the LED changes according to the do or else branch.

Arduino loop forever:
   if  [read analog pin# [A0]]  [≥]  [500]
   do:
      [set built-in LED] [HIGH]
   else:
      [set built-in LED] [LOW]
   [wait] 100 milliseconds

Explain your full condition: what input you read, what threshold (or state) you compare it with, and what output changes.

Describe two tests: one where the LED switches on and one where it switches off. Include the input position/state and, if you calibrated it, the final threshold.

4

If it does not change, debug

7 min

If the LED does not change when you move the input, write three ordered checks you would do before asking for help (think about: read pin, threshold value, and whether you uploaded the program).

Turn this preview into a live class session

Continue to LabsLand Teach to use this lesson with your students and review the access available to your account.