Input Devices

Back to Home

Goals

group assignment

Individual Assignment

Group Assignment

Introduction to Analog and Digital Signals

What are Analog and Digital Signals?

In electronic systems, input devices generate two types of signals: Digital Signals and Analog Signals. Understanding their differences is fundamental for electronic design and programming.

What is a Digital Signal?

A digital signal is a discrete signal that has only two states:

It functions like a switch: only on or off.

Characteristics:

Example: A push button outputs 0 when pressed, 1 when released.

What is an Analog Signal?

An analog signal is a continuous voltage signal that represents a range of values such as brightness, temperature, or position.

Its voltage can vary smoothly between 0V and 3.3V (or 5V), allowing more detailed input.

Characteristics:

Example: A potentiometer outputs varying voltage depending on rotation.

Comparison Table

FeatureDigital SignalAnalog Signal
TypeDiscrete (0 or 1)Continuous
InformationSimple on/offDetailed variation
Noise ResistanceHighLow
Reading FunctiondigitalRead()analogRead()
Example DevicesButton, IR switchPotentiometer, LDR

Why is this important?

In real-world projects, both analog and digital inputs are used together. For example, you might use a button (digital) to start a process and a potentiometer (analog) to adjust intensity. Knowing how to handle both types correctly is essential in interactive electronics and embedded systems.


Objective

The goal of this group task was to understand and probe analog signals using a simple input device. We chose a potentiometer (rotary knob sensor) to demonstrate how analog signals behave and how they can be read using the XIAO ESP32S3 development board.

Introduction to the Potentiometer

The potentiometer is a three-pin variable resistor. It acts as a voltage divider by providing a continuously variable voltage at its middle pin depending on the knob's rotation.

Wiring

Potentiometer PinFunctionESP32S6 Connection
LeftGNDGND
MiddleAnalog OutputA0
Right3.3V Power3.3V

Note: The outer pins can be reversed; the result will only change the direction of increase/decrease.

Arduino Code

void setup() {
                Serial.begin(115200);
                }

                void loop() {
                int rawValue = analogRead(A0);
                float voltage = rawValue * (3.3 / 4095.0);
                Serial.print("Analog Value: ");
                Serial.print(rawValue);
                Serial.print("    Voltage: ");
                Serial.println(voltage, 2);
                delay(200);
                }

Experiment Steps

  1. Connect the potentiometer to the ESP32S3 as shown above.
  2. Upload the Arduino sketch to the board.
  3. Open the Serial Plotter in Arduino IDE.
  4. Slowly turn the knob and observe the output values and curves.

Observations

Knob PositionAnalog ValueVoltage
Far Left00.00 V
Center~2048~1.65 V
Far Right~4095~3.30 V

The Serial Plotter shows a smooth, continuous curve. The analog value increases linearly with the knob rotation.

Group Discussion and Conclusion

FeatureDescription
Signal TypeAnalog (continuous)
OutputVoltage from 0V to 3.3V
Reading MethodanalogRead()
ResponseLinear and smooth
AdvantagesSimple, intuitive, perfect for analog input demo

This experiment helped us clearly understand what an analog signal is and how a microcontroller like the XIAO ESP32S3 can read it. The potentiometer is an excellent demonstration tool for analog input behavior.

Button as Digital Input

A push button is a basic digital input device. It outputs only two states:

Wiring

Arduino Code

This code outputs both numeric and descriptive data so it's compatible with Serial Plotter and Serial Monitor.

const int buttonPin = D1;  
              
              void setup() {
                pinMode(buttonPin, INPUT_PULLUP);
                Serial.begin(115200);
              }
              
              void loop() {
                int state = digitalRead(buttonPin);
              
                // Numeric output for Serial Plotter
                Serial.print(state);
                Serial.print("  -->  ");
              
                // Text output for Serial Monitor
                if (state == LOW) {
                  Serial.println("Pressed");
                } else {
                  Serial.println("Released");
                }
              
                delay(200);
              }

Observations

Conclusion

The button provides a clear example of a digital input: two distinct states, perfect for detecting on/off events. The combined use of numeric and textual output allows for debugging in Serial Monitor and visualization in Serial Plotter, making this a flexible setup for input testing.

Individual Assignment

Assignment Requirement: "Measure something: add a sensor to a microcontroller board that you have designed and read its data."

Project Objective

This week, the input device I chose is the DHT11 temperature and humidity sensor. It is a digital sensor based on single-wire communication, capable of outputting both environmental temperature (Celsius) and relative humidity (%RH). I have integrated it into the microcontroller development board I am using, the Seeed Studio XIAO ESP32S3, and written a program in the Arduino IDE to read, output, and visualize the data.

This project helped me achieve the following goals:


What is an Input Device?

An input device is a component or module that converts information from the external physical world into electronic signals, playing the role of "perception" in an electronic system. It can be a button, thermometer, light-dependent resistor, potentiometer, etc.

DHT11 Overview:

The DHT11 is a common digital temperature and humidity sensor. It is encased in a blue plastic shell and contains:

Its communication uses a dedicated single-wire protocol, with the microcontroller board communicating with the sensor via a data pin.

Hardware Components and Electrical Connections

Main Controller Board: Seeed Studio XIAO ESP32S3

Sensor: DHT11 (Module Version)

Pin Name Function Connected to XIAO ESP32S3 Pin
VCC Power Input 3.3V
GND Ground GND
DATA Signal Output GPIO3 (D2 on board)

Software Environment and Development Process

Arduino IDE Configuration Steps:

  1. Install Board Support Package: XIAO ESP32S3
  2. Open the IDE → Select Board → Type xiao → Choose xiaoesp32s3

Install Required Libraries:

  1. Open ToolsLibrary Manager
  2. Search and install: DHT sensor library by Adafruit (and its dependency: Adafruit Unified Sensor)

Final Setup:

Sample Code (Arduino IDE - DHT11 Sensor Reading)

#include "DHT.h"  // Include the DHT library

        #define DHTPIN 3        // Signal pin connected to GPIO3 (D2)
        #define DHTTYPE DHT11   // Specify sensor type: DHT11

        DHT dht(DHTPIN, DHTTYPE); // Create a DHT11 sensor object

        void setup() {
        Serial.begin(115200);   // Initialize serial communication
        dht.begin();            // Initialize the sensor
        }

        void loop() {
        float humidity = dht.readHumidity();        // Read humidity (%RH)
        float temperature = dht.readTemperature();  // Read temperature (°C)

        // Error handling: check if reading failed
        if (isnan(humidity) || isnan(temperature)) {
            Serial.println("❌ Failed to read from sensor. Please check wiring or sensor status.");
            delay(2000);
            return;
        }

        // Output for Serial Plotter (to draw graphs)
        Serial.print(humidity);
        Serial.print(",");
        Serial.println(temperature);

        // Output for Serial Monitor (human-readable)
        Serial.print("✅ Humidity: ");
        Serial.print(humidity);
        Serial.print("%  Temperature: ");
        Serial.print(temperature);
        Serial.println(" °C");

        delay(2000);  // Recommended reading interval ≥ 2 seconds
        }
        

Experiment Process and Data Observation

After uploading the program, I opened the Serial Monitor and Serial Plotter to perform the following test:

✅ Normal Reading:

✅ Humidity: 58.00%  Temperature: 26.60 °C
        

Experimental Intervention:


Error Handling Strategies

Issue Possible Cause Solution
Read failure / Output shows nan Incorrect pin setting, damaged module, or interval too short Check GPIO configuration; increase delay to more than 2 seconds
Garbled output / No data displayed Serial baud rate mismatch Ensure Serial.begin() matches the serial monitor settings
Data not updating Sensor not responding or stable air conditions Trigger sensor by exhaling or applying heat

Conclusion and Reflection

Through this experiment, I successfully completed the individual assignment for the Fab Academy's "Input Devices" module. This task not only involved physically connecting a real sensor (DHT11), but also gave me a clearer understanding of the entire process from "sensor → data reading → information display."

Specifically, I:

Although this sensor is relatively basic, through hands-on practice I developed a more intuitive grasp of how input devices work and what role they play in a system.