Week 09: Input Devices
Assignment:
- Group: probe an input device's analog levels and digital signals.
- Individual: measure something: add a sensor to a microcontroller board that you have designed and read it.
Measuring distance with a VL53L0X time-of-flight sensor

The VL53L0X is a time-of-flight distance sensor: it fires an infrared laser pulse and measures how long the light takes to bounce back. It communicates over I²C, so it only needs four wires: VIN, GND, SCL and SDA.

Code
I used the Adafruit VL53L0X library. The sketch starts the sensor over I²C, then prints the distance in millimetres every 200 ms, or "Out of range" when there is no valid reading.

#include <Wire.h>
#include <Adafruit_VL53L0X.h>
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA, SCL
Serial.println("VL53L0X Test");
if (!lox.begin()) {
Serial.println("Failed to find VL53L0X sensor");
while (1);
}
Serial.println("Sensor initialized!");
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false); // pass true to debug
if (measure.RangeStatus != 4) { // valid reading
Serial.print("Distance (mm): ");
Serial.println(measure.RangeMilliMeter);
} else {
Serial.println("Out of range");
}
delay(200);
}
Result

The serial monitor shows live readings of roughly 1,190–1,280 mm, with occasional "Out of range" results when nothing valid is in front of the sensor.
Exploring the input devices in the lab
A push button is a momentary input device that only completes the circuit when pressed. It has internal metal contacts that touch when force is applied and disconnect when released. This produces a digital signal (HIGH/LOW) for microcontrollers. It is commonly used for triggering events like turning LEDs on/off or resetting systems. Debouncing is often required because mechanical contacts can create noise. It is one of the simplest and most reliable human input interfaces.
A toggle switch is a latching mechanical switch that stays in its position after being flipped.
Unlike push buttons, it does not require continuous force to maintain state. It is typically used for ON/OFF control of circuits. Internally, it connects or disconnects terminals based on lever position.
It outputs a stable digital HIGH or LOW signal.
Used in power control, mode selection, and hardware toggling.
A slide switch changes state by sliding a small actuator horizontally.
It is a latching switch, meaning it stays in position until moved again. It typically has 2 or 3 terminals depending on configuration (SPST/SPDT). Used for mode selection or power switching in compact devices. Provides a clean digital output without bouncing issues as severe as push buttons.
Common in portable electronics and embedded systems
A rocker switch operates by pressing one side down to toggle states. It is a latching switch commonly used for power control. Many versions include internal illumination to indicate ON state. It provides a stable HIGH/LOW output depending on position. Mechanically robust, suitable for higher current applications. Widely used in appliances and power distribution systems.
This is a household AC switch used for controlling mains power. It works by physically connecting or disconnecting live wires. Unlike microcontroller switches, it handles high voltage (220–240V AC). Internally, it uses spring-loaded contacts for quick switching. Not directly interfaced with microcontrollers without relays or isolation. Represents real-world large-scale switching systems.
This is a compact version of a slide switch designed for PCBs. Used in space-constrained electronic designs. Operates the same as a regular slide switch but in smaller form factor. Typically used for configuration settings or power toggling. Provides reliable digital switching with minimal footprint. Common in wearable devices and compact circuits.
A flex sensor measures bending by changing its resistance. When straight, resistance is low; when bent, resistance increases. It provides an analog output proportional to curvature. Used in gesture detection, robotics, and wearable tech. Requires a voltage divider to read values using a microcontroller. Useful for capturing physical motion as electrical data
An FSR detects pressure or force applied to its surface. Resistance decreases as more force is applied. It outputs an analog signal based on applied pressure. Used in touch sensing, weight detection, and interactive surfaces. Not highly precise but good for relative force measurement. Requires calibration for consistent readings.
A rotary encoder detects rotation and direction instead of absolute position. It outputs digital pulses (CLK and DT) when rotated. Unlike potentiometers, it has no fixed start or end.
Often includes a push button for additional input.
Used in menus, volume control, and navigation systems. Requires decoding logic in software
A joystick module provides two-axis analog input (X and Y) along with a push button. It uses two potentiometers internally to detect direction and position. The output is analog voltage for movement and digital for the button press. It is widely used for navigation, robotics control, and gaming interfaces.
A PIR sensor detects motion using infrared radiation changes. It senses heat differences from moving objects (like humans). Outputs a digital HIGH signal when motion is detected. Does not emit energy, only detects passive IR radiation. Used in security systems and automatic lighting.
Has adjustable sensitivity and delay.
A gas sensor is an input device used to detect the presence and concentration of gases in the environment. It works by sensing changes in electrical properties (like resistance or voltage) when gas molecules interact with the sensor material. Common types such as MQ-series sensors can detect gases like LPG, methane, carbon monoxide, and smoke. The sensor outputs an analog or digital signal that can be read by a microcontroller (like Arduino or ESP32) for further processing. These sensors are widely used in safety systems, air quality monitoring, and smart alert devices to prevent hazards.
This is an advanced LDR module with built-in signal conditioning. It includes a potentiometer to adjust sensitivity threshold. Provides a clean digital output using comparator (LM393). Also supports analog output for raw light values. Useful when precise triggering is needed based on light level. Common in automation and smart lighting systems.

The MQ series sensors are gas detection modules that work on changes in resistance when exposed to different gases. Each variant is tuned for specific gases like LPG, methane, alcohol, carbon monoxide, hydrogen, or air quality compounds. They contain a heated sensing element (SnO₂) which reacts with gases and alters conductivity. Output can be both analog (concentration level) and digital (threshold detection). They require a warm-up time (typically 20–60 seconds or more) for stable readings. These sensors are widely used in safety systems, air quality monitoring, and leak detection.