Physical Computing Review Quiz 2: Digital In & Out

Explain the difference between an analog sensor and a digital sensor. Give examples of both.

Analog sensor reads a variable change. For example,  accelerometers, pressure sensors, light sensors, sound sensors, temperature sensors, and so on.

Digital sensors could only read 2 states: on and off, and it uses binary value to communicate. For example, digital accelerometers, digital temperature sensor.


Draw a circuit for connecting a pushbutton as a digital input to a microcontroller. Connect it so that the digital input pin gets HIGH when the button is pushed. What does the resistor (called a pulldown resistor) do?

The resistor connecting the switch is a pulldown resistor.The resistor connects the digital input to ground, so that it reads as zero voltage, or LOW.

Write a program that reads a digital input to an Arduino and turns off an LED whenever the digital input goes LOW. Draw the schematic that goes with this program as well.

void setup() {
  pinMode(2, INPUT);    // set the switch pin to be an input
  pinMode(3, OUTPUT);   // set the green LED pin to be an output
  pinMode(4, OUTPUT);   // set the red LED pin to be an output
void loop() {
   // read the switch input:
   if (digitalRead(2) == HIGH) {
     // if the switch is closed:
     digitalWrite(3, HIGH);    // turn on the green LED
     digitalWrite(4, LOW);     // turn off the red LED
   else {
     // if the switch is open:
     digitalWrite(3, LOW);     // turn off the green LED
     digitalWrite(4, HIGH);    // turn on the red LED

Write a program that reads a digital input and prints out a message when the input changes from HIGH to LOW.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top