• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Tuan Huang

  • Spring 2022
  • Fall 2021
  • About

PComp Lab W2 – Digital Input / Output

1. Digital Input and Output

starting week 2 lab by controlling digital input and output from a pushbutton. (figure 1.01, 1.02)

Question

  • Why need a voltage divider? (or is it only a potentiometer that does not need it?)
a breadboard with a LED circuit
1.01 – when pressing the pushbutton, the left LED lights
a breadboard with a LED circuit
1.02 – when not pressing the pushbutton, the right LED lights

 

 

 

 

 

 

2. Analog In with an Arduino

Adding a potentiometer to the breadboard, the input was read from an Analog pin, which was  what made it adjustable (not all-or-nothing like a digital pin) (figure 2.01, 2.02)

Then in the second circuit, 2 LED lights are controlled by 2 photocells. The input of the photocell determined the brightness of LED. (figure 2.03, 2.04)
However, 2 photocells (with same kind of fixed resistor) had 2 different ranges, so I had to map them separately. (figure 2.05)

Notes

  • analogRead (pin) – value goes from 0 to 1023
    ➔ which means the resolution of Arduino’s reading is 1024 
  • analogWrite (pin, value) – value goes from 0 to 255
  • In the case of the potentiometer, who can give a full range from 0 to 1023, the read value should be divided by 4 in order to fit into the range of analogWrite
  • When using other senses with a fixed resistor (voltage divider), it limits the range  and so the number divided should also be adjusted accordingly. To do so:
    ➔ 1. find the range – use Serial.print();
    ➔ 2. map the new range – let value = map (sensorValue, rangeMin, rangeMax, 0,255);

Question

  • What does Serial.begin(9600) mean exactly, and when do we need to type this?
a breadboard with a LED circuit and a potentiometer
2.01 – one end of potentiometer – dimmer light
a breadboard with a LED circuit and a potentiometer
2.02 – the other end of potentiometer – stronger light

 

 

 

 

 

 

a breadboard with a LED circuit and 2 photocells
2.03 – 2 photocells controlling 2 LED lights
2.04 – when covering photocells, LED lights were dimmer
a screenshot of Arduino code
2.05 – the 2 photocells had different ranges

 

3. Sensor Change Detection

In this lab, we learned how to note the peak of input data, and printed them in the Serial Monitor. I used a pushbutton for digital input and a photocell for analog input. 

In the digital one, we practiced 2 states of the peak – one when the threshold is crossed, and one categorizing the length of pressing time. (figure 3.01, 3.02)

a screenshot of Arduino code
3.01 – notes when threshold is crossed
a screenshot of Arduino code
3.02 categorizing pressed time

 

 

 

 

 

and in the analog one, I used a photocell, recording peaks of the values. (figure 3.03, 3.04)

a breadboard with a LED circuit and 2 photocells
3.03 photocell circuit
3.04 recording peaks of values

 

 

 

 

 

 

Question

  • I don’t quite understand the logic of the code in figure 3.04. When I hid the line ” if (sensorValue <= threshold) { ” the whole program still worked. I felt that the line was a bit redundant and lost my thread of the logic here.

 

Primary Sidebar

Footer

Recent

  • #final project: E-Forms
  • #5 Form Generator + Auto-fill by computers
  • #4 Revisiting Digital Cut-up
  • 03: Form Generator
  • 04: Tunnel Cube

Tuan © 2025