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?)
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?
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)
and in the analog one, I used a photocell, recording peaks of the values. (figure 3.03, 3.04)
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.