This week's lab focused on digital and analog inputs/outputs, as well as sensor devices.

Lab 1: digital input and output

In this lab, I connect a digital input circuit and a digital output circuit to a microcontroller.

When pushbutton is not pressed, the red LED is programmed to be on. When the pushbutton is pressed, the yellow LED turns on.

When pushbutton is not pressed, the red LED is programmed to be on. When the pushbutton is pressed, the yellow LED turns on.

Wiring setup for the first project of Lab 1. Red LED is turned on .

Wiring setup for the first project of Lab 1. Red LED is turned on .

When I first went to record the video, I learned that the while the red light stayed on, the yellow light wasn't switching on when the button was pressed. I figured that the likeliest reason was a mechanical problem, otherwise the Arduino's on light and red light would not be turned on. In fact, when I replaced the pushbutton the whole system worked well.

Here is the code with which the Arduino was programmed:

void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT);    // set the pushbutton pin to be an input
  pinMode(3, OUTPUT);   // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);   // set the red LED pin to be an output
}

void loop() {
  // put your main code here, to run repeatedly:
   // read the pushbutton input:
   if (digitalRead(2) == HIGH) {
     // if the pushbutton is closed:
     digitalWrite(3, HIGH);    // turn on the yellow LED
     digitalWrite(4, LOW);     // turn off the red LED
   }
   else {
     // if the switch is open:
     digitalWrite(3, LOW);     // turn off the yellow LED
     digitalWrite(4, HIGH);    // turn on the red LED
   }
 }

Lab 2: analog input

In this lab, I connect a variable resistor to a microcontroller and read it is an analog input.

The red LED glows brighter as the knob is turned counter-clockwise.

The red LED glows brighter as the knob is turned counter-clockwise.

The red LED at its brightest setting.

The red LED at its brightest setting.

Here is the code with which the Arduino was programmed: